|
23 | 23 |
|
24 | 24 | from steel import Steel, AsyncSteel, APIResponseValidationError |
25 | 25 | from steel._types import Omit |
26 | | -from steel._utils import maybe_transform |
27 | 26 | from steel._models import BaseModel, FinalRequestOptions |
28 | | -from steel._constants import RAW_RESPONSE_HEADER |
29 | 27 | from steel._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError |
30 | 28 | from steel._base_client import ( |
31 | 29 | DEFAULT_TIMEOUT, |
|
35 | 33 | DefaultAsyncHttpxClient, |
36 | 34 | make_request_options, |
37 | 35 | ) |
38 | | -from steel.types.session_create_params import SessionCreateParams |
39 | 36 |
|
40 | 37 | from .utils import update_env |
41 | 38 |
|
@@ -745,32 +742,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str |
745 | 742 |
|
746 | 743 | @mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
747 | 744 | @pytest.mark.respx(base_url=base_url) |
748 | | - def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 745 | + def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Steel) -> None: |
749 | 746 | respx_mock.post("/v1/sessions").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
750 | 747 |
|
751 | 748 | with pytest.raises(APITimeoutError): |
752 | | - self.client.post( |
753 | | - "/v1/sessions", |
754 | | - body=cast(object, maybe_transform({}, SessionCreateParams)), |
755 | | - cast_to=httpx.Response, |
756 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
757 | | - ) |
| 749 | + client.sessions.with_streaming_response.create().__enter__() |
758 | 750 |
|
759 | 751 | assert _get_open_connections(self.client) == 0 |
760 | 752 |
|
761 | 753 | @mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
762 | 754 | @pytest.mark.respx(base_url=base_url) |
763 | | - def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 755 | + def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Steel) -> None: |
764 | 756 | respx_mock.post("/v1/sessions").mock(return_value=httpx.Response(500)) |
765 | 757 |
|
766 | 758 | with pytest.raises(APIStatusError): |
767 | | - self.client.post( |
768 | | - "/v1/sessions", |
769 | | - body=cast(object, maybe_transform({}, SessionCreateParams)), |
770 | | - cast_to=httpx.Response, |
771 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
772 | | - ) |
773 | | - |
| 759 | + client.sessions.with_streaming_response.create().__enter__() |
774 | 760 | assert _get_open_connections(self.client) == 0 |
775 | 761 |
|
776 | 762 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
@@ -1588,32 +1574,21 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte |
1588 | 1574 |
|
1589 | 1575 | @mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1590 | 1576 | @pytest.mark.respx(base_url=base_url) |
1591 | | - async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1577 | + async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncSteel) -> None: |
1592 | 1578 | respx_mock.post("/v1/sessions").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
1593 | 1579 |
|
1594 | 1580 | with pytest.raises(APITimeoutError): |
1595 | | - await self.client.post( |
1596 | | - "/v1/sessions", |
1597 | | - body=cast(object, maybe_transform({}, SessionCreateParams)), |
1598 | | - cast_to=httpx.Response, |
1599 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1600 | | - ) |
| 1581 | + await async_client.sessions.with_streaming_response.create().__aenter__() |
1601 | 1582 |
|
1602 | 1583 | assert _get_open_connections(self.client) == 0 |
1603 | 1584 |
|
1604 | 1585 | @mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1605 | 1586 | @pytest.mark.respx(base_url=base_url) |
1606 | | - async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1587 | + async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncSteel) -> None: |
1607 | 1588 | respx_mock.post("/v1/sessions").mock(return_value=httpx.Response(500)) |
1608 | 1589 |
|
1609 | 1590 | with pytest.raises(APIStatusError): |
1610 | | - await self.client.post( |
1611 | | - "/v1/sessions", |
1612 | | - body=cast(object, maybe_transform({}, SessionCreateParams)), |
1613 | | - cast_to=httpx.Response, |
1614 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1615 | | - ) |
1616 | | - |
| 1591 | + await async_client.sessions.with_streaming_response.create().__aenter__() |
1617 | 1592 | assert _get_open_connections(self.client) == 0 |
1618 | 1593 |
|
1619 | 1594 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
|
0 commit comments