|
23 | 23 |
|
24 | 24 | from codex import Codex, AsyncCodex, APIResponseValidationError
|
25 | 25 | from codex._types import Omit
|
26 |
| -from codex._utils import maybe_transform |
27 | 26 | from codex._models import BaseModel, FinalRequestOptions
|
28 |
| -from codex._constants import RAW_RESPONSE_HEADER |
29 | 27 | from codex._exceptions import APIStatusError, APITimeoutError, APIResponseValidationError
|
30 | 28 | from codex._base_client import (
|
31 | 29 | DEFAULT_TIMEOUT,
|
|
35 | 33 | DefaultAsyncHttpxClient,
|
36 | 34 | make_request_options,
|
37 | 35 | )
|
38 |
| -from codex.types.project_create_params import ProjectCreateParams |
39 | 36 |
|
40 | 37 | from .utils import update_env
|
41 | 38 |
|
@@ -683,44 +680,25 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
|
683 | 680 |
|
684 | 681 | @mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
685 | 682 | @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: |
687 | 684 | respx_mock.post("/api/projects/").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
688 | 685 |
|
689 | 686 | 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__() |
702 | 690 |
|
703 | 691 | assert _get_open_connections(self.client) == 0
|
704 | 692 |
|
705 | 693 | @mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
706 | 694 | @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: |
708 | 696 | respx_mock.post("/api/projects/").mock(return_value=httpx.Response(500))
|
709 | 697 |
|
710 | 698 | 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__() |
724 | 702 | assert _get_open_connections(self.client) == 0
|
725 | 703 |
|
726 | 704 | @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
|
1489 | 1467 |
|
1490 | 1468 | @mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1491 | 1469 | @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: |
1493 | 1471 | respx_mock.post("/api/projects/").mock(side_effect=httpx.TimeoutException("Test timeout error"))
|
1494 | 1472 |
|
1495 | 1473 | 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__() |
1508 | 1477 |
|
1509 | 1478 | assert _get_open_connections(self.client) == 0
|
1510 | 1479 |
|
1511 | 1480 | @mock.patch("codex._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
|
1512 | 1481 | @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: |
1514 | 1483 | respx_mock.post("/api/projects/").mock(return_value=httpx.Response(500))
|
1515 | 1484 |
|
1516 | 1485 | 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__() |
1530 | 1489 | assert _get_open_connections(self.client) == 0
|
1531 | 1490 |
|
1532 | 1491 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4])
|
|
0 commit comments