Skip to content

Commit 38b773a

Browse files
fix(tests): fix: tests which call HTTP endpoints directly with the example parameters
1 parent 6339cd8 commit 38b773a

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

tests/test_client.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from ydc_search_api import YdcSearchAPI, AsyncYdcSearchAPI, APIResponseValidationError
2525
from ydc_search_api._types import Omit
2626
from ydc_search_api._models import BaseModel, FinalRequestOptions
27-
from ydc_search_api._constants import RAW_RESPONSE_HEADER
2827
from ydc_search_api._exceptions import APIStatusError, APITimeoutError, YdcSearchAPIError, APIResponseValidationError
2928
from ydc_search_api._base_client import (
3029
DEFAULT_TIMEOUT,
@@ -723,22 +722,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
723722

724723
@mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
725724
@pytest.mark.respx(base_url=base_url)
726-
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: YdcSearchAPI) -> None:
727726
respx_mock.get("/search").mock(side_effect=httpx.TimeoutException("Test timeout error"))
728727

729728
with pytest.raises(APITimeoutError):
730-
self.client.get("/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}})
729+
client.search.with_streaming_response.query(query="query").__enter__()
731730

732731
assert _get_open_connections(self.client) == 0
733732

734733
@mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
735734
@pytest.mark.respx(base_url=base_url)
736-
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: YdcSearchAPI) -> None:
737736
respx_mock.get("/search").mock(return_value=httpx.Response(500))
738737

739738
with pytest.raises(APIStatusError):
740-
self.client.get("/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}})
741-
739+
client.search.with_streaming_response.query(query="query").__enter__()
742740
assert _get_open_connections(self.client) == 0
743741

744742
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1540,26 +1538,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15401538

15411539
@mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15421540
@pytest.mark.respx(base_url=base_url)
1543-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1541+
async def test_retrying_timeout_errors_doesnt_leak(
1542+
self, respx_mock: MockRouter, async_client: AsyncYdcSearchAPI
1543+
) -> None:
15441544
respx_mock.get("/search").mock(side_effect=httpx.TimeoutException("Test timeout error"))
15451545

15461546
with pytest.raises(APITimeoutError):
1547-
await self.client.get(
1548-
"/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}
1549-
)
1547+
await async_client.search.with_streaming_response.query(query="query").__aenter__()
15501548

15511549
assert _get_open_connections(self.client) == 0
15521550

15531551
@mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15541552
@pytest.mark.respx(base_url=base_url)
1555-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1553+
async def test_retrying_status_errors_doesnt_leak(
1554+
self, respx_mock: MockRouter, async_client: AsyncYdcSearchAPI
1555+
) -> None:
15561556
respx_mock.get("/search").mock(return_value=httpx.Response(500))
15571557

15581558
with pytest.raises(APIStatusError):
1559-
await self.client.get(
1560-
"/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}
1561-
)
1562-
1559+
await async_client.search.with_streaming_response.query(query="query").__aenter__()
15631560
assert _get_open_connections(self.client) == 0
15641561

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

0 commit comments

Comments
 (0)