Skip to content

Commit a54268b

Browse files
chore(tests): improve raw response test (#110)
1 parent 4bbbb34 commit a54268b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/test_client.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ def _get_params(client: BaseClient) -> dict[str, str]:
3232
class TestFinch:
3333
client = Finch(base_url=base_url, access_token=access_token, _strict_response_validation=True)
3434

35-
def test_raw_response(self) -> None:
36-
response = self.client.get("/providers", cast_to=httpx.Response)
35+
@pytest.mark.respx(base_url=base_url)
36+
def test_raw_response(self, respx_mock: MockRouter) -> None:
37+
respx_mock.post("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"}))
38+
39+
response = self.client.post("/foo", cast_to=httpx.Response)
3740
assert response.status_code == 200
3841
assert isinstance(response, httpx.Response)
42+
assert response.json() == {"foo": "bar"}
3943

4044
def test_copy(self) -> None:
4145
copied = self.client.copy()
@@ -420,10 +424,15 @@ class Model(BaseModel):
420424
class TestAsyncFinch:
421425
client = AsyncFinch(base_url=base_url, access_token=access_token, _strict_response_validation=True)
422426

423-
async def test_raw_response(self) -> None:
424-
response = await self.client.get("/providers", cast_to=httpx.Response)
427+
@pytest.mark.respx(base_url=base_url)
428+
@pytest.mark.asyncio
429+
async def test_raw_response(self, respx_mock: MockRouter) -> None:
430+
respx_mock.post("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"}))
431+
432+
response = await self.client.post("/foo", cast_to=httpx.Response)
425433
assert response.status_code == 200
426434
assert isinstance(response, httpx.Response)
435+
assert response.json() == {"foo": "bar"}
427436

428437
def test_copy(self) -> None:
429438
copied = self.client.copy()

0 commit comments

Comments
 (0)