Skip to content

Commit 5d2c5b9

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 5e316fe commit 5d2c5b9

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 isaacus.types.classifications.universal_create_params import UniversalCreateParams
@@ -850,6 +852,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
850852

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

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

17361760
time.sleep(0.1)
17371761

1762+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1763+
# Test that the proxy environment variables are set correctly
1764+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1765+
1766+
client = DefaultAsyncHttpxClient()
1767+
1768+
mounts = tuple(client._mounts.items())
1769+
assert len(mounts) == 1
1770+
assert mounts[0][0].pattern == "https://"
1771+
1772+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1773+
async def test_default_client_creation(self) -> None:
1774+
# Ensure that the client can be initialized without any exceptions
1775+
DefaultAsyncHttpxClient(
1776+
verify=True,
1777+
cert=None,
1778+
trust_env=True,
1779+
http1=True,
1780+
http2=False,
1781+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1782+
)
1783+
17381784
@pytest.mark.respx(base_url=base_url)
17391785
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17401786
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)