|
23 | 23 |
|
24 | 24 | from lithic import Lithic, AsyncLithic, APIResponseValidationError |
25 | 25 | from lithic._types import Omit |
26 | | -from lithic._utils import maybe_transform |
27 | 26 | from lithic._models import BaseModel, FinalRequestOptions |
28 | | -from lithic._constants import RAW_RESPONSE_HEADER |
29 | 27 | from lithic._exceptions import LithicError, APIStatusError, APITimeoutError, APIResponseValidationError |
30 | 28 | from lithic._base_client import ( |
31 | 29 | DEFAULT_TIMEOUT, |
|
35 | 33 | DefaultAsyncHttpxClient, |
36 | 34 | make_request_options, |
37 | 35 | ) |
38 | | -from lithic.types.card_create_params import CardCreateParams |
39 | 36 |
|
40 | 37 | from .utils import update_env |
41 | 38 |
|
@@ -721,32 +718,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str |
721 | 718 |
|
722 | 719 | @mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
723 | 720 | @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: |
725 | 722 | respx_mock.post("/v1/cards").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
726 | 723 |
|
727 | 724 | 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__() |
734 | 726 |
|
735 | 727 | assert _get_open_connections(self.client) == 0 |
736 | 728 |
|
737 | 729 | @mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
738 | 730 | @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: |
740 | 732 | respx_mock.post("/v1/cards").mock(return_value=httpx.Response(500)) |
741 | 733 |
|
742 | 734 | 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__() |
750 | 736 | assert _get_open_connections(self.client) == 0 |
751 | 737 |
|
752 | 738 | @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 |
1583 | 1569 |
|
1584 | 1570 | @mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1585 | 1571 | @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: |
1587 | 1573 | respx_mock.post("/v1/cards").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
1588 | 1574 |
|
1589 | 1575 | 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__() |
1596 | 1577 |
|
1597 | 1578 | assert _get_open_connections(self.client) == 0 |
1598 | 1579 |
|
1599 | 1580 | @mock.patch("lithic._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1600 | 1581 | @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: |
1602 | 1583 | respx_mock.post("/v1/cards").mock(return_value=httpx.Response(500)) |
1603 | 1584 |
|
1604 | 1585 | 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__() |
1612 | 1587 | assert _get_open_connections(self.client) == 0 |
1613 | 1588 |
|
1614 | 1589 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
|
0 commit comments