Skip to content

Commit 9dcbc13

Browse files
author
Anonymous Committer
committed
chore: add new tests for edge cases and remove redundant error handling
1 parent d03ef49 commit 9dcbc13

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

justoneapi/_transport.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ def get(self, path: str, params: dict[str, Any]) -> ApiResponse[Any]:
5353
f"JustOneAPI Python SDK version {__version__} is deprecated. Please update to the latest version."
5454
)
5555

56-
if response.status_code >= 400:
57-
raise TransportError(
58-
f"Server returned HTTP {response.status_code} for GET {path}"
59-
)
60-
6156
try:
6257
payload = response.json()
6358
except ValueError as exc:
@@ -84,7 +79,7 @@ def get(self, path: str, params: dict[str, Any]) -> ApiResponse[Any]:
8479

8580
@staticmethod
8681
def _is_success_code(code: Any) -> bool:
87-
return code == 0 or code == "0"
82+
return code == 0
8883

8984
@staticmethod
9085
def _clean_params(params: dict[str, Any]) -> dict[str, Any]:

tests/test_runtime.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ def handler(request: httpx.Request) -> httpx.Response:
6161
assert response.message == "not ok"
6262

6363

64+
def test_http_error_with_json_payload_returns_api_response(make_client):
65+
def handler(request: httpx.Request) -> httpx.Response:
66+
return httpx.Response(
67+
401,
68+
json={"code": 100, "message": "invalid token", "data": None},
69+
)
70+
71+
client = make_client(handler)
72+
response = client.search.search_v1(keyword="deepseek")
73+
74+
assert response.success is False
75+
assert response.code == 100
76+
assert response.message == "invalid token"
77+
78+
6479
def test_raise_on_business_error(make_client):
6580
def handler(request: httpx.Request) -> httpx.Response:
6681
return httpx.Response(
@@ -87,6 +102,17 @@ def handler(request: httpx.Request) -> httpx.Response:
87102
client.search.search_v1(keyword="deepseek")
88103

89104

105+
def test_string_zero_is_not_treated_as_success(make_client):
106+
def handler(request: httpx.Request) -> httpx.Response:
107+
return httpx.Response(200, json={"code": "0", "message": "ok", "data": {}})
108+
109+
client = make_client(handler)
110+
response = client.search.search_v1(keyword="deepseek")
111+
112+
assert response.success is False
113+
assert response.code == "0"
114+
115+
90116
def test_optional_none_is_omitted_and_bool_is_lowercase(make_client):
91117
captured: dict[str, str] = {}
92118

0 commit comments

Comments
 (0)