Skip to content

Commit 8aabce1

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent f4810f4 commit 8aabce1

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

@@ -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
@@ -1667,6 +1691,28 @@ async def test_main() -> None:
16671691

16681692
time.sleep(0.1)
16691693

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

0 commit comments

Comments
 (0)