Skip to content

Commit c620e09

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

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 asktable.types.datasource_create_params import DatasourceCreateParams
@@ -812,6 +814,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
812814

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

817+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
818+
# Test that the proxy environment variables are set correctly
819+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
820+
821+
client = DefaultHttpxClient()
822+
823+
mounts = tuple(client._mounts.items())
824+
assert len(mounts) == 1
825+
assert mounts[0][0].pattern == "https://"
826+
827+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
828+
def test_default_client_creation(self) -> None:
829+
# Ensure that the client can be initialized without any exceptions
830+
DefaultHttpxClient(
831+
verify=True,
832+
cert=None,
833+
trust_env=True,
834+
http1=True,
835+
http2=False,
836+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
837+
)
838+
815839
@pytest.mark.respx(base_url=base_url)
816840
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
817841
# Test that the default follow_redirects=True allows following redirects
@@ -1657,6 +1681,28 @@ async def test_main() -> None:
16571681

16581682
time.sleep(0.1)
16591683

1684+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1685+
# Test that the proxy environment variables are set correctly
1686+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1687+
1688+
client = DefaultAsyncHttpxClient()
1689+
1690+
mounts = tuple(client._mounts.items())
1691+
assert len(mounts) == 1
1692+
assert mounts[0][0].pattern == "https://"
1693+
1694+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1695+
async def test_default_client_creation(self) -> None:
1696+
# Ensure that the client can be initialized without any exceptions
1697+
DefaultAsyncHttpxClient(
1698+
verify=True,
1699+
cert=None,
1700+
trust_env=True,
1701+
http1=True,
1702+
http2=False,
1703+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1704+
)
1705+
16601706
@pytest.mark.respx(base_url=base_url)
16611707
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
16621708
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)