Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit632e659

Browse files
committed
feat(api): OpenAPI spec update
1 parenta561dff commit632e659

File tree

1 file changed

+32
-122
lines changed

1 file changed

+32
-122
lines changed

‎tests/test_client.py‎

Lines changed: 32 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
IntercomError,
2424
APIStatusError,
2525
APITimeoutError,
26-
APIConnectionError,
2726
APIResponseValidationError,
2827
)
2928
fromintercom._base_clientimport (
@@ -45,14 +44,8 @@ def _get_params(client: BaseClient[Any, Any]) -> dict[str, str]:
4544
returndict(url.params)
4645

4746

48-
_original_response_init=cast(Any,httpx.Response.__init__)# type: ignore
49-
50-
51-
def_low_retry_response_init(*args:Any,**kwargs:Any)->Any:
52-
headers=cast("list[tuple[bytes, bytes]]",kwargs["headers"])
53-
headers.append((b"retry-after",b"0.1"))
54-
55-
return_original_response_init(*args,**kwargs)
47+
def_low_retry_timeout(*_args:Any,**_kwargs:Any)->float:
48+
return0.1
5649

5750

5851
def_get_open_connections(client:Intercom|AsyncIntercom)->int:
@@ -702,70 +695,29 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
702695
calculated=client._calculate_retry_timeout(remaining_retries,options,headers)
703696
assertcalculated==pytest.approx(timeout,0.5*0.875)# pyright: ignore[reportUnknownMemberType]
704697

705-
@mock.patch("httpx.Response.__init__",_low_retry_response_init)
706-
deftest_retrying_timeout_errors_doesnt_leak(self)->None:
707-
defraise_for_status(response:httpx.Response)->None:
708-
raisehttpx.TimeoutException("Test timeout error",request=response.request)
709-
710-
withmock.patch("httpx.Response.raise_for_status",raise_for_status):
711-
withpytest.raises(APITimeoutError):
712-
self.client.get(
713-
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
714-
)
715-
716-
assert_get_open_connections(self.client)==0
717-
718-
@mock.patch("httpx.Response.__init__",_low_retry_response_init)
719-
deftest_retrying_runtime_errors_doesnt_leak(self)->None:
720-
defraise_for_status(_response:httpx.Response)->None:
721-
raiseRuntimeError("Test error")
722-
723-
withmock.patch("httpx.Response.raise_for_status",raise_for_status):
724-
withpytest.raises(APIConnectionError):
725-
self.client.get(
726-
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
727-
)
728-
729-
assert_get_open_connections(self.client)==0
730-
731-
@mock.patch("httpx.Response.__init__",_low_retry_response_init)
732-
deftest_retrying_status_errors_doesnt_leak(self)->None:
733-
defraise_for_status(response:httpx.Response)->None:
734-
response.status_code=500
735-
raisehttpx.HTTPStatusError("Test 500 error",response=response,request=response.request)
698+
@mock.patch("intercom._base_client.BaseClient._calculate_retry_timeout",_low_retry_timeout)
699+
@pytest.mark.respx(base_url=base_url)
700+
deftest_retrying_timeout_errors_doesnt_leak(self,respx_mock:MockRouter)->None:
701+
respx_mock.get("/me").mock(side_effect=httpx.TimeoutException("Test timeout error"))
736702

737-
withmock.patch("httpx.Response.raise_for_status",raise_for_status):
738-
withpytest.raises(APIStatusError):
739-
self.client.get(
740-
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
741-
)
703+
withpytest.raises(APITimeoutError):
704+
self.client.get(
705+
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
706+
)
742707

743708
assert_get_open_connections(self.client)==0
744709

710+
@mock.patch("intercom._base_client.BaseClient._calculate_retry_timeout",_low_retry_timeout)
745711
@pytest.mark.respx(base_url=base_url)
746-
deftest_status_error_within_httpx(self,respx_mock:MockRouter)->None:
747-
respx_mock.post("/foo").mock(return_value=httpx.Response(200,json={"foo":"bar"}))
712+
deftest_retrying_status_errors_doesnt_leak(self,respx_mock:MockRouter)->None:
713+
respx_mock.get("/me").mock(return_value=httpx.Response(500))
748714

749-
defon_response(response:httpx.Response)->None:
750-
raisehttpx.HTTPStatusError(
751-
"Simulating an error inside httpx",
752-
response=response,
753-
request=response.request,
715+
withpytest.raises(APIStatusError):
716+
self.client.get(
717+
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
754718
)
755719

756-
client=Intercom(
757-
base_url=base_url,
758-
bearer_token=bearer_token,
759-
_strict_response_validation=True,
760-
http_client=httpx.Client(
761-
event_hooks={
762-
"response": [on_response],
763-
}
764-
),
765-
max_retries=0,
766-
)
767-
withpytest.raises(APIStatusError):
768-
client.post("/foo",cast_to=httpx.Response)
720+
assert_get_open_connections(self.client)==0
769721

770722

771723
classTestAsyncIntercom:
@@ -1413,68 +1365,26 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
14131365
calculated=client._calculate_retry_timeout(remaining_retries,options,headers)
14141366
assertcalculated==pytest.approx(timeout,0.5*0.875)# pyright: ignore[reportUnknownMemberType]
14151367

1416-
@mock.patch("httpx.Response.__init__",_low_retry_response_init)
1417-
asyncdeftest_retrying_timeout_errors_doesnt_leak(self)->None:
1418-
defraise_for_status(response:httpx.Response)->None:
1419-
raisehttpx.TimeoutException("Test timeout error",request=response.request)
1420-
1421-
withmock.patch("httpx.Response.raise_for_status",raise_for_status):
1422-
withpytest.raises(APITimeoutError):
1423-
awaitself.client.get(
1424-
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
1425-
)
1426-
1427-
assert_get_open_connections(self.client)==0
1428-
1429-
@mock.patch("httpx.Response.__init__",_low_retry_response_init)
1430-
asyncdeftest_retrying_runtime_errors_doesnt_leak(self)->None:
1431-
defraise_for_status(_response:httpx.Response)->None:
1432-
raiseRuntimeError("Test error")
1433-
1434-
withmock.patch("httpx.Response.raise_for_status",raise_for_status):
1435-
withpytest.raises(APIConnectionError):
1436-
awaitself.client.get(
1437-
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
1438-
)
1439-
1440-
assert_get_open_connections(self.client)==0
1441-
1442-
@mock.patch("httpx.Response.__init__",_low_retry_response_init)
1443-
asyncdeftest_retrying_status_errors_doesnt_leak(self)->None:
1444-
defraise_for_status(response:httpx.Response)->None:
1445-
response.status_code=500
1446-
raisehttpx.HTTPStatusError("Test 500 error",response=response,request=response.request)
1368+
@mock.patch("intercom._base_client.BaseClient._calculate_retry_timeout",_low_retry_timeout)
1369+
@pytest.mark.respx(base_url=base_url)
1370+
asyncdeftest_retrying_timeout_errors_doesnt_leak(self,respx_mock:MockRouter)->None:
1371+
respx_mock.get("/me").mock(side_effect=httpx.TimeoutException("Test timeout error"))
14471372

1448-
withmock.patch("httpx.Response.raise_for_status",raise_for_status):
1449-
withpytest.raises(APIStatusError):
1450-
awaitself.client.get(
1451-
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
1452-
)
1373+
withpytest.raises(APITimeoutError):
1374+
awaitself.client.get(
1375+
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
1376+
)
14531377

14541378
assert_get_open_connections(self.client)==0
14551379

1380+
@mock.patch("intercom._base_client.BaseClient._calculate_retry_timeout",_low_retry_timeout)
14561381
@pytest.mark.respx(base_url=base_url)
1457-
@pytest.mark.asyncio
1458-
asyncdeftest_status_error_within_httpx(self,respx_mock:MockRouter)->None:
1459-
respx_mock.post("/foo").mock(return_value=httpx.Response(200,json={"foo":"bar"}))
1382+
asyncdeftest_retrying_status_errors_doesnt_leak(self,respx_mock:MockRouter)->None:
1383+
respx_mock.get("/me").mock(return_value=httpx.Response(500))
14601384

1461-
defon_response(response:httpx.Response)->None:
1462-
raisehttpx.HTTPStatusError(
1463-
"Simulating an error inside httpx",
1464-
response=response,
1465-
request=response.request,
1385+
withpytest.raises(APIStatusError):
1386+
awaitself.client.get(
1387+
"/me",cast_to=httpx.Response,options={"headers": {"X-Stainless-Streamed-Raw-Response":"true"}}
14661388
)
14671389

1468-
client=AsyncIntercom(
1469-
base_url=base_url,
1470-
bearer_token=bearer_token,
1471-
_strict_response_validation=True,
1472-
http_client=httpx.AsyncClient(
1473-
event_hooks={
1474-
"response": [on_response],
1475-
}
1476-
),
1477-
max_retries=0,
1478-
)
1479-
withpytest.raises(APIStatusError):
1480-
awaitclient.post("/foo",cast_to=httpx.Response)
1390+
assert_get_open_connections(self.client)==0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp