From b97d07caf580de0145294b5c928b0f17c85534f9 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Tue, 5 Mar 2024 12:33:05 +0000 Subject: [PATCH] feat: OpenAPI spec update via Stainless API --- src/cloudflare/_base_client.py | 10 ++++++++++ tests/test_client.py | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/cloudflare/_base_client.py b/src/cloudflare/_base_client.py index 5be217ad4ca..2b3a1f98bab 100644 --- a/src/cloudflare/_base_client.py +++ b/src/cloudflare/_base_client.py @@ -779,6 +779,11 @@ def __init__( else: timeout = DEFAULT_TIMEOUT + if http_client is not None and not isinstance(http_client, httpx.Client): # pyright: ignore[reportUnnecessaryIsInstance] + raise TypeError( + f"Invalid `http_client` argument; Expected an instance of `httpx.Client` but got {type(http_client)}" + ) + super().__init__( version=version, limits=limits, @@ -1308,6 +1313,11 @@ def __init__( else: timeout = DEFAULT_TIMEOUT + if http_client is not None and not isinstance(http_client, httpx.AsyncClient): # pyright: ignore[reportUnnecessaryIsInstance] + raise TypeError( + f"Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got {type(http_client)}" + ) + super().__init__( version=version, base_url=base_url, diff --git a/tests/test_client.py b/tests/test_client.py index 629cd45de30..45e7ef663f3 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -328,6 +328,17 @@ def test_http_client_timeout_option(self) -> None: timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore assert timeout == DEFAULT_TIMEOUT # our default + async def test_invalid_http_client(self) -> None: + with pytest.raises(TypeError, match="Invalid `http_client` arg"): + async with httpx.AsyncClient() as http_client: + Cloudflare( + base_url=base_url, + api_key=api_key, + api_email=api_email, + _strict_response_validation=True, + http_client=cast(Any, http_client), + ) + def test_default_headers_option(self) -> None: client = Cloudflare( base_url=base_url, @@ -1075,6 +1086,17 @@ async def test_http_client_timeout_option(self) -> None: timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore assert timeout == DEFAULT_TIMEOUT # our default + def test_invalid_http_client(self) -> None: + with pytest.raises(TypeError, match="Invalid `http_client` arg"): + with httpx.Client() as http_client: + AsyncCloudflare( + base_url=base_url, + api_key=api_key, + api_email=api_email, + _strict_response_validation=True, + http_client=cast(Any, http_client), + ) + def test_default_headers_option(self) -> None: client = AsyncCloudflare( base_url=base_url,