|
28 | 28 | from openai._constants import RAW_RESPONSE_HEADER
|
29 | 29 | from openai._streaming import Stream, AsyncStream
|
30 | 30 | from openai._exceptions import OpenAIError, APIStatusError, APITimeoutError, APIResponseValidationError
|
31 |
| -from openai._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options |
| 31 | +from openai._base_client import ( |
| 32 | + DEFAULT_TIMEOUT, |
| 33 | + HTTPX_DEFAULT_TIMEOUT, |
| 34 | + BaseClient, |
| 35 | + DefaultHttpxClient, |
| 36 | + DefaultAsyncHttpxClient, |
| 37 | + make_request_options, |
| 38 | +) |
32 | 39 | from openai.types.chat.completion_create_params import CompletionCreateParamsNonStreaming
|
33 | 40 |
|
34 | 41 | from .utils import update_env
|
@@ -908,6 +915,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
|
908 | 915 | assert response.retries_taken == failures_before_success
|
909 | 916 | assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
|
910 | 917 |
|
| 918 | + def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 919 | + # Test that the proxy environment variables are set correctly |
| 920 | + monkeypatch.setenv("HTTPS_PROXY", "https://example.org") |
| 921 | + |
| 922 | + client = DefaultHttpxClient() |
| 923 | + |
| 924 | + mounts = tuple(client._mounts.items()) |
| 925 | + assert len(mounts) == 1 |
| 926 | + assert mounts[0][0].pattern == "https://" |
| 927 | + |
| 928 | + @pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") |
| 929 | + def test_default_client_creation(self) -> None: |
| 930 | + # Ensure that the client can be initialized without any exceptions |
| 931 | + DefaultHttpxClient( |
| 932 | + verify=True, |
| 933 | + cert=None, |
| 934 | + trust_env=True, |
| 935 | + http1=True, |
| 936 | + http2=False, |
| 937 | + limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 938 | + ) |
| 939 | + |
911 | 940 | @pytest.mark.respx(base_url=base_url)
|
912 | 941 | def test_follow_redirects(self, respx_mock: MockRouter) -> None:
|
913 | 942 | # Test that the default follow_redirects=True allows following redirects
|
@@ -1857,6 +1886,28 @@ async def test_main() -> None:
|
1857 | 1886 |
|
1858 | 1887 | time.sleep(0.1)
|
1859 | 1888 |
|
| 1889 | + async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None: |
| 1890 | + # Test that the proxy environment variables are set correctly |
| 1891 | + monkeypatch.setenv("HTTPS_PROXY", "https://example.org") |
| 1892 | + |
| 1893 | + client = DefaultAsyncHttpxClient() |
| 1894 | + |
| 1895 | + mounts = tuple(client._mounts.items()) |
| 1896 | + assert len(mounts) == 1 |
| 1897 | + assert mounts[0][0].pattern == "https://" |
| 1898 | + |
| 1899 | + @pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning") |
| 1900 | + async def test_default_client_creation(self) -> None: |
| 1901 | + # Ensure that the client can be initialized without any exceptions |
| 1902 | + DefaultAsyncHttpxClient( |
| 1903 | + verify=True, |
| 1904 | + cert=None, |
| 1905 | + trust_env=True, |
| 1906 | + http1=True, |
| 1907 | + http2=False, |
| 1908 | + limits=httpx.Limits(max_connections=100, max_keepalive_connections=20), |
| 1909 | + ) |
| 1910 | + |
1860 | 1911 | @pytest.mark.respx(base_url=base_url)
|
1861 | 1912 | async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
|
1862 | 1913 | # Test that the default follow_redirects=True allows following redirects
|
|
0 commit comments