|
23 | 23 |
|
24 | 24 | from cloudflare import Cloudflare, AsyncCloudflare, APIResponseValidationError
|
25 | 25 | from cloudflare._types import Omit
|
26 |
| -from cloudflare._utils import maybe_transform |
27 | 26 | from cloudflare._models import BaseModel, FinalRequestOptions
|
28 |
| -from cloudflare._constants import RAW_RESPONSE_HEADER |
29 | 27 | from cloudflare._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
|
30 | 28 | from cloudflare._base_client import (
|
31 | 29 | DEFAULT_TIMEOUT,
|
|
35 | 33 | DefaultAsyncHttpxClient,
|
36 | 34 | make_request_options,
|
37 | 35 | )
|
38 |
| -from cloudflare.types.zones.zone_create_params import ZoneCreateParams |
39 | 36 |
|
40 | 37 | from .utils import update_env
|
41 | 38 |
|
@@ -893,44 +890,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
|
893 | 890 |
|
894 | 891 | @mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
895 | 892 | @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: |
897 | 894 | respx_mock.post("/zones").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
898 | 895 |
|
899 | 896 | 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__() |
912 | 898 |
|
913 | 899 | assert _get_open_connections(self.client) == 0
|
914 | 900 |
|
915 | 901 | @mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
916 | 902 | @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: |
918 | 904 | respx_mock.post("/zones").mock(return_value=httpx.Response(500))
|
919 | 905 |
|
920 | 906 | 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__() |
934 | 908 | assert _get_open_connections(self.client) == 0
|
935 | 909 |
|
936 | 910 | @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
|
1821 | 1795 |
|
1822 | 1796 | @mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1823 | 1797 | @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: |
1825 | 1801 | respx_mock.post("/zones").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
1826 | 1802 |
|
1827 | 1803 | 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__() |
1840 | 1805 |
|
1841 | 1806 | assert _get_open_connections(self.client) == 0
|
1842 | 1807 |
|
1843 | 1808 | @mock.patch("cloudflare._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1844 | 1809 | @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: |
1846 | 1813 | respx_mock.post("/zones").mock(return_value=httpx.Response(500))
|
1847 | 1814 |
|
1848 | 1815 | 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__() |
1862 | 1817 | assert _get_open_connections(self.client) == 0
|
1863 | 1818 |
|
1864 | 1819 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4])
|
|
0 commit comments