|
25 | 25 | from finch._types import Omit
|
26 | 26 | from finch._models import BaseModel, FinalRequestOptions
|
27 | 27 | from finch._exceptions import APIStatusError, APIResponseValidationError
|
28 |
| -from finch._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options |
| 28 | +from finch._base_client import ( |
| 29 | + DEFAULT_TIMEOUT, |
| 30 | + HTTPX_DEFAULT_TIMEOUT, |
| 31 | + BaseClient, |
| 32 | + DefaultHttpxClient, |
| 33 | + DefaultAsyncHttpxClient, |
| 34 | + make_request_options, |
| 35 | +) |
29 | 36 |
|
30 | 37 | from .utils import update_env
|
31 | 38 |
|
@@ -829,6 +836,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
|
829 | 836 | assert response.retries_taken == failures_before_success
|
830 | 837 | assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
|
831 | 838 |
|
| 839 | + def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 840 | + # Test that the proxy environment variables are set correctly |
| 841 | + monkeypatch.setenv("HTTPS_PROXY", "https://example.org") |
| 842 | + |
| 843 | + client = DefaultHttpxClient() |
| 844 | + |
| 845 | + mounts = tuple(client._mounts.items()) |
| 846 | + assert len(mounts) == 1 |
| 847 | + assert mounts[0][0].pattern == "https://" |
| 848 | + |
| 849 | + @pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") |
| 850 | + def test_default_client_creation(self) -> None: |
| 851 | + # Ensure that the client can be initialized without any exceptions |
| 852 | + DefaultHttpxClient( |
| 853 | + verify=True, |
| 854 | + cert=None, |
| 855 | + trust_env=True, |
| 856 | + http1=True, |
| 857 | + http2=False, |
| 858 | + limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 859 | + ) |
| 860 | + |
832 | 861 | @pytest.mark.respx(base_url=base_url)
|
833 | 862 | def test_follow_redirects(self, respx_mock: MockRouter) -> None:
|
834 | 863 | # Test that the default follow_redirects=True allows following redirects
|
@@ -1700,6 +1729,28 @@ async def test_main() -> None:
|
1700 | 1729 |
|
1701 | 1730 | time.sleep(0.1)
|
1702 | 1731 |
|
| 1732 | + async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 1733 | + # Test that the proxy environment variables are set correctly |
| 1734 | + monkeypatch.setenv("HTTPS_PROXY", "https://example.org") |
| 1735 | + |
| 1736 | + client = DefaultAsyncHttpxClient() |
| 1737 | + |
| 1738 | + mounts = tuple(client._mounts.items()) |
| 1739 | + assert len(mounts) == 1 |
| 1740 | + assert mounts[0][0].pattern == "https://" |
| 1741 | + |
| 1742 | + @pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") |
| 1743 | + async def test_default_client_creation(self) -> None: |
| 1744 | + # Ensure that the client can be initialized without any exceptions |
| 1745 | + DefaultAsyncHttpxClient( |
| 1746 | + verify=True, |
| 1747 | + cert=None, |
| 1748 | + trust_env=True, |
| 1749 | + http1=True, |
| 1750 | + http2=False, |
| 1751 | + limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 1752 | + ) |
| 1753 | + |
1703 | 1754 | @pytest.mark.respx(base_url=base_url)
|
1704 | 1755 | async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
|
1705 | 1756 | # Test that the default follow_redirects=True allows following redirects
|
|
0 commit comments