Skip to content

Commit 64a0a4c

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent f7b7ef9 commit 64a0a4c

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 zeroentropy.types.status_get_status_params import StatusGetStatusParams
@@ -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
@@ -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)