Skip to content

Commit 638c7c4

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent cd48569 commit 638c7c4

File tree

1 file changed

+26
-73
lines changed

1 file changed

+26
-73
lines changed

tests/test_client.py

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

2424
from isaacus import Isaacus, AsyncIsaacus, APIResponseValidationError
2525
from isaacus._types import Omit
26-
from isaacus._utils import maybe_transform
2726
from isaacus._models import BaseModel, FinalRequestOptions
28-
from isaacus._constants import RAW_RESPONSE_HEADER
2927
from isaacus._exceptions import IsaacusError, APIStatusError, APITimeoutError, APIResponseValidationError
3028
from isaacus._base_client import (
3129
DEFAULT_TIMEOUT,
@@ -35,7 +33,6 @@
3533
DefaultAsyncHttpxClient,
3634
make_request_options,
3735
)
38-
from isaacus.types.classifications.universal_create_params import UniversalCreateParams
3936

4037
from .utils import update_env
4138

@@ -713,52 +710,29 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
713710

714711
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
715712
@pytest.mark.respx(base_url=base_url)
716-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
713+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Isaacus) -> None:
717714
respx_mock.post("/classifications/universal").mock(side_effect=httpx.TimeoutException("Test timeout error"))
718715

719716
with pytest.raises(APITimeoutError):
720-
self.client.post(
721-
"/classifications/universal",
722-
body=cast(
723-
object,
724-
maybe_transform(
725-
dict(
726-
model="kanon-universal-classifier",
727-
query="This is a confidentiality clause.",
728-
texts=["I agree not to tell anyone about the document."],
729-
),
730-
UniversalCreateParams,
731-
),
732-
),
733-
cast_to=httpx.Response,
734-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
735-
)
717+
client.classifications.universal.with_streaming_response.create(
718+
model="kanon-universal-classifier",
719+
query="This is a confidentiality clause.",
720+
texts=["I agree not to tell anyone about the document."],
721+
).__enter__()
736722

737723
assert _get_open_connections(self.client) == 0
738724

739725
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
740726
@pytest.mark.respx(base_url=base_url)
741-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
727+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Isaacus) -> None:
742728
respx_mock.post("/classifications/universal").mock(return_value=httpx.Response(500))
743729

744730
with pytest.raises(APIStatusError):
745-
self.client.post(
746-
"/classifications/universal",
747-
body=cast(
748-
object,
749-
maybe_transform(
750-
dict(
751-
model="kanon-universal-classifier",
752-
query="This is a confidentiality clause.",
753-
texts=["I agree not to tell anyone about the document."],
754-
),
755-
UniversalCreateParams,
756-
),
757-
),
758-
cast_to=httpx.Response,
759-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
760-
)
761-
731+
client.classifications.universal.with_streaming_response.create(
732+
model="kanon-universal-classifier",
733+
query="This is a confidentiality clause.",
734+
texts=["I agree not to tell anyone about the document."],
735+
).__enter__()
762736
assert _get_open_connections(self.client) == 0
763737

764738
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1572,52 +1546,31 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15721546

15731547
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15741548
@pytest.mark.respx(base_url=base_url)
1575-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1549+
async def test_retrying_timeout_errors_doesnt_leak(
1550+
self, respx_mock: MockRouter, async_client: AsyncIsaacus
1551+
) -> None:
15761552
respx_mock.post("/classifications/universal").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15771553

15781554
with pytest.raises(APITimeoutError):
1579-
await self.client.post(
1580-
"/classifications/universal",
1581-
body=cast(
1582-
object,
1583-
maybe_transform(
1584-
dict(
1585-
model="kanon-universal-classifier",
1586-
query="This is a confidentiality clause.",
1587-
texts=["I agree not to tell anyone about the document."],
1588-
),
1589-
UniversalCreateParams,
1590-
),
1591-
),
1592-
cast_to=httpx.Response,
1593-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1594-
)
1555+
await async_client.classifications.universal.with_streaming_response.create(
1556+
model="kanon-universal-classifier",
1557+
query="This is a confidentiality clause.",
1558+
texts=["I agree not to tell anyone about the document."],
1559+
).__aenter__()
15951560

15961561
assert _get_open_connections(self.client) == 0
15971562

15981563
@mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15991564
@pytest.mark.respx(base_url=base_url)
1600-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1565+
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncIsaacus) -> None:
16011566
respx_mock.post("/classifications/universal").mock(return_value=httpx.Response(500))
16021567

16031568
with pytest.raises(APIStatusError):
1604-
await self.client.post(
1605-
"/classifications/universal",
1606-
body=cast(
1607-
object,
1608-
maybe_transform(
1609-
dict(
1610-
model="kanon-universal-classifier",
1611-
query="This is a confidentiality clause.",
1612-
texts=["I agree not to tell anyone about the document."],
1613-
),
1614-
UniversalCreateParams,
1615-
),
1616-
),
1617-
cast_to=httpx.Response,
1618-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1619-
)
1620-
1569+
await async_client.classifications.universal.with_streaming_response.create(
1570+
model="kanon-universal-classifier",
1571+
query="This is a confidentiality clause.",
1572+
texts=["I agree not to tell anyone about the document."],
1573+
).__aenter__()
16211574
assert _get_open_connections(self.client) == 0
16221575

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

0 commit comments

Comments
 (0)