Skip to content

Commit e8aaf3b

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent 40f10ad commit e8aaf3b

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

tests/test_client.py

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323

2424
from meterhub import Meterhub, AsyncMeterhub, APIResponseValidationError
2525
from meterhub._types import Omit
26-
from meterhub._utils import maybe_transform
2726
from meterhub._models import BaseModel, FinalRequestOptions
28-
from meterhub._constants import RAW_RESPONSE_HEADER
2927
from meterhub._exceptions import MeterhubError, APIStatusError, APITimeoutError, APIResponseValidationError
3028
from meterhub._base_client import (
3129
DEFAULT_TIMEOUT,
@@ -35,7 +33,6 @@
3533
DefaultAsyncHttpxClient,
3634
make_request_options,
3735
)
38-
from meterhub.types.api.v1.meter_detect_params import MeterDetectParams
3936

4037
from .utils import update_env
4138

@@ -715,32 +712,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
715712

716713
@mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
717714
@pytest.mark.respx(base_url=base_url)
718-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
715+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Meterhub) -> None:
719716
respx_mock.post("/api/v1/meter/detect/").mock(side_effect=httpx.TimeoutException("Test timeout error"))
720717

721718
with pytest.raises(APITimeoutError):
722-
self.client.post(
723-
"/api/v1/meter/detect/",
724-
body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)),
725-
cast_to=httpx.Response,
726-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
727-
)
719+
client.api.v1.meter.with_streaming_response.detect(image="image").__enter__()
728720

729721
assert _get_open_connections(self.client) == 0
730722

731723
@mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
732724
@pytest.mark.respx(base_url=base_url)
733-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
725+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Meterhub) -> None:
734726
respx_mock.post("/api/v1/meter/detect/").mock(return_value=httpx.Response(500))
735727

736728
with pytest.raises(APIStatusError):
737-
self.client.post(
738-
"/api/v1/meter/detect/",
739-
body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)),
740-
cast_to=httpx.Response,
741-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
742-
)
743-
729+
client.api.v1.meter.with_streaming_response.detect(image="image").__enter__()
744730
assert _get_open_connections(self.client) == 0
745731

746732
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1544,32 +1530,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15441530

15451531
@mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15461532
@pytest.mark.respx(base_url=base_url)
1547-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1533+
async def test_retrying_timeout_errors_doesnt_leak(
1534+
self, respx_mock: MockRouter, async_client: AsyncMeterhub
1535+
) -> None:
15481536
respx_mock.post("/api/v1/meter/detect/").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15491537

15501538
with pytest.raises(APITimeoutError):
1551-
await self.client.post(
1552-
"/api/v1/meter/detect/",
1553-
body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)),
1554-
cast_to=httpx.Response,
1555-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1556-
)
1539+
await async_client.api.v1.meter.with_streaming_response.detect(image="image").__aenter__()
15571540

15581541
assert _get_open_connections(self.client) == 0
15591542

15601543
@mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15611544
@pytest.mark.respx(base_url=base_url)
1562-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1545+
async def test_retrying_status_errors_doesnt_leak(
1546+
self, respx_mock: MockRouter, async_client: AsyncMeterhub
1547+
) -> None:
15631548
respx_mock.post("/api/v1/meter/detect/").mock(return_value=httpx.Response(500))
15641549

15651550
with pytest.raises(APIStatusError):
1566-
await self.client.post(
1567-
"/api/v1/meter/detect/",
1568-
body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)),
1569-
cast_to=httpx.Response,
1570-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1571-
)
1572-
1551+
await async_client.api.v1.meter.with_streaming_response.detect(image="image").__aenter__()
15731552
assert _get_open_connections(self.client) == 0
15741553

15751554
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])

0 commit comments

Comments
 (0)