Skip to content

Commit 5e99c8f

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 55872c2 commit 5e99c8f

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/test_client.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
DEFAULT_TIMEOUT,
3333
HTTPX_DEFAULT_TIMEOUT,
3434
BaseClient,
35+
DefaultHttpxClient,
36+
DefaultAsyncHttpxClient,
3537
make_request_options,
3638
)
3739
from writerai.types.chat_chat_params import ChatChatParamsNonStreaming
@@ -860,6 +862,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
860862

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

865+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
866+
# Test that the proxy environment variables are set correctly
867+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
868+
869+
client = DefaultHttpxClient()
870+
871+
mounts = tuple(client._mounts.items())
872+
assert len(mounts) == 1
873+
assert mounts[0][0].pattern == "https://"
874+
875+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
876+
def test_default_client_creation(self) -> None:
877+
# Ensure that the client can be initialized without any exceptions
878+
DefaultHttpxClient(
879+
verify=True,
880+
cert=None,
881+
trust_env=True,
882+
http1=True,
883+
http2=False,
884+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
885+
)
886+
863887
@pytest.mark.respx(base_url=base_url)
864888
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
865889
# Test that the default follow_redirects=True allows following redirects
@@ -1755,6 +1779,28 @@ async def test_main() -> None:
17551779

17561780
time.sleep(0.1)
17571781

1782+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1783+
# Test that the proxy environment variables are set correctly
1784+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1785+
1786+
client = DefaultAsyncHttpxClient()
1787+
1788+
mounts = tuple(client._mounts.items())
1789+
assert len(mounts) == 1
1790+
assert mounts[0][0].pattern == "https://"
1791+
1792+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1793+
async def test_default_client_creation(self) -> None:
1794+
# Ensure that the client can be initialized without any exceptions
1795+
DefaultAsyncHttpxClient(
1796+
verify=True,
1797+
cert=None,
1798+
trust_env=True,
1799+
http1=True,
1800+
http2=False,
1801+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1802+
)
1803+
17581804
@pytest.mark.respx(base_url=base_url)
17591805
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17601806
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)