Skip to content

Commit d312ce9

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

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

3340
from .utils import update_env
@@ -847,6 +854,28 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
847854

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

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

17231752
time.sleep(0.1)
17241753

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

0 commit comments

Comments
 (0)