Skip to content

Commit c00a75c

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent 1696e2a commit c00a75c

File tree

1 file changed

+12
-53
lines changed

1 file changed

+12
-53
lines changed

tests/test_client.py

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

2424
from orb import Orb, AsyncOrb, APIResponseValidationError
2525
from orb._types import Omit
26-
from orb._utils import maybe_transform
2726
from orb._models import BaseModel, FinalRequestOptions
28-
from orb._constants import RAW_RESPONSE_HEADER
2927
from orb._exceptions import OrbError, APIStatusError, APITimeoutError, APIResponseValidationError
3028
from orb._base_client import (
3129
DEFAULT_TIMEOUT,
@@ -35,7 +33,6 @@
3533
DefaultAsyncHttpxClient,
3634
make_request_options,
3735
)
38-
from orb.types.customer_create_params import CustomerCreateParams
3936

4037
from .utils import update_env
4138

@@ -736,42 +733,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
736733

737734
@mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
738735
@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:
740737
respx_mock.post("/customers").mock(side_effect=httpx.TimeoutException("Test timeout error"))
741738

742739
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__()
754741

755742
assert _get_open_connections(self.client) == 0
756743

757744
@mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
758745
@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:
760747
respx_mock.post("/customers").mock(return_value=httpx.Response(500))
761748

762749
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__()
775751
assert _get_open_connections(self.client) == 0
776752

777753
@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
16171593

16181594
@mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
16191595
@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:
16211597
respx_mock.post("/customers").mock(side_effect=httpx.TimeoutException("Test timeout error"))
16221598

16231599
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__()
16351603

16361604
assert _get_open_connections(self.client) == 0
16371605

16381606
@mock.patch("orb._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
16391607
@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:
16411609
respx_mock.post("/customers").mock(return_value=httpx.Response(500))
16421610

16431611
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__()
16561615
assert _get_open_connections(self.client) == 0
16571616

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

0 commit comments

Comments
 (0)