Skip to content

Commit a462f22

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 2d9b26c commit a462f22

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 supermemory.types.memory_add_params import MemoryAddParams
@@ -846,6 +848,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
846848

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

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+
849873
@pytest.mark.respx(base_url=base_url)
850874
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
851875
# Test that the default follow_redirects=True allows following redirects
@@ -1715,6 +1739,28 @@ async def test_main() -> None:
17151739

17161740
time.sleep(0.1)
17171741

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

0 commit comments

Comments
 (0)