Skip to content
This repository was archived by the owner on Aug 14, 2025. It is now read-only.

Commit b27b11b

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 85d6bbd commit b27b11b

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 llama_stack_client.types.datasetio_append_rows_params import DatasetioAppendRowsParams
@@ -843,6 +845,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
843845

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

848+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
849+
# Test that the proxy environment variables are set correctly
850+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
851+
852+
client = DefaultHttpxClient()
853+
854+
mounts = tuple(client._mounts.items())
855+
assert len(mounts) == 1
856+
assert mounts[0][0].pattern == "https://"
857+
858+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
859+
def test_default_client_creation(self) -> None:
860+
# Ensure that the client can be initialized without any exceptions
861+
DefaultHttpxClient(
862+
verify=True,
863+
cert=None,
864+
trust_env=True,
865+
http1=True,
866+
http2=False,
867+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
868+
)
869+
846870
@pytest.mark.respx(base_url=base_url)
847871
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
848872
# Test that the default follow_redirects=True allows following redirects
@@ -1709,6 +1733,28 @@ async def test_main() -> None:
17091733

17101734
time.sleep(0.1)
17111735

1736+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1737+
# Test that the proxy environment variables are set correctly
1738+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1739+
1740+
client = DefaultAsyncHttpxClient()
1741+
1742+
mounts = tuple(client._mounts.items())
1743+
assert len(mounts) == 1
1744+
assert mounts[0][0].pattern == "https://"
1745+
1746+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1747+
async def test_default_client_creation(self) -> None:
1748+
# Ensure that the client can be initialized without any exceptions
1749+
DefaultAsyncHttpxClient(
1750+
verify=True,
1751+
cert=None,
1752+
trust_env=True,
1753+
http1=True,
1754+
http2=False,
1755+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1756+
)
1757+
17121758
@pytest.mark.respx(base_url=base_url)
17131759
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17141760
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)