|
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,
|
32 | 31 | HTTPX_DEFAULT_TIMEOUT,
|
33 | 32 | BaseClient,
|
| 33 | + DefaultHttpxClient, |
| 34 | + DefaultAsyncHttpxClient, |
34 | 35 | make_request_options,
|
35 | 36 | )
|
36 | 37 |
|
@@ -715,30 +716,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
|
715 | 716 |
|
716 | 717 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
717 | 718 | @pytest.mark.respx(base_url=base_url)
|
718 |
| - 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: |
719 | 720 | respx_mock.get("/api/where/current-time.json").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
720 | 721 |
|
721 | 722 | with pytest.raises(APITimeoutError):
|
722 |
| - self.client.get( |
723 |
| - "/api/where/current-time.json", |
724 |
| - cast_to=httpx.Response, |
725 |
| - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
726 |
| - ) |
| 723 | + client.current_time.with_streaming_response.retrieve().__enter__() |
727 | 724 |
|
728 | 725 | assert _get_open_connections(self.client) == 0
|
729 | 726 |
|
730 | 727 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
731 | 728 | @pytest.mark.respx(base_url=base_url)
|
732 |
| - 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: |
733 | 730 | respx_mock.get("/api/where/current-time.json").mock(return_value=httpx.Response(500))
|
734 | 731 |
|
735 | 732 | with pytest.raises(APIStatusError):
|
736 |
| - self.client.get( |
737 |
| - "/api/where/current-time.json", |
738 |
| - cast_to=httpx.Response, |
739 |
| - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
740 |
| - ) |
741 |
| - |
| 733 | + client.current_time.with_streaming_response.retrieve().__enter__() |
742 | 734 | assert _get_open_connections(self.client) == 0
|
743 | 735 |
|
744 | 736 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4])
|
@@ -818,6 +810,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
|
818 | 810 |
|
819 | 811 | assert response.http_request.headers.get("x-stainless-retry-count") == "42"
|
820 | 812 |
|
| 813 | + def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 814 | + # Test that the proxy environment variables are set correctly |
| 815 | + monkeypatch.setenv("HTTPS_PROXY", "https://example.org") |
| 816 | + |
| 817 | + client = DefaultHttpxClient() |
| 818 | + |
| 819 | + mounts = tuple(client._mounts.items()) |
| 820 | + assert len(mounts) == 1 |
| 821 | + assert mounts[0][0].pattern == "https://" |
| 822 | + |
| 823 | + @pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") |
| 824 | + def test_default_client_creation(self) -> None: |
| 825 | + # Ensure that the client can be initialized without any exceptions |
| 826 | + DefaultHttpxClient( |
| 827 | + verify=True, |
| 828 | + cert=None, |
| 829 | + trust_env=True, |
| 830 | + http1=True, |
| 831 | + http2=False, |
| 832 | + limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 833 | + ) |
| 834 | + |
821 | 835 | @pytest.mark.respx(base_url=base_url)
|
822 | 836 | def test_follow_redirects(self, respx_mock: MockRouter) -> None:
|
823 | 837 | # Test that the default follow_redirects=True allows following redirects
|
@@ -1509,30 +1523,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
|
1509 | 1523 |
|
1510 | 1524 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1511 | 1525 | @pytest.mark.respx(base_url=base_url)
|
1512 |
| - 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: |
1513 | 1529 | respx_mock.get("/api/where/current-time.json").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
1514 | 1530 |
|
1515 | 1531 | with pytest.raises(APITimeoutError):
|
1516 |
| - await self.client.get( |
1517 |
| - "/api/where/current-time.json", |
1518 |
| - cast_to=httpx.Response, |
1519 |
| - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1520 |
| - ) |
| 1532 | + await async_client.current_time.with_streaming_response.retrieve().__aenter__() |
1521 | 1533 |
|
1522 | 1534 | assert _get_open_connections(self.client) == 0
|
1523 | 1535 |
|
1524 | 1536 | @mock.patch("onebusaway._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1525 | 1537 | @pytest.mark.respx(base_url=base_url)
|
1526 |
| - 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: |
1527 | 1541 | respx_mock.get("/api/where/current-time.json").mock(return_value=httpx.Response(500))
|
1528 | 1542 |
|
1529 | 1543 | with pytest.raises(APIStatusError):
|
1530 |
| - await self.client.get( |
1531 |
| - "/api/where/current-time.json", |
1532 |
| - cast_to=httpx.Response, |
1533 |
| - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1534 |
| - ) |
1535 |
| - |
| 1544 | + await async_client.current_time.with_streaming_response.retrieve().__aenter__() |
1536 | 1545 | assert _get_open_connections(self.client) == 0
|
1537 | 1546 |
|
1538 | 1547 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4])
|
@@ -1662,6 +1671,28 @@ async def test_main() -> None:
|
1662 | 1671 |
|
1663 | 1672 | time.sleep(0.1)
|
1664 | 1673 |
|
| 1674 | + async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 1675 | + # Test that the proxy environment variables are set correctly |
| 1676 | + monkeypatch.setenv("HTTPS_PROXY", "https://example.org") |
| 1677 | + |
| 1678 | + client = DefaultAsyncHttpxClient() |
| 1679 | + |
| 1680 | + mounts = tuple(client._mounts.items()) |
| 1681 | + assert len(mounts) == 1 |
| 1682 | + assert mounts[0][0].pattern == "https://" |
| 1683 | + |
| 1684 | + @pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") |
| 1685 | + async def test_default_client_creation(self) -> None: |
| 1686 | + # Ensure that the client can be initialized without any exceptions |
| 1687 | + DefaultAsyncHttpxClient( |
| 1688 | + verify=True, |
| 1689 | + cert=None, |
| 1690 | + trust_env=True, |
| 1691 | + http1=True, |
| 1692 | + http2=False, |
| 1693 | + limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 1694 | + ) |
| 1695 | + |
1665 | 1696 | @pytest.mark.respx(base_url=base_url)
|
1666 | 1697 | async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
|
1667 | 1698 | # Test that the default follow_redirects=True allows following redirects
|
|
0 commit comments