Skip to content

Commit 0c4973f

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 518cbab commit 0c4973f

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 contextual.types.agent_create_params import AgentCreateParams
@@ -828,6 +830,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
828830

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

833+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
834+
# Test that the proxy environment variables are set correctly
835+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
836+
837+
client = DefaultHttpxClient()
838+
839+
mounts = tuple(client._mounts.items())
840+
assert len(mounts) == 1
841+
assert mounts[0][0].pattern == "https://"
842+
843+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
844+
def test_default_client_creation(self) -> None:
845+
# Ensure that the client can be initialized without any exceptions
846+
DefaultHttpxClient(
847+
verify=True,
848+
cert=None,
849+
trust_env=True,
850+
http1=True,
851+
http2=False,
852+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
853+
)
854+
831855
@pytest.mark.respx(base_url=base_url)
832856
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
833857
# Test that the default follow_redirects=True allows following redirects
@@ -1685,6 +1709,28 @@ async def test_main() -> None:
16851709

16861710
time.sleep(0.1)
16871711

1712+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1713+
# Test that the proxy environment variables are set correctly
1714+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1715+
1716+
client = DefaultAsyncHttpxClient()
1717+
1718+
mounts = tuple(client._mounts.items())
1719+
assert len(mounts) == 1
1720+
assert mounts[0][0].pattern == "https://"
1721+
1722+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1723+
async def test_default_client_creation(self) -> None:
1724+
# Ensure that the client can be initialized without any exceptions
1725+
DefaultAsyncHttpxClient(
1726+
verify=True,
1727+
cert=None,
1728+
trust_env=True,
1729+
http1=True,
1730+
http2=False,
1731+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1732+
)
1733+
16881734
@pytest.mark.respx(base_url=base_url)
16891735
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
16901736
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)