|
27 | 27 | from kernel._models import BaseModel, FinalRequestOptions |
28 | 28 | from kernel._constants import RAW_RESPONSE_HEADER |
29 | 29 | 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 | +) |
31 | 38 | from kernel.types.browser_create_params import BrowserCreateParams |
32 | 39 |
|
33 | 40 | from .utils import update_env |
@@ -837,6 +844,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response: |
837 | 844 |
|
838 | 845 | assert response.http_request.headers.get("x-stainless-retry-count") == "42" |
839 | 846 |
|
| 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 | + |
840 | 869 | @pytest.mark.respx(base_url=base_url) |
841 | 870 | def test_follow_redirects(self, respx_mock: MockRouter) -> None: |
842 | 871 | # Test that the default follow_redirects=True allows following redirects |
@@ -1716,6 +1745,28 @@ async def test_main() -> None: |
1716 | 1745 |
|
1717 | 1746 | time.sleep(0.1) |
1718 | 1747 |
|
| 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 | + |
1719 | 1770 | @pytest.mark.respx(base_url=base_url) |
1720 | 1771 | async def test_follow_redirects(self, respx_mock: MockRouter) -> None: |
1721 | 1772 | # Test that the default follow_redirects=True allows following redirects |
|
0 commit comments