Skip to content

Commit 6f1d30e

Browse files
committed
fix(python): waitForApiKey consistency
1 parent d3a23fb commit 6f1d30e

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

templates/python/search_helpers.mustache

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555

5656
async def wait_for_api_key(
5757
self,
58-
operation: str,
5958
key: str,
59+
operation: str,
6060
api_key: Optional[ApiKey] = None,
6161
max_retries: int = 50,
6262
timeout: RetryTimeout = RetryTimeout(),
6363
request_options: Optional[Union[dict, RequestOptions]] = None,
64-
) -> GetApiKeyResponse:
64+
) -> GetApiKeyResponse | None:
6565
"""
6666
Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
6767
"""
@@ -72,26 +72,30 @@
7272
"`apiKey` is required when waiting for an `update` operation."
7373
)
7474

75-
async def _func(_prev: GetApiKeyResponse) -> GetApiKeyResponse:
75+
async def _func(_prev: GetApiKeyResponse | None) -> GetApiKeyResponse | None:
7676
try:
7777
return await self.get_api_key(key=key, request_options=request_options)
7878
except RequestException as e:
7979
if e.status_code == 404 and (operation == "delete" or operation == "add"):
8080
return None
8181
raise e
8282

83-
def _aggregator(_: GetApiKeyResponse) -> None:
83+
def _aggregator(_: GetApiKeyResponse | None) -> None:
8484
self._retry_count += 1
8585

86-
def _validate(_resp: GetApiKeyResponse) -> bool:
86+
def _validate(_resp: GetApiKeyResponse | None) -> bool:
8787
if operation == "update":
88-
for field in api_key:
89-
if isinstance(api_key[field], list) and isinstance(_resp[field], list):
90-
if len(api_key[field]) != len(_resp[field]) or any(
91-
v != _resp[field][i] for i, v in enumerate(api_key[field])
88+
resp_dict = _resp.to_dict()
89+
api_key_dict = api_key.to_dict() if isinstance(api_key, ApiKey) else api_key
90+
for field in api_key_dict:
91+
if isinstance(api_key_dict[field], list) and isinstance(
92+
resp_dict[field], list
93+
):
94+
if len(api_key_dict[field]) != len(resp_dict[field]) or any(
95+
v != resp_dict[field][i] for i, v in enumerate(api_key_dict[field])
9296
):
9397
return False
94-
elif api_key[field] != _resp[field]:
98+
elif api_key_dict[field] != resp_dict[field]:
9599
return False
96100
return True
97101
elif operation == "add":

templates/python/tests/client/suite.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}:
5353
assert (_req if isinstance(_req, dict) else [elem.to_dict() for elem in _req] if isinstance(_req, list) else _req.to_dict()) == loads("""{{{match.parameters}}}""")
5454
{{/matchIsJSON}}
5555
{{^matchIsJSON}}
56+
{{#matchIsNull}}
57+
assert _req is None
58+
{{/matchIsNull}}
59+
{{^matchIsNull}}
5660
assert _req == """{{{match}}}"""
61+
{{/matchIsNull}}
5762
{{/matchIsJSON}}
5863
{{/testResponse}}
5964
{{/match}}

0 commit comments

Comments
 (0)