Skip to content

Commit d7920f1

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

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed

tests/test_client.py

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

2424
from contextual import ContextualAI, AsyncContextualAI, APIResponseValidationError
2525
from contextual._types import Omit
26-
from contextual._utils import maybe_transform
2726
from contextual._models import BaseModel, FinalRequestOptions
28-
from contextual._constants import RAW_RESPONSE_HEADER
2927
from contextual._exceptions import APIStatusError, APITimeoutError, ContextualAIError, APIResponseValidationError
3028
from contextual._base_client import (
3129
DEFAULT_TIMEOUT,
@@ -35,7 +33,6 @@
3533
DefaultAsyncHttpxClient,
3634
make_request_options,
3735
)
38-
from contextual.types.agent_create_params import AgentCreateParams
3936

4037
from .utils import update_env
4138

@@ -725,32 +722,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
725722

726723
@mock.patch("contextual._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
727724
@pytest.mark.respx(base_url=base_url)
728-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
725+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: ContextualAI) -> None:
729726
respx_mock.post("/agents").mock(side_effect=httpx.TimeoutException("Test timeout error"))
730727

731728
with pytest.raises(APITimeoutError):
732-
self.client.post(
733-
"/agents",
734-
body=cast(object, maybe_transform(dict(name="Example"), AgentCreateParams)),
735-
cast_to=httpx.Response,
736-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
737-
)
729+
client.agents.with_streaming_response.create(name="xxx").__enter__()
738730

739731
assert _get_open_connections(self.client) == 0
740732

741733
@mock.patch("contextual._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
742734
@pytest.mark.respx(base_url=base_url)
743-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
735+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: ContextualAI) -> None:
744736
respx_mock.post("/agents").mock(return_value=httpx.Response(500))
745737

746738
with pytest.raises(APIStatusError):
747-
self.client.post(
748-
"/agents",
749-
body=cast(object, maybe_transform(dict(name="Example"), AgentCreateParams)),
750-
cast_to=httpx.Response,
751-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
752-
)
753-
739+
client.agents.with_streaming_response.create(name="xxx").__enter__()
754740
assert _get_open_connections(self.client) == 0
755741

756742
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1550,32 +1536,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15501536

15511537
@mock.patch("contextual._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15521538
@pytest.mark.respx(base_url=base_url)
1553-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1539+
async def test_retrying_timeout_errors_doesnt_leak(
1540+
self, respx_mock: MockRouter, async_client: AsyncContextualAI
1541+
) -> None:
15541542
respx_mock.post("/agents").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15551543

15561544
with pytest.raises(APITimeoutError):
1557-
await self.client.post(
1558-
"/agents",
1559-
body=cast(object, maybe_transform(dict(name="Example"), AgentCreateParams)),
1560-
cast_to=httpx.Response,
1561-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1562-
)
1545+
await async_client.agents.with_streaming_response.create(name="xxx").__aenter__()
15631546

15641547
assert _get_open_connections(self.client) == 0
15651548

15661549
@mock.patch("contextual._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15671550
@pytest.mark.respx(base_url=base_url)
1568-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1551+
async def test_retrying_status_errors_doesnt_leak(
1552+
self, respx_mock: MockRouter, async_client: AsyncContextualAI
1553+
) -> None:
15691554
respx_mock.post("/agents").mock(return_value=httpx.Response(500))
15701555

15711556
with pytest.raises(APIStatusError):
1572-
await self.client.post(
1573-
"/agents",
1574-
body=cast(object, maybe_transform(dict(name="Example"), AgentCreateParams)),
1575-
cast_to=httpx.Response,
1576-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1577-
)
1578-
1557+
await async_client.agents.with_streaming_response.create(name="xxx").__aenter__()
15791558
assert _get_open_connections(self.client) == 0
15801559

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

0 commit comments

Comments
 (0)