Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update waiters to handle expected boolean values when matching errors #3220

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion botocore/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,15 @@ def acceptor_matches(response):
# response. So response is still a dictionary, and in the case
# of an error response will contain the "Error" and
# "ResponseMetadata" key.
return response.get("Error", {}).get("Code", "") == expected
# When expected is True, accept any error code.
# When expected is False, check if any errors were encountered.
# Otherwise, check for a specific AWS error code.
if expected is True:
return "Error" in response and "Code" in response["Error"]
elif expected is False:
return "Error" not in response
else:
return response.get("Error", {}).get("Code", "") == expected

return acceptor_matches

Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_waiters.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ def test_single_waiter_supports_error(self):
success_acceptor({'Error': {'Code': 'DoesNotExistErorr'}})
)

def test_single_waiter_supports_no_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': False,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({}))
self.assertFalse(success_acceptor({'Error': {'Code': 'ExampleError'}}))

def test_single_waiter_supports_any_error(self):
single_waiter = {
'acceptors': [
{
'state': 'success',
'matcher': 'error',
'expected': True,
}
],
}
single_waiter.update(self.boiler_plate_config)
config = SingleWaiterConfig(single_waiter)
success_acceptor = config.acceptors[0].matcher_func
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError1'}}))
self.assertTrue(success_acceptor({'Error': {'Code': 'ExampleError2'}}))

def test_unknown_matcher(self):
unknown_type = 'arbitrary_type'
single_waiter = {
Expand Down
Loading