Skip to content

Commit 6fbce26

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent 5a08ed9 commit 6fbce26

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

tests/test_client.py

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

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

4037
from .utils import update_env
4138

@@ -721,32 +718,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
721718

722719
@mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
723720
@pytest.mark.respx(base_url=base_url)
724-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
721+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Lithic) -> None:
725722
respx_mock.post("/v1/cards").mock(side_effect=httpx.TimeoutException("Test timeout error"))
726723

727724
with pytest.raises(APITimeoutError):
728-
self.client.post(
729-
"/v1/cards",
730-
body=cast(object, maybe_transform(dict(type="SINGLE_USE"), CardCreateParams)),
731-
cast_to=httpx.Response,
732-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
733-
)
725+
client.cards.with_streaming_response.create(type="VIRTUAL").__enter__()
734726

735727
assert _get_open_connections(self.client) == 0
736728

737729
@mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
738730
@pytest.mark.respx(base_url=base_url)
739-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
731+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Lithic) -> None:
740732
respx_mock.post("/v1/cards").mock(return_value=httpx.Response(500))
741733

742734
with pytest.raises(APIStatusError):
743-
self.client.post(
744-
"/v1/cards",
745-
body=cast(object, maybe_transform(dict(type="SINGLE_USE"), CardCreateParams)),
746-
cast_to=httpx.Response,
747-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
748-
)
749-
735+
client.cards.with_streaming_response.create(type="VIRTUAL").__enter__()
750736
assert _get_open_connections(self.client) == 0
751737

752738
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1583,32 +1569,21 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15831569

15841570
@mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15851571
@pytest.mark.respx(base_url=base_url)
1586-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1572+
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncLithic) -> None:
15871573
respx_mock.post("/v1/cards").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15881574

15891575
with pytest.raises(APITimeoutError):
1590-
await self.client.post(
1591-
"/v1/cards",
1592-
body=cast(object, maybe_transform(dict(type="SINGLE_USE"), CardCreateParams)),
1593-
cast_to=httpx.Response,
1594-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1595-
)
1576+
await async_client.cards.with_streaming_response.create(type="VIRTUAL").__aenter__()
15961577

15971578
assert _get_open_connections(self.client) == 0
15981579

15991580
@mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
16001581
@pytest.mark.respx(base_url=base_url)
1601-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1582+
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncLithic) -> None:
16021583
respx_mock.post("/v1/cards").mock(return_value=httpx.Response(500))
16031584

16041585
with pytest.raises(APIStatusError):
1605-
await self.client.post(
1606-
"/v1/cards",
1607-
body=cast(object, maybe_transform(dict(type="SINGLE_USE"), CardCreateParams)),
1608-
cast_to=httpx.Response,
1609-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1610-
)
1611-
1586+
await async_client.cards.with_streaming_response.create(type="VIRTUAL").__aenter__()
16121587
assert _get_open_connections(self.client) == 0
16131588

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

0 commit comments

Comments
 (0)