Skip to content

Commit 7447978

Browse files
committed
Create test_cloudwatch.py
Add ambiguous error test
1 parent e86184a commit 7447978

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
14+
15+
import botocore.session
16+
from botocore.exceptions import ClientError
17+
18+
19+
def test_ambiguous_error_parsing():
20+
# We map errors from services to modeled errors based on the error code, but
21+
# cloudwatch has two errors that are both modeled to the `ResourceNotFound`
22+
# code: `DashboardNotFoundError` and `ResourceNotFound`. Botocore picks the one
23+
# that is defined later, which in this case is `ResourceNotFound`. This test
24+
# ensures that we continue to select the latter error going forward.
25+
session = botocore.session.get_session()
26+
client = session.create_client('cloudwatch', region_name='us-west-2')
27+
try:
28+
client.get_dashboard(DashboardName='dashboard-which-does-not-exist')
29+
assert False, "No error raised for non-existant dashboard"
30+
except Exception as exception:
31+
exception_class = exception.__class__
32+
error_response = exception.response['Error']
33+
assert isinstance(exception, ClientError)
34+
assert (
35+
f"{exception_class.__module__}.{exception_class.__name__}"
36+
== 'botocore.errorfactory.ResourceNotFound'
37+
)
38+
assert error_response['Type'] == 'Sender'
39+
assert error_response['Code'] == 'ResourceNotFound'

0 commit comments

Comments
 (0)