Skip to content

Commit 38beb38

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent f2eb44d commit 38beb38

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
@@ -31,6 +31,8 @@
3131
DEFAULT_TIMEOUT,
3232
HTTPX_DEFAULT_TIMEOUT,
3333
BaseClient,
34+
DefaultHttpxClient,
35+
DefaultAsyncHttpxClient,
3436
make_request_options,
3537
)
3638
from meterhub.types.api.v1.meter_detect_params import MeterDetectParams
@@ -822,6 +824,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
822824

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

827+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
828+
# Test that the proxy environment variables are set correctly
829+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
830+
831+
client = DefaultHttpxClient()
832+
833+
mounts = tuple(client._mounts.items())
834+
assert len(mounts) == 1
835+
assert mounts[0][0].pattern == "https://"
836+
837+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
838+
def test_default_client_creation(self) -> None:
839+
# Ensure that the client can be initialized without any exceptions
840+
DefaultHttpxClient(
841+
verify=True,
842+
cert=None,
843+
trust_env=True,
844+
http1=True,
845+
http2=False,
846+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
847+
)
848+
825849
@pytest.mark.respx(base_url=base_url)
826850
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
827851
# Test that the default follow_redirects=True allows following redirects
@@ -1677,6 +1701,28 @@ async def test_main() -> None:
16771701

16781702
time.sleep(0.1)
16791703

1704+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1705+
# Test that the proxy environment variables are set correctly
1706+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1707+
1708+
client = DefaultAsyncHttpxClient()
1709+
1710+
mounts = tuple(client._mounts.items())
1711+
assert len(mounts) == 1
1712+
assert mounts[0][0].pattern == "https://"
1713+
1714+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1715+
async def test_default_client_creation(self) -> None:
1716+
# Ensure that the client can be initialized without any exceptions
1717+
DefaultAsyncHttpxClient(
1718+
verify=True,
1719+
cert=None,
1720+
trust_env=True,
1721+
http1=True,
1722+
http2=False,
1723+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1724+
)
1725+
16801726
@pytest.mark.respx(base_url=base_url)
16811727
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
16821728
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)