Skip to content

Commit e17ea60

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent d0b8b5e commit e17ea60

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 browserbase.types.session_create_params import SessionCreateParams
@@ -832,6 +834,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
832834

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

837+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
838+
# Test that the proxy environment variables are set correctly
839+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
840+
841+
client = DefaultHttpxClient()
842+
843+
mounts = tuple(client._mounts.items())
844+
assert len(mounts) == 1
845+
assert mounts[0][0].pattern == "https://"
846+
847+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
848+
def test_default_client_creation(self) -> None:
849+
# Ensure that the client can be initialized without any exceptions
850+
DefaultHttpxClient(
851+
verify=True,
852+
cert=None,
853+
trust_env=True,
854+
http1=True,
855+
http2=False,
856+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
857+
)
858+
835859
@pytest.mark.respx(base_url=base_url)
836860
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
837861
# Test that the default follow_redirects=True allows following redirects
@@ -1687,6 +1711,28 @@ async def test_main() -> None:
16871711

16881712
time.sleep(0.1)
16891713

1714+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1715+
# Test that the proxy environment variables are set correctly
1716+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1717+
1718+
client = DefaultAsyncHttpxClient()
1719+
1720+
mounts = tuple(client._mounts.items())
1721+
assert len(mounts) == 1
1722+
assert mounts[0][0].pattern == "https://"
1723+
1724+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1725+
async def test_default_client_creation(self) -> None:
1726+
# Ensure that the client can be initialized without any exceptions
1727+
DefaultAsyncHttpxClient(
1728+
verify=True,
1729+
cert=None,
1730+
trust_env=True,
1731+
http1=True,
1732+
http2=False,
1733+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1734+
)
1735+
16901736
@pytest.mark.respx(base_url=base_url)
16911737
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
16921738
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)