Skip to content

Commit 366c38b

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent bdbe8e1 commit 366c38b

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 hyperspell.types.document_add_params import DocumentAddParams
@@ -837,6 +839,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
837839

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

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

17021726
time.sleep(0.1)
17031727

1728+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1729+
# Test that the proxy environment variables are set correctly
1730+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1731+
1732+
client = DefaultAsyncHttpxClient()
1733+
1734+
mounts = tuple(client._mounts.items())
1735+
assert len(mounts) == 1
1736+
assert mounts[0][0].pattern == "https://"
1737+
1738+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1739+
async def test_default_client_creation(self) -> None:
1740+
# Ensure that the client can be initialized without any exceptions
1741+
DefaultAsyncHttpxClient(
1742+
verify=True,
1743+
cert=None,
1744+
trust_env=True,
1745+
http1=True,
1746+
http2=False,
1747+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1748+
)
1749+
17041750
@pytest.mark.respx(base_url=base_url)
17051751
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17061752
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)