Skip to content

Commit 0291352

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 07bbf75 commit 0291352

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 cloudflare.types.zones.zone_create_params import ZoneCreateParams
@@ -1012,6 +1014,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
10121014

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

1017+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1018+
# Test that the proxy environment variables are set correctly
1019+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1020+
1021+
client = DefaultHttpxClient()
1022+
1023+
mounts = tuple(client._mounts.items())
1024+
assert len(mounts) == 1
1025+
assert mounts[0][0].pattern == "https://"
1026+
1027+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1028+
def test_default_client_creation(self) -> None:
1029+
# Ensure that the client can be initialized without any exceptions
1030+
DefaultHttpxClient(
1031+
verify=True,
1032+
cert=None,
1033+
trust_env=True,
1034+
http1=True,
1035+
http2=False,
1036+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1037+
)
1038+
10151039
@pytest.mark.respx(base_url=base_url)
10161040
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
10171041
# Test that the default follow_redirects=True allows following redirects
@@ -1966,6 +1990,28 @@ async def test_main() -> None:
19661990

19671991
time.sleep(0.1)
19681992

1993+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1994+
# Test that the proxy environment variables are set correctly
1995+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1996+
1997+
client = DefaultAsyncHttpxClient()
1998+
1999+
mounts = tuple(client._mounts.items())
2000+
assert len(mounts) == 1
2001+
assert mounts[0][0].pattern == "https://"
2002+
2003+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
2004+
async def test_default_client_creation(self) -> None:
2005+
# Ensure that the client can be initialized without any exceptions
2006+
DefaultAsyncHttpxClient(
2007+
verify=True,
2008+
cert=None,
2009+
trust_env=True,
2010+
http1=True,
2011+
http2=False,
2012+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
2013+
)
2014+
19692015
@pytest.mark.respx(base_url=base_url)
19702016
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
19712017
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)