|
25 | 25 | from onebusaway import OnebusawaySDK, AsyncOnebusawaySDK, APIResponseValidationError
|
26 | 26 | from onebusaway._types import Omit
|
27 | 27 | from onebusaway._models import BaseModel, FinalRequestOptions
|
28 |
| -from onebusaway._constants import RAW_RESPONSE_HEADER |
29 | 28 | from onebusaway._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
|
30 | 29 | from onebusaway._base_client import (
|
31 | 30 | DEFAULT_TIMEOUT,
|
@@ -717,30 +716,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
|
717 | 716 |
|
718 | 717 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
719 | 718 | @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: |
721 | 720 | respx_mock.get("/api/where/current-time.json").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
722 | 721 |
|
723 | 722 | 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__() |
729 | 724 |
|
730 | 725 | assert _get_open_connections(self.client) == 0
|
731 | 726 |
|
732 | 727 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
733 | 728 | @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: |
735 | 730 | respx_mock.get("/api/where/current-time.json").mock(return_value=httpx.Response(500))
|
736 | 731 |
|
737 | 732 | 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__() |
744 | 734 | assert _get_open_connections(self.client) == 0
|
745 | 735 |
|
746 | 736 | @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
|
1533 | 1523 |
|
1534 | 1524 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1535 | 1525 | @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: |
1537 | 1529 | respx_mock.get("/api/where/current-time.json").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
1538 | 1530 |
|
1539 | 1531 | 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__() |
1545 | 1533 |
|
1546 | 1534 | assert _get_open_connections(self.client) == 0
|
1547 | 1535 |
|
1548 | 1536 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1549 | 1537 | @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: |
1551 | 1541 | respx_mock.get("/api/where/current-time.json").mock(return_value=httpx.Response(500))
|
1552 | 1542 |
|
1553 | 1543 | 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__() |
1560 | 1545 | assert _get_open_connections(self.client) == 0
|
1561 | 1546 |
|
1562 | 1547 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4])
|
|
0 commit comments