Skip to content

Commit ffacf10

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent e210ee7 commit ffacf10

1 file changed

Lines changed: 8 additions & 33 deletions

File tree

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 steel import Steel, AsyncSteel, APIResponseValidationError
2525
from steel._types import Omit
26-
from steel._utils import maybe_transform
2726
from steel._models import BaseModel, FinalRequestOptions
28-
from steel._constants import RAW_RESPONSE_HEADER
2927
from steel._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
3028
from steel._base_client import (
3129
DEFAULT_TIMEOUT,
@@ -35,7 +33,6 @@
3533
DefaultAsyncHttpxClient,
3634
make_request_options,
3735
)
38-
from steel.types.session_create_params import SessionCreateParams
3936

4037
from .utils import update_env
4138

@@ -745,32 +742,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
745742

746743
@mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
747744
@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:
749746
respx_mock.post("/v1/sessions").mock(side_effect=httpx.TimeoutException("Test timeout error"))
750747

751748
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__()
758750

759751
assert _get_open_connections(self.client) == 0
760752

761753
@mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
762754
@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:
764756
respx_mock.post("/v1/sessions").mock(return_value=httpx.Response(500))
765757

766758
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__()
774760
assert _get_open_connections(self.client) == 0
775761

776762
@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
15881574

15891575
@mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15901576
@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:
15921578
respx_mock.post("/v1/sessions").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15931579

15941580
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__()
16011582

16021583
assert _get_open_connections(self.client) == 0
16031584

16041585
@mock.patch("steel._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
16051586
@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:
16071588
respx_mock.post("/v1/sessions").mock(return_value=httpx.Response(500))
16081589

16091590
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__()
16171592
assert _get_open_connections(self.client) == 0
16181593

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

0 commit comments

Comments
 (0)