Skip to content

Commit 235bf24

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent fe8d70b commit 235bf24

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 kernel._models import BaseModel, FinalRequestOptions
2828
from kernel._constants import RAW_RESPONSE_HEADER
2929
from kernel._exceptions import KernelError, APIStatusError, APITimeoutError, APIResponseValidationError
30-
from kernel._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options
30+
from kernel._base_client import (
31+
DEFAULT_TIMEOUT,
32+
HTTPX_DEFAULT_TIMEOUT,
33+
BaseClient,
34+
DefaultHttpxClient,
35+
DefaultAsyncHttpxClient,
36+
make_request_options,
37+
)
3138
from kernel.types.browser_create_params import BrowserCreateParams
3239

3340
from .utils import update_env
@@ -837,6 +844,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
837844

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

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

17171746
time.sleep(0.1)
17181747

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

0 commit comments

Comments
 (0)