-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathdebug_test.py
57 lines (42 loc) · 1.71 KB
/
debug_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Tests for the Debug class."""
from __future__ import annotations
import requests_mock
from tests.utils.object_assertions import assert_match_object, assert_object_lists_match
from typesense.api_call import ApiCall
from typesense.debug import Debug
from typesense.types.debug import DebugResponseSchema
def test_init(fake_api_call: ApiCall) -> None:
"""Test that the Debug object is initialized correctly."""
debug = Debug(
fake_api_call,
)
assert_match_object(debug.api_call, fake_api_call)
assert_object_lists_match(
debug.api_call.node_manager.nodes,
fake_api_call.node_manager.nodes,
)
assert_match_object(
debug.api_call.config.nearest_node,
fake_api_call.config.nearest_node,
)
assert debug.resource_path == "/debug" # noqa: WPS437
def test_retrieve(fake_debug: Debug) -> None:
"""Test that the Debug object can retrieve a debug."""
json_response: DebugResponseSchema = {"state": 1, "version": "27.1"}
with requests_mock.Mocker() as mock:
mock.get(
"/debug",
json=json_response,
)
response = fake_debug.retrieve()
assert len(mock.request_history) == 1
assert mock.request_history[0].method == "GET"
assert mock.request_history[0].url == "http://nearest:8108/debug"
assert response == json_response
def test_actual_retrieve(actual_debug: Debug) -> None:
"""Test that the Debug object can retrieve a debug on Typesense server and verify response structure."""
response = actual_debug.retrieve()
assert "state" in response
assert "version" in response
assert isinstance(response["state"], int)
assert isinstance(response["version"], str)