Skip to content

Commit b8dfd7a

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 02cb51b commit b8dfd7a

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 replicate.types.prediction_create_params import PredictionCreateParams
@@ -868,6 +870,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
868870

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

873+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
874+
# Test that the proxy environment variables are set correctly
875+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
876+
877+
client = DefaultHttpxClient()
878+
879+
mounts = tuple(client._mounts.items())
880+
assert len(mounts) == 1
881+
assert mounts[0][0].pattern == "https://"
882+
883+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
884+
def test_default_client_creation(self) -> None:
885+
# Ensure that the client can be initialized without any exceptions
886+
DefaultHttpxClient(
887+
verify=True,
888+
cert=None,
889+
trust_env=True,
890+
http1=True,
891+
http2=False,
892+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
893+
)
894+
871895
@pytest.mark.respx(base_url=base_url)
872896
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
873897
# Test that the default follow_redirects=True allows following redirects
@@ -1759,6 +1783,28 @@ async def test_main() -> None:
17591783

17601784
time.sleep(0.1)
17611785

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

0 commit comments

Comments
 (0)