Skip to content

Commit 55a2e38

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent d519499 commit 55a2e38

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_client.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
DEFAULT_TIMEOUT,
3232
HTTPX_DEFAULT_TIMEOUT,
3333
BaseClient,
34+
DefaultHttpxClient,
35+
DefaultAsyncHttpxClient,
3436
make_request_options,
3537
)
3638
from openlayer.types.inference_pipelines.data_stream_params import DataStreamParams
@@ -921,6 +923,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
921923

922924
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
923925

926+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
927+
# Test that the proxy environment variables are set correctly
928+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
929+
930+
client = DefaultHttpxClient()
931+
932+
mounts = tuple(client._mounts.items())
933+
assert len(mounts) == 1
934+
assert mounts[0][0].pattern == "https://"
935+
936+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
937+
def test_default_client_creation(self) -> None:
938+
# Ensure that the client can be initialized without any exceptions
939+
DefaultHttpxClient(
940+
verify=True,
941+
cert=None,
942+
trust_env=True,
943+
http1=True,
944+
http2=False,
945+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
946+
)
947+
924948
@pytest.mark.respx(base_url=base_url)
925949
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
926950
# Test that the default follow_redirects=True allows following redirects
@@ -1875,6 +1899,28 @@ async def test_main() -> None:
18751899

18761900
time.sleep(0.1)
18771901

1902+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1903+
# Test that the proxy environment variables are set correctly
1904+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1905+
1906+
client = DefaultAsyncHttpxClient()
1907+
1908+
mounts = tuple(client._mounts.items())
1909+
assert len(mounts) == 1
1910+
assert mounts[0][0].pattern == "https://"
1911+
1912+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1913+
async def test_default_client_creation(self) -> None:
1914+
# Ensure that the client can be initialized without any exceptions
1915+
DefaultAsyncHttpxClient(
1916+
verify=True,
1917+
cert=None,
1918+
trust_env=True,
1919+
http1=True,
1920+
http2=False,
1921+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1922+
)
1923+
18781924
@pytest.mark.respx(base_url=base_url)
18791925
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
18801926
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)