Skip to content

Commit 55c4719

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 8962801 commit 55c4719

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

@@ -818,6 +820,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
818820

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

823+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
824+
# Test that the proxy environment variables are set correctly
825+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
826+
827+
client = DefaultHttpxClient()
828+
829+
mounts = tuple(client._mounts.items())
830+
assert len(mounts) == 1
831+
assert mounts[0][0].pattern == "https://"
832+
833+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
834+
def test_default_client_creation(self) -> None:
835+
# Ensure that the client can be initialized without any exceptions
836+
DefaultHttpxClient(
837+
verify=True,
838+
cert=None,
839+
trust_env=True,
840+
http1=True,
841+
http2=False,
842+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
843+
)
844+
821845
@pytest.mark.respx(base_url=base_url)
822846
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
823847
# Test that the default follow_redirects=True allows following redirects
@@ -1662,6 +1686,28 @@ async def test_main() -> None:
16621686

16631687
time.sleep(0.1)
16641688

1689+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1690+
# Test that the proxy environment variables are set correctly
1691+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1692+
1693+
client = DefaultAsyncHttpxClient()
1694+
1695+
mounts = tuple(client._mounts.items())
1696+
assert len(mounts) == 1
1697+
assert mounts[0][0].pattern == "https://"
1698+
1699+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1700+
async def test_default_client_creation(self) -> None:
1701+
# Ensure that the client can be initialized without any exceptions
1702+
DefaultAsyncHttpxClient(
1703+
verify=True,
1704+
cert=None,
1705+
trust_env=True,
1706+
http1=True,
1707+
http2=False,
1708+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1709+
)
1710+
16651711
@pytest.mark.respx(base_url=base_url)
16661712
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
16671713
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)