Skip to content

Commit b541374

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

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

tests/test_client.py

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

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

4037
from .utils import update_env
4138

@@ -743,34 +740,23 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str
743740

744741
@mock.patch("gitpod._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
745742
@pytest.mark.respx(base_url=base_url)
746-
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
743+
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Gitpod) -> None:
747744
respx_mock.post("/gitpod.v1.IdentityService/GetAuthenticatedIdentity").mock(
748745
side_effect=httpx.TimeoutException("Test timeout error")
749746
)
750747

751748
with pytest.raises(APITimeoutError):
752-
self.client.post(
753-
"/gitpod.v1.IdentityService/GetAuthenticatedIdentity",
754-
body=cast(object, maybe_transform({}, IdentityGetAuthenticatedIdentityParams)),
755-
cast_to=httpx.Response,
756-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
757-
)
749+
client.identity.with_streaming_response.get_authenticated_identity().__enter__()
758750

759751
assert _get_open_connections(self.client) == 0
760752

761753
@mock.patch("gitpod._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
762754
@pytest.mark.respx(base_url=base_url)
763-
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
755+
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Gitpod) -> None:
764756
respx_mock.post("/gitpod.v1.IdentityService/GetAuthenticatedIdentity").mock(return_value=httpx.Response(500))
765757

766758
with pytest.raises(APIStatusError):
767-
self.client.post(
768-
"/gitpod.v1.IdentityService/GetAuthenticatedIdentity",
769-
body=cast(object, maybe_transform({}, IdentityGetAuthenticatedIdentityParams)),
770-
cast_to=httpx.Response,
771-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
772-
)
773-
759+
client.identity.with_streaming_response.get_authenticated_identity().__enter__()
774760
assert _get_open_connections(self.client) == 0
775761

776762
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -1592,34 +1578,23 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte
15921578

15931579
@mock.patch("gitpod._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
15941580
@pytest.mark.respx(base_url=base_url)
1595-
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1581+
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncGitpod) -> None:
15961582
respx_mock.post("/gitpod.v1.IdentityService/GetAuthenticatedIdentity").mock(
15971583
side_effect=httpx.TimeoutException("Test timeout error")
15981584
)
15991585

16001586
with pytest.raises(APITimeoutError):
1601-
await self.client.post(
1602-
"/gitpod.v1.IdentityService/GetAuthenticatedIdentity",
1603-
body=cast(object, maybe_transform({}, IdentityGetAuthenticatedIdentityParams)),
1604-
cast_to=httpx.Response,
1605-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1606-
)
1587+
await async_client.identity.with_streaming_response.get_authenticated_identity().__aenter__()
16071588

16081589
assert _get_open_connections(self.client) == 0
16091590

16101591
@mock.patch("gitpod._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
16111592
@pytest.mark.respx(base_url=base_url)
1612-
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None:
1593+
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncGitpod) -> None:
16131594
respx_mock.post("/gitpod.v1.IdentityService/GetAuthenticatedIdentity").mock(return_value=httpx.Response(500))
16141595

16151596
with pytest.raises(APIStatusError):
1616-
await self.client.post(
1617-
"/gitpod.v1.IdentityService/GetAuthenticatedIdentity",
1618-
body=cast(object, maybe_transform({}, IdentityGetAuthenticatedIdentityParams)),
1619-
cast_to=httpx.Response,
1620-
options={"headers": {RAW_RESPONSE_HEADER: "stream"}},
1621-
)
1622-
1597+
await async_client.identity.with_streaming_response.get_authenticated_identity().__aenter__()
16231598
assert _get_open_connections(self.client) == 0
16241599

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

0 commit comments

Comments
 (0)