Skip to content

Commit 7ecf66c

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent ed595b0 commit 7ecf66c

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
@@ -30,6 +30,8 @@
3030
DEFAULT_TIMEOUT,
3131
HTTPX_DEFAULT_TIMEOUT,
3232
BaseClient,
33+
DefaultHttpxClient,
34+
DefaultAsyncHttpxClient,
3335
make_request_options,
3436
)
3537

@@ -826,6 +828,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
826828

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

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

16801704
time.sleep(0.1)
16811705

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

0 commit comments

Comments
 (0)