Skip to content

Commit 14a4f3c

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent 0bb6eec commit 14a4f3c

File tree

1 file changed

+16
-57
lines changed

1 file changed

+16
-57
lines changed

tests/test_client.py

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

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

4037
from .utils import update_env
4138

@@ -683,44 +680,25 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
683680

684681
@mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
685682
@pytest.mark.respx(base_url=base_url)
686-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
683+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Codex) -> None:
687684
respx_mock.post("/api/projects/").mock(side_effect=httpx.TimeoutException("Test timeout error"))
688685

689686
with pytest.raises(APITimeoutError):
690-
self.client.post(
691-
"/api/projects/",
692-
body=cast(
693-
object,
694-
maybe_transform(
695-
dict(config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
696-
ProjectCreateParams,
697-
),
698-
),
699-
cast_to=httpx.Response,
700-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
701-
)
687+
client.projects.with_streaming_response.create(
688+
config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
689+
).__enter__()
702690

703691
assert _get_open_connections(self.client) == 0
704692

705693
@mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
706694
@pytest.mark.respx(base_url=base_url)
707-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
695+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Codex) -> None:
708696
respx_mock.post("/api/projects/").mock(return_value=httpx.Response(500))
709697

710698
with pytest.raises(APIStatusError):
711-
self.client.post(
712-
"/api/projects/",
713-
body=cast(
714-
object,
715-
maybe_transform(
716-
dict(config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
717-
ProjectCreateParams,
718-
),
719-
),
720-
cast_to=httpx.Response,
721-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
722-
)
723-
699+
client.projects.with_streaming_response.create(
700+
config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
701+
).__enter__()
724702
assert _get_open_connections(self.client) == 0
725703

726704
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1489,44 +1467,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
14891467

14901468
@mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
14911469
@pytest.mark.respx(base_url=base_url)
1492-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1470+
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncCodex) -> None:
14931471
respx_mock.post("/api/projects/").mock(side_effect=httpx.TimeoutException("Test timeout error"))
14941472

14951473
with pytest.raises(APITimeoutError):
1496-
await self.client.post(
1497-
"/api/projects/",
1498-
body=cast(
1499-
object,
1500-
maybe_transform(
1501-
dict(config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
1502-
ProjectCreateParams,
1503-
),
1504-
),
1505-
cast_to=httpx.Response,
1506-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1507-
)
1474+
await async_client.projects.with_streaming_response.create(
1475+
config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
1476+
).__aenter__()
15081477

15091478
assert _get_open_connections(self.client) == 0
15101479

15111480
@mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15121481
@pytest.mark.respx(base_url=base_url)
1513-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1482+
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncCodex) -> None:
15141483
respx_mock.post("/api/projects/").mock(return_value=httpx.Response(500))
15151484

15161485
with pytest.raises(APIStatusError):
1517-
await self.client.post(
1518-
"/api/projects/",
1519-
body=cast(
1520-
object,
1521-
maybe_transform(
1522-
dict(config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"),
1523-
ProjectCreateParams,
1524-
),
1525-
),
1526-
cast_to=httpx.Response,
1527-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1528-
)
1529-
1486+
await async_client.projects.with_streaming_response.create(
1487+
config={}, name="name", organization_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
1488+
).__aenter__()
15301489
assert _get_open_connections(self.client) == 0
15311490

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

0 commit comments

Comments
 (0)