Skip to content

Commit bf46662

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 425caff commit bf46662

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

tests/test_client.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727
from codex._models import BaseModel, FinalRequestOptions
2828
from codex._constants import RAW_RESPONSE_HEADER
2929
from codex._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
30-
from codex._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options
30+
from codex._base_client import (
31+
DEFAULT_TIMEOUT,
32+
HTTPX_DEFAULT_TIMEOUT,
33+
BaseClient,
34+
DefaultHttpxClient,
35+
DefaultAsyncHttpxClient,
36+
make_request_options,
37+
)
3138
from codex.types.project_create_params import ProjectCreateParams
3239

3340
from .utils import update_env
@@ -803,6 +810,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
803810

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

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

16381667
time.sleep(0.1)
16391668

1669+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1670+
# Test that the proxy environment variables are set correctly
1671+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1672+
1673+
client = DefaultAsyncHttpxClient()
1674+
1675+
mounts = tuple(client._mounts.items())
1676+
assert len(mounts) == 1
1677+
assert mounts[0][0].pattern == "https://"
1678+
1679+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1680+
async def test_default_client_creation(self) -> None:
1681+
# Ensure that the client can be initialized without any exceptions
1682+
DefaultAsyncHttpxClient(
1683+
verify=True,
1684+
cert=None,
1685+
trust_env=True,
1686+
http1=True,
1687+
http2=False,
1688+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1689+
)
1690+
16401691
@pytest.mark.respx(base_url=base_url)
16411692
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
16421693
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)