Skip to content

Commit 3036c4b

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent bc28102 commit 3036c4b

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

tests/test_client.py

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

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

4037
from .utils import update_env
4138

@@ -705,32 +702,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
705702

706703
@mock.patch("asktable._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
707704
@pytest.mark.respx(base_url=base_url)
708-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
705+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Asktable) -> None:
709706
respx_mock.post("/v1/datasources").mock(side_effect=httpx.TimeoutException("Test timeout error"))
710707

711708
with pytest.raises(APITimeoutError):
712-
self.client.post(
713-
"/v1/datasources",
714-
body=cast(object, maybe_transform(dict(engine="mysql"), DatasourceCreateParams)),
715-
cast_to=httpx.Response,
716-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
717-
)
709+
client.datasources.with_streaming_response.create(engine="mysql").__enter__()
718710

719711
assert _get_open_connections(self.client) == 0
720712

721713
@mock.patch("asktable._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
722714
@pytest.mark.respx(base_url=base_url)
723-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
715+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Asktable) -> None:
724716
respx_mock.post("/v1/datasources").mock(return_value=httpx.Response(500))
725717

726718
with pytest.raises(APIStatusError):
727-
self.client.post(
728-
"/v1/datasources",
729-
body=cast(object, maybe_transform(dict(engine="mysql"), DatasourceCreateParams)),
730-
cast_to=httpx.Response,
731-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
732-
)
733-
719+
client.datasources.with_streaming_response.create(engine="mysql").__enter__()
734720
assert _get_open_connections(self.client) == 0
735721

736722
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1524,32 +1510,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15241510

15251511
@mock.patch("asktable._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15261512
@pytest.mark.respx(base_url=base_url)
1527-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1513+
async def test_retrying_timeout_errors_doesnt_leak(
1514+
self, respx_mock: MockRouter, async_client: AsyncAsktable
1515+
) -> None:
15281516
respx_mock.post("/v1/datasources").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15291517

15301518
with pytest.raises(APITimeoutError):
1531-
await self.client.post(
1532-
"/v1/datasources",
1533-
body=cast(object, maybe_transform(dict(engine="mysql"), DatasourceCreateParams)),
1534-
cast_to=httpx.Response,
1535-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1536-
)
1519+
await async_client.datasources.with_streaming_response.create(engine="mysql").__aenter__()
15371520

15381521
assert _get_open_connections(self.client) == 0
15391522

15401523
@mock.patch("asktable._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15411524
@pytest.mark.respx(base_url=base_url)
1542-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1525+
async def test_retrying_status_errors_doesnt_leak(
1526+
self, respx_mock: MockRouter, async_client: AsyncAsktable
1527+
) -> None:
15431528
respx_mock.post("/v1/datasources").mock(return_value=httpx.Response(500))
15441529

15451530
with pytest.raises(APIStatusError):
1546-
await self.client.post(
1547-
"/v1/datasources",
1548-
body=cast(object, maybe_transform(dict(engine="mysql"), DatasourceCreateParams)),
1549-
cast_to=httpx.Response,
1550-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1551-
)
1552-
1531+
await async_client.datasources.with_streaming_response.create(engine="mysql").__aenter__()
15531532
assert _get_open_connections(self.client) == 0
15541533

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

0 commit comments

Comments
 (0)