Skip to content

Commit 355779a

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent dc50499 commit 355779a

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

tests/test_client.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from onebusaway import OnebusawaySDK, AsyncOnebusawaySDK, APIResponseValidationError
2626
from onebusaway._types import Omit
2727
from onebusaway._models import BaseModel, FinalRequestOptions
28-
from onebusaway._constants import RAW_RESPONSE_HEADER
2928
from onebusaway._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
3029
from onebusaway._base_client import (
3130
DEFAULT_TIMEOUT,
@@ -717,30 +716,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
717716

718717
@mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
719718
@pytest.mark.respx(base_url=base_url)
720-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
719+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: OnebusawaySDK) -> None:
721720
respx_mock.get("/api/where/current-time.json").mock(side_effect=httpx.TimeoutException("Test timeout error"))
722721

723722
with pytest.raises(APITimeoutError):
724-
self.client.get(
725-
"/api/where/current-time.json",
726-
cast_to=httpx.Response,
727-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
728-
)
723+
client.current_time.with_streaming_response.retrieve().__enter__()
729724

730725
assert _get_open_connections(self.client) == 0
731726

732727
@mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
733728
@pytest.mark.respx(base_url=base_url)
734-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
729+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: OnebusawaySDK) -> None:
735730
respx_mock.get("/api/where/current-time.json").mock(return_value=httpx.Response(500))
736731

737732
with pytest.raises(APIStatusError):
738-
self.client.get(
739-
"/api/where/current-time.json",
740-
cast_to=httpx.Response,
741-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
742-
)
743-
733+
client.current_time.with_streaming_response.retrieve().__enter__()
744734
assert _get_open_connections(self.client) == 0
745735

746736
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1533,30 +1523,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15331523

15341524
@mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15351525
@pytest.mark.respx(base_url=base_url)
1536-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1526+
async def test_retrying_timeout_errors_doesnt_leak(
1527+
self, respx_mock: MockRouter, async_client: AsyncOnebusawaySDK
1528+
) -> None:
15371529
respx_mock.get("/api/where/current-time.json").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15381530

15391531
with pytest.raises(APITimeoutError):
1540-
await self.client.get(
1541-
"/api/where/current-time.json",
1542-
cast_to=httpx.Response,
1543-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1544-
)
1532+
await async_client.current_time.with_streaming_response.retrieve().__aenter__()
15451533

15461534
assert _get_open_connections(self.client) == 0
15471535

15481536
@mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15491537
@pytest.mark.respx(base_url=base_url)
1550-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1538+
async def test_retrying_status_errors_doesnt_leak(
1539+
self, respx_mock: MockRouter, async_client: AsyncOnebusawaySDK
1540+
) -> None:
15511541
respx_mock.get("/api/where/current-time.json").mock(return_value=httpx.Response(500))
15521542

15531543
with pytest.raises(APIStatusError):
1554-
await self.client.get(
1555-
"/api/where/current-time.json",
1556-
cast_to=httpx.Response,
1557-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1558-
)
1559-
1544+
await async_client.current_time.with_streaming_response.retrieve().__aenter__()
15601545
assert _get_open_connections(self.client) == 0
15611546

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

0 commit comments

Comments
 (0)