@@ -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+
6479def 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+
90116def test_optional_none_is_omitted_and_bool_is_lowercase (make_client ):
91117 captured : dict [str , str ] = {}
92118
0 commit comments