Skip to content

Commit 5b5cda3

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 1c23f45 commit 5b5cda3

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

3340
from .utils import update_env
@@ -846,6 +853,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
846853
assert response.retries_taken == failures_before_success
847854
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
848855

856+
def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
857+
# Test that the proxy environment variables are set correctly
858+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
859+
860+
client = DefaultHttpxClient()
861+
862+
mounts = tuple(client._mounts.items())
863+
assert len(mounts) == 1
864+
assert mounts[0][0].pattern == "https://"
865+
866+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
867+
def test_default_client_creation(self) -> None:
868+
# Ensure that the client can be initialized without any exceptions
869+
DefaultHttpxClient(
870+
verify=True,
871+
cert=None,
872+
trust_env=True,
873+
http1=True,
874+
http2=False,
875+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
876+
)
877+
849878
@pytest.mark.respx(base_url=base_url)
850879
def test_follow_redirects(self, respx_mock: MockRouter) -> None:
851880
# Test that the default follow_redirects=True allows following redirects
@@ -1735,6 +1764,28 @@ async def test_main() -> None:
17351764

17361765
time.sleep(0.1)
17371766

1767+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1768+
# Test that the proxy environment variables are set correctly
1769+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1770+
1771+
client = DefaultAsyncHttpxClient()
1772+
1773+
mounts = tuple(client._mounts.items())
1774+
assert len(mounts) == 1
1775+
assert mounts[0][0].pattern == "https://"
1776+
1777+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1778+
async def test_default_client_creation(self) -> None:
1779+
# Ensure that the client can be initialized without any exceptions
1780+
DefaultAsyncHttpxClient(
1781+
verify=True,
1782+
cert=None,
1783+
trust_env=True,
1784+
http1=True,
1785+
http2=False,
1786+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1787+
)
1788+
17381789
@pytest.mark.respx(base_url=base_url)
17391790
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17401791
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)