Skip to content

Commit

Permalink
chore(tests): improve raw response test (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Sep 27, 2023
1 parent e7aa3e7 commit 8042473
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8042473

Please sign in to comment.