Skip to content

Commit f0b2a9d

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

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
@@ -835,6 +842,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
835842

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

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

17131742
time.sleep(0.1)
17141743

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

0 commit comments

Comments
 (0)