Skip to content

Commit 938b9aa

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 9b40fb9 commit 938b9aa

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 runloop_api_client.types.devbox_create_params import DevboxCreateParams
@@ -873,6 +875,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
873875

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

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

17701794
time.sleep(0.1)
17711795

1796+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1797+
# Test that the proxy environment variables are set correctly
1798+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1799+
1800+
client = DefaultAsyncHttpxClient()
1801+
1802+
mounts = tuple(client._mounts.items())
1803+
assert len(mounts) == 1
1804+
assert mounts[0][0].pattern == "https://"
1805+
1806+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1807+
async def test_default_client_creation(self) -> None:
1808+
# Ensure that the client can be initialized without any exceptions
1809+
DefaultAsyncHttpxClient(
1810+
verify=True,
1811+
cert=None,
1812+
trust_env=True,
1813+
http1=True,
1814+
http2=False,
1815+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1816+
)
1817+
17721818
@pytest.mark.respx(base_url=base_url)
17731819
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17741820
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)