Skip to content

Commit 721188d

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent b84a94e commit 721188d

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

tests/test_client.py

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323

2424
from cloudflare import Cloudflare, AsyncCloudflare, APIResponseValidationError
2525
from cloudflare._types import Omit
26-
from cloudflare._utils import maybe_transform
2726
from cloudflare._models import BaseModel, FinalRequestOptions
28-
from cloudflare._constants import RAW_RESPONSE_HEADER
2927
from cloudflare._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
3028
from cloudflare._base_client import (
3129
DEFAULT_TIMEOUT,
@@ -35,7 +33,6 @@
3533
DefaultAsyncHttpxClient,
3634
make_request_options,
3735
)
38-
from cloudflare.types.zones.zone_create_params import ZoneCreateParams
3936

4037
from .utils import update_env
4138

@@ -893,44 +890,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
893890

894891
@mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
895892
@pytest.mark.respx(base_url=base_url)
896-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
893+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Cloudflare) -> None:
897894
respx_mock.post("/zones").mock(side_effect=httpx.TimeoutException("Test timeout error"))
898895

899896
with pytest.raises(APITimeoutError):
900-
self.client.post(
901-
"/zones",
902-
body=cast(
903-
object,
904-
maybe_transform(
905-
dict(account={"id": "023e105f4ecef8ad9ca31a8372d0c353"}, name="example.com", type="full"),
906-
ZoneCreateParams,
907-
),
908-
),
909-
cast_to=httpx.Response,
910-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
911-
)
897+
client.zones.with_streaming_response.create(account={}, name="example.com").__enter__()
912898

913899
assert _get_open_connections(self.client) == 0
914900

915901
@mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
916902
@pytest.mark.respx(base_url=base_url)
917-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
903+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Cloudflare) -> None:
918904
respx_mock.post("/zones").mock(return_value=httpx.Response(500))
919905

920906
with pytest.raises(APIStatusError):
921-
self.client.post(
922-
"/zones",
923-
body=cast(
924-
object,
925-
maybe_transform(
926-
dict(account={"id": "023e105f4ecef8ad9ca31a8372d0c353"}, name="example.com", type="full"),
927-
ZoneCreateParams,
928-
),
929-
),
930-
cast_to=httpx.Response,
931-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
932-
)
933-
907+
client.zones.with_streaming_response.create(account={}, name="example.com").__enter__()
934908
assert _get_open_connections(self.client) == 0
935909

936910
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1821,44 +1795,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
18211795

18221796
@mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
18231797
@pytest.mark.respx(base_url=base_url)
1824-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1798+
async def test_retrying_timeout_errors_doesnt_leak(
1799+
self, respx_mock: MockRouter, async_client: AsyncCloudflare
1800+
) -> None:
18251801
respx_mock.post("/zones").mock(side_effect=httpx.TimeoutException("Test timeout error"))
18261802

18271803
with pytest.raises(APITimeoutError):
1828-
await self.client.post(
1829-
"/zones",
1830-
body=cast(
1831-
object,
1832-
maybe_transform(
1833-
dict(account={"id": "023e105f4ecef8ad9ca31a8372d0c353"}, name="example.com", type="full"),
1834-
ZoneCreateParams,
1835-
),
1836-
),
1837-
cast_to=httpx.Response,
1838-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1839-
)
1804+
await async_client.zones.with_streaming_response.create(account={}, name="example.com").__aenter__()
18401805

18411806
assert _get_open_connections(self.client) == 0
18421807

18431808
@mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
18441809
@pytest.mark.respx(base_url=base_url)
1845-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1810+
async def test_retrying_status_errors_doesnt_leak(
1811+
self, respx_mock: MockRouter, async_client: AsyncCloudflare
1812+
) -> None:
18461813
respx_mock.post("/zones").mock(return_value=httpx.Response(500))
18471814

18481815
with pytest.raises(APIStatusError):
1849-
await self.client.post(
1850-
"/zones",
1851-
body=cast(
1852-
object,
1853-
maybe_transform(
1854-
dict(account={"id": "023e105f4ecef8ad9ca31a8372d0c353"}, name="example.com", type="full"),
1855-
ZoneCreateParams,
1856-
),
1857-
),
1858-
cast_to=httpx.Response,
1859-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1860-
)
1861-
1816+
await async_client.zones.with_streaming_response.create(account={}, name="example.com").__aenter__()
18621817
assert _get_open_connections(self.client) == 0
18631818

18641819
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])

0 commit comments

Comments
 (0)