1010# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111# ANY KIND, either express or implied. See the License for the specific
1212# language governing permissions and limitations under the License.
13-
13+ import pytest
1414
1515import botocore .session
16- from botocore .exceptions import ClientError
1716
1817
1918def test_ambiguous_error_parsing ():
@@ -23,17 +22,15 @@ def test_ambiguous_error_parsing():
2322 # that is defined later, which in this case is `ResourceNotFound`. This test
2423 # ensures that we continue to select the latter error going forward.
2524 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'
25+ cloudwatch = session .create_client ('cloudwatch' , region_name = 'us-west-2' )
26+ with pytest .raises (cloudwatch .exceptions .ResourceNotFound ) as exception :
27+ cloudwatch .get_dashboard (
28+ DashboardName = 'dashboard-which-does-not-exist'
3729 )
38- assert error_response ['Type' ] == 'Sender'
39- assert error_response ['Code' ] == 'ResourceNotFound'
30+
31+ error_response = exception .value .response ['Error' ]
32+ assert error_response ['Type' ] == 'Sender'
33+ assert error_response ['Code' ] == 'ResourceNotFound'
34+ assert (
35+ exception .value .response ['ResponseMetadata' ]['HTTPStatusCode' ] == 404
36+ )
0 commit comments