def test_get_limit_check_id_other_exception(self):

        def se_api(language=None):
            response = {
                'ResponseMetadata': {
                    'HTTPStatusCode': 400,
                    'RequestId': '3cc9b2a8-c6e5-11e5-bc1d-b13dcea36176'
                },
                'Error': {
                    'Message': 'foo',
                    'Code': 'SomeOtherException'
                }
            }
            raise ClientError(response, 'operation')

        self.mock_conn.describe_trusted_advisor_checks.side_effect = se_api
        with pytest.raises(ClientError) as excinfo:
            self.cls._get_limit_check_id()
        assert self.mock_conn.mock_calls == [
            call.describe_trusted_advisor_checks(language='en')
        ]
        assert excinfo.value.response['ResponseMetadata'][
                   'HTTPStatusCode'] == 400
        assert excinfo.value.response['Error']['Message'] == 'foo'
        assert excinfo.value.response['Error']['Code'] == 'SomeOtherException'
Ejemplo n.º 2
0
    def test_get_limit_check_id_subscription_required(self):
        def se_api(language=None):
            response = {
                'ResponseMetadata': {
                    'HTTPStatusCode': 400,
                    'RequestId': '3cc9b2a8-c6e5-11e5-bc1d-b13dcea36176'
                },
                'Error': {
                    'Message': 'AWS Premium Support Subscription is required '
                    'to use this service.',
                    'Code': 'SubscriptionRequiredException'
                }
            }
            raise ClientError(response, 'operation')

        assert self.cls.have_ta is True
        self.mock_conn.describe_trusted_advisor_checks.side_effect = se_api
        with patch('awslimitchecker.trustedadvisor'
                   '.logger', autospec=True) as mock_logger:
            res = self.cls._get_limit_check_id()
        assert self.cls.have_ta is False
        assert res == (None, None)
        assert self.mock_conn.mock_calls == [
            call.describe_trusted_advisor_checks(language='en')
        ]
        assert mock_logger.mock_calls == [
            call.debug("Querying Trusted Advisor checks"),
            call.warning(
                "Cannot check TrustedAdvisor: %s",
                'AWS Premium Support Subscription is required to '
                'use this service.')
        ]
    def test_get_limit_check_id_subscription_required(self):

        def se_api(language=None):
            response = {
                'ResponseMetadata': {
                    'HTTPStatusCode': 400,
                    'RequestId': '3cc9b2a8-c6e5-11e5-bc1d-b13dcea36176'
                },
                'Error': {
                    'Message': 'AWS Premium Support Subscription is required '
                               'to use this service.',
                    'Code': 'SubscriptionRequiredException'
                }
            }
            raise ClientError(response, 'operation')

        assert self.cls.have_ta is True
        self.mock_conn.describe_trusted_advisor_checks.side_effect = se_api
        with patch('awslimitchecker.trustedadvisor'
                   '.logger', autospec=True) as mock_logger:
            res = self.cls._get_limit_check_id()
        assert self.cls.have_ta is False
        assert res == (None, None)
        assert self.mock_conn.mock_calls == [
            call.describe_trusted_advisor_checks(language='en')
        ]
        assert mock_logger.mock_calls == [
            call.debug("Querying Trusted Advisor checks"),
            call.warning("Cannot check TrustedAdvisor: %s",
                         'AWS Premium Support Subscription is required to '
                         'use this service.')
        ]
Ejemplo n.º 4
0
 def test_get_limit_check_id(self):
     api_resp = {
         'checks': [
             {
                 'category':
                 'performance',
                 'name':
                 'Service Limits',
                 'id':
                 'bar',
                 'metadata': [
                     'Region', 'Service', 'Limit Name', 'Limit Amount',
                     'Current Usage', 'Status'
                 ],
             },
             {
                 'category': 'fault_tolerance',
                 'name': 'ELB Cross-Zone Load Balancing',
                 'id': 'foo',
             },
         ]
     }
     self.mock_conn.describe_trusted_advisor_checks.return_value = api_resp
     res = self.cls._get_limit_check_id()
     assert res == ('bar', [
         'Region', 'Service', 'Limit Name', 'Limit Amount', 'Current Usage',
         'Status'
     ])
     assert self.mock_conn.mock_calls == [
         call.describe_trusted_advisor_checks(language='en')
     ]
    def test_get_limit_check_id_subscription_required(self):

        def se_api(language):
            status = 400
            reason = 'Bad Request'
            body = {
                'message': 'AWS Premium Support Subscription is required to '
                'use this service.',
                '__type': 'SubscriptionRequiredException'
            }
            raise JSONResponseError(status, reason, body)

        self.mock_conn.describe_trusted_advisor_checks.side_effect = se_api
        assert self.cls.have_ta is True
        with patch('awslimitchecker.trustedadvisor'
                   '.logger', autospec=True) as mock_logger:
            res = self.cls._get_limit_check_id()
        assert self.cls.have_ta is False
        assert res == (None, None)
        assert self.mock_conn.mock_calls == [
            call.describe_trusted_advisor_checks('en')
        ]
        assert mock_logger.mock_calls == [
            call.debug("Querying Trusted Advisor checks"),
            call.warning("Cannot check TrustedAdvisor: %s",
                         "AWS Premium Support "
                         "Subscription is required to use this service.")
        ]
Ejemplo n.º 6
0
    def test_other_exception(self):

        def se_api(language=None):
            response = {
                'ResponseMetadata': {
                    'HTTPStatusCode': 400,
                    'RequestId': '3cc9b2a8-c6e5-11e5-bc1d-b13dcea36176'
                },
                'Error': {
                    'Message': 'foo',
                    'Code': 'SomeOtherException'
                }
            }
            raise ClientError(response, 'operation')

        self.mock_conn.describe_trusted_advisor_checks.side_effect = se_api
        with pytest.raises(ClientError) as excinfo:
            self.cls._get_limit_check_id()
        assert self.mock_conn.mock_calls == [
            call.describe_trusted_advisor_checks(language='en')
        ]
        assert excinfo.value.response['ResponseMetadata'][
                   'HTTPStatusCode'] == 400
        assert excinfo.value.response['Error']['Message'] == 'foo'
        assert excinfo.value.response['Error']['Code'] == 'SomeOtherException'
    def test_get_limit_check_id_other_exception(self):

        def se_api(language):
            status = 400
            reason = 'foobar'
            body = {
                'message': 'other message',
                '__type': 'OtherException'
            }
            raise JSONResponseError(status, reason, body)

        self.mock_conn.describe_trusted_advisor_checks.side_effect = se_api
        with pytest.raises(BotoServerError) as excinfo:
            self.cls._get_limit_check_id()
        assert self.mock_conn.mock_calls == [
            call.describe_trusted_advisor_checks('en')
        ]
        assert excinfo.value.status == 400
        assert excinfo.value.reason == 'foobar'
        assert excinfo.value.body['__type'] == 'OtherException'
 def test_get_limit_check_id_none(self):
     api_resp = {
         'checks': [
             {
                 'category': 'performance',
                 'name': 'Something Else',
                 'id': 'bar',
             },
             {
                 'category': 'fault_tolerance',
                 'name': 'ELB Cross-Zone Load Balancing',
                 'id': 'foo',
             },
         ]
     }
     self.mock_conn.describe_trusted_advisor_checks.return_value = api_resp
     res = self.cls._get_limit_check_id()
     assert res == (None, None)
     assert self.mock_conn.mock_calls == [
         call.describe_trusted_advisor_checks(language='en')
     ]
Ejemplo n.º 9
0
 def test_get_limit_check_id_none(self):
     api_resp = {
         'checks': [
             {
                 'category': 'performance',
                 'name': 'Something Else',
                 'id': 'bar',
             },
             {
                 'category': 'fault_tolerance',
                 'name': 'ELB Cross-Zone Load Balancing',
                 'id': 'foo',
             },
         ]
     }
     self.mock_conn.describe_trusted_advisor_checks.return_value = api_resp
     res = self.cls._get_limit_check_id()
     assert res == (None, None)
     assert self.mock_conn.mock_calls == [
         call.describe_trusted_advisor_checks(language='en')
     ]
 def test_get_limit_check_id(self):
     api_resp = {
         'checks': [
             {
                 'category': 'performance',
                 'name': 'Service Limits',
                 'id': 'bar',
                 'metadata': [
                     'Region',
                     'Service',
                     'Limit Name',
                     'Limit Amount',
                     'Current Usage',
                     'Status'
                 ],
             },
             {
                 'category': 'fault_tolerance',
                 'name': 'ELB Cross-Zone Load Balancing',
                 'id': 'foo',
             },
         ]
     }
     self.mock_conn.describe_trusted_advisor_checks.return_value = api_resp
     res = self.cls._get_limit_check_id()
     assert res == (
         'bar',
         [
             'Region',
             'Service',
             'Limit Name',
             'Limit Amount',
             'Current Usage',
             'Status'
         ]
     )
     assert self.mock_conn.mock_calls == [
         call.describe_trusted_advisor_checks(language='en')
     ]