Skip to content

Commit e51c8f7

Browse files
chore(tests): add tests for httpx client instantiation & proxies
1 parent 260c761 commit e51c8f7

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
@@ -25,7 +25,14 @@
2525
from finch._types import Omit
2626
from finch._models import BaseModel, FinalRequestOptions
2727
from finch._exceptions import APIStatusError, APIResponseValidationError
28-
from finch._base_client import DEFAULT_TIMEOUT, HTTPX_DEFAULT_TIMEOUT, BaseClient, make_request_options
28+
from finch._base_client import (
29+
DEFAULT_TIMEOUT,
30+
HTTPX_DEFAULT_TIMEOUT,
31+
BaseClient,
32+
DefaultHttpxClient,
33+
DefaultAsyncHttpxClient,
34+
make_request_options,
35+
)
2936

3037
from .utils import update_env
3138

@@ -829,6 +836,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
829836
assert response.retries_taken == failures_before_success
830837
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
831838

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

17011730
time.sleep(0.1)
17021731

1732+
async def test_proxy_environment_variables(self, monkeypatch: pytest.MonkeyPatch) -> None:
1733+
# Test that the proxy environment variables are set correctly
1734+
monkeypatch.setenv("HTTPS_PROXY", "https://example.org")
1735+
1736+
client = DefaultAsyncHttpxClient()
1737+
1738+
mounts = tuple(client._mounts.items())
1739+
assert len(mounts) == 1
1740+
assert mounts[0][0].pattern == "https://"
1741+
1742+
@pytest.mark.filterwarnings("ignore:.*deprecated.*:DeprecationWarning")
1743+
async def test_default_client_creation(self) -> None:
1744+
# Ensure that the client can be initialized without any exceptions
1745+
DefaultAsyncHttpxClient(
1746+
verify=True,
1747+
cert=None,
1748+
trust_env=True,
1749+
http1=True,
1750+
http2=False,
1751+
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
1752+
)
1753+
17031754
@pytest.mark.respx(base_url=base_url)
17041755
async def test_follow_redirects(self, respx_mock: MockRouter) -> None:
17051756
# Test that the default follow_redirects=True allows following redirects

0 commit comments

Comments
 (0)