|
23 | 23 |
|
24 | 24 | from orb import Orb, AsyncOrb, APIResponseValidationError |
25 | 25 | from orb._types import Omit |
26 | | -from orb._utils import maybe_transform |
27 | 26 | from orb._models import BaseModel, FinalRequestOptions |
28 | | -from orb._constants import RAW_RESPONSE_HEADER |
29 | 27 | from orb._exceptions import OrbError, APIStatusError, APITimeoutError, APIResponseValidationError |
30 | 28 | from orb._base_client import ( |
31 | 29 | DEFAULT_TIMEOUT, |
|
35 | 33 | DefaultAsyncHttpxClient, |
36 | 34 | make_request_options, |
37 | 35 | ) |
38 | | -from orb.types.customer_create_params import CustomerCreateParams |
39 | 36 |
|
40 | 37 | from .utils import update_env |
41 | 38 |
|
@@ -736,42 +733,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str |
736 | 733 |
|
737 | 734 | @mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
738 | 735 | @pytest.mark.respx(base_url=base_url) |
739 | | - def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 736 | + def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Orb) -> None: |
740 | 737 | respx_mock.post("/customers").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
741 | 738 |
|
742 | 739 | with pytest.raises(APITimeoutError): |
743 | | - self.client.post( |
744 | | - "/customers", |
745 | | - body=cast( |
746 | | - object, |
747 | | - maybe_transform( |
748 | | - dict(email="example-customer@withorb.com", name="My Customer"), CustomerCreateParams |
749 | | - ), |
750 | | - ), |
751 | | - cast_to=httpx.Response, |
752 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
753 | | - ) |
| 740 | + client.customers.with_streaming_response.create(email="dev@stainless.com", name="x").__enter__() |
754 | 741 |
|
755 | 742 | assert _get_open_connections(self.client) == 0 |
756 | 743 |
|
757 | 744 | @mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
758 | 745 | @pytest.mark.respx(base_url=base_url) |
759 | | - def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 746 | + def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Orb) -> None: |
760 | 747 | respx_mock.post("/customers").mock(return_value=httpx.Response(500)) |
761 | 748 |
|
762 | 749 | with pytest.raises(APIStatusError): |
763 | | - self.client.post( |
764 | | - "/customers", |
765 | | - body=cast( |
766 | | - object, |
767 | | - maybe_transform( |
768 | | - dict(email="example-customer@withorb.com", name="My Customer"), CustomerCreateParams |
769 | | - ), |
770 | | - ), |
771 | | - cast_to=httpx.Response, |
772 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
773 | | - ) |
774 | | - |
| 750 | + client.customers.with_streaming_response.create(email="dev@stainless.com", name="x").__enter__() |
775 | 751 | assert _get_open_connections(self.client) == 0 |
776 | 752 |
|
777 | 753 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
@@ -1617,42 +1593,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte |
1617 | 1593 |
|
1618 | 1594 | @mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1619 | 1595 | @pytest.mark.respx(base_url=base_url) |
1620 | | - async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1596 | + async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncOrb) -> None: |
1621 | 1597 | respx_mock.post("/customers").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
1622 | 1598 |
|
1623 | 1599 | with pytest.raises(APITimeoutError): |
1624 | | - await self.client.post( |
1625 | | - "/customers", |
1626 | | - body=cast( |
1627 | | - object, |
1628 | | - maybe_transform( |
1629 | | - dict(email="example-customer@withorb.com", name="My Customer"), CustomerCreateParams |
1630 | | - ), |
1631 | | - ), |
1632 | | - cast_to=httpx.Response, |
1633 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1634 | | - ) |
| 1600 | + await async_client.customers.with_streaming_response.create( |
| 1601 | + email="dev@stainless.com", name="x" |
| 1602 | + ).__aenter__() |
1635 | 1603 |
|
1636 | 1604 | assert _get_open_connections(self.client) == 0 |
1637 | 1605 |
|
1638 | 1606 | @mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1639 | 1607 | @pytest.mark.respx(base_url=base_url) |
1640 | | - async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1608 | + async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncOrb) -> None: |
1641 | 1609 | respx_mock.post("/customers").mock(return_value=httpx.Response(500)) |
1642 | 1610 |
|
1643 | 1611 | with pytest.raises(APIStatusError): |
1644 | | - await self.client.post( |
1645 | | - "/customers", |
1646 | | - body=cast( |
1647 | | - object, |
1648 | | - maybe_transform( |
1649 | | - dict(email="example-customer@withorb.com", name="My Customer"), CustomerCreateParams |
1650 | | - ), |
1651 | | - ), |
1652 | | - cast_to=httpx.Response, |
1653 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1654 | | - ) |
1655 | | - |
| 1612 | + await async_client.customers.with_streaming_response.create( |
| 1613 | + email="dev@stainless.com", name="x" |
| 1614 | + ).__aenter__() |
1656 | 1615 | assert _get_open_connections(self.client) == 0 |
1657 | 1616 |
|
1658 | 1617 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
|
0 commit comments