Skip to content

Commit ad4f8a1

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 96bc0a5 commit ad4f8a1

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

tests/test_client.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727
from steel._models import BaseModel, FinalRequestOptions
2828
from steel._constants import RAW_RESPONSE_HEADER
2929
from steel._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
30-
from steel._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options
30+
from steel._base_client import (
31+
DEFAULT_TIMEOUT,
32+
HTTPX_DEFAULT_TIMEOUT,
33+
BaseClient,
34+
DefaultHttpxClient,
35+
DefaultAsyncHttpxClient,
36+
make_request_options,
37+
)
3138
from steel.types.session_create_params import SessionCreateParams
3239

3340
from .utils import update_env
@@ -841,6 +848,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
841848

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

851+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
852+
# Test that the proxy environment variables are set correctly
853+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
854+
855+
client = DefaultHttpxClient()
856+
857+
mounts = tuple(client._mounts.items())
858+
assert len(mounts) == 1
859+
assert mounts[0][0].pattern == "https://"
860+
861+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
862+
def test_default_client_creation(self) -> None:
863+
# Ensure that the client can be initialized without any exceptions
864+
DefaultHttpxClient(
865+
verify=True,
866+
cert=None,
867+
trust_env=True,
868+
http1=True,
869+
http2=False,
870+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
871+
)
872+
844873
@pytest.mark.respx(base_url=base_url)
845874
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
846875
# Test that the default follow_redirects=True allows following redirects
@@ -1712,6 +1741,28 @@ async def test_main() -> None:
17121741

17131742
time.sleep(0.1)
17141743

1744+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1745+
# Test that the proxy environment variables are set correctly
1746+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1747+
1748+
client = DefaultAsyncHttpxClient()
1749+
1750+
mounts = tuple(client._mounts.items())
1751+
assert len(mounts) == 1
1752+
assert mounts[0][0].pattern == "https://"
1753+
1754+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1755+
async def test_default_client_creation(self) -> None:
1756+
# Ensure that the client can be initialized without any exceptions
1757+
DefaultAsyncHttpxClient(
1758+
verify=True,
1759+
cert=None,
1760+
trust_env=True,
1761+
http1=True,
1762+
http2=False,
1763+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1764+
)
1765+
17151766
@pytest.mark.respx(base_url=base_url)
17161767
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17171768
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)