From 8042473bd73faa0b819c27a68bfc19b918361461 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 27 Sep 2023 04:54:45 +0100 Subject: [PATCH] chore(tests): improve raw response test (#166) --- tests/test_client.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_client.py b/tests/test_client.py index 8fab6b6d..fdd1e323 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -33,6 +33,15 @@ def _get_params(client: BaseClient) -> dict[str, str]: class TestAnthropic: client = Anthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True) + @pytest.mark.respx(base_url=base_url) + def test_raw_response(self, respx_mock: MockRouter) -> None: + respx_mock.post("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"})) + + response = self.client.post("/foo", cast_to=httpx.Response) + assert response.status_code == 200 + assert isinstance(response, httpx.Response) + assert response.json() == {"foo": "bar"} + def test_copy(self) -> None: copied = self.client.copy() assert id(copied) != id(self.client) @@ -418,6 +427,16 @@ class Model(BaseModel): class TestAsyncAnthropic: client = AsyncAnthropic(base_url=base_url, api_key=api_key, _strict_response_validation=True) + @pytest.mark.respx(base_url=base_url) + @pytest.mark.asyncio + async def test_raw_response(self, respx_mock: MockRouter) -> None: + respx_mock.post("/foo").mock(return_value=httpx.Response(200, json={"foo": "bar"})) + + response = await self.client.post("/foo", cast_to=httpx.Response) + assert response.status_code == 200 + assert isinstance(response, httpx.Response) + assert response.json() == {"foo": "bar"} + def test_copy(self) -> None: copied = self.client.copy() assert id(copied) != id(self.client)