Skip to content

chore(tests): improve raw response test #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ def _get_params(client: BaseClient) -> dict[str, str]:
class TestFinch:
client = Finch(base_url=base_url, access_token=access_token, _strict_response_validation=True)

def test_raw_response(self) -> None:
response = self.client.get("/providers", cast_to=httpx.Response)
@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()
Expand Down Expand Up @@ -420,10 +424,15 @@ class Model(BaseModel):
class TestAsyncFinch:
client = AsyncFinch(base_url=base_url, access_token=access_token, _strict_response_validation=True)

async def test_raw_response(self) -> None:
response = await self.client.get("/providers", cast_to=httpx.Response)
@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()
Expand Down