Exemplo n.º 1
0
 def test_no_data(self):
     mock_conn = Mock()
     mock_conn.get_metric_data.return_value = {
         'MetricDataResults': [],
         'NextToken': 'foo',
         'Messages': [],
         'ResponseMetadata': {
             'RequestId': '77a86d3c-16e1-47c5-b2d1-0f7d81d48a05',
             'HTTPStatusCode': 200,
             'HTTPHeaders': {
                 'x-amzn-requestid': '70f7d81d48a05',
                 'content-type': 'text/xml',
                 'content-length': '796',
                 'date': 'Tue, 22 Sep 2020 12:26:36 GMT'
             },
             'RetryAttempts': 0
         }
     }
     cls = AwsServiceTester(1, 2, {'foo': 'bar'}, None)
     with patch(
             'awslimitchecker.services.base._AwsService._cloudwatch_connection',
             autospec=True) as m_cw_conn:
         m_cw_conn.return_value = mock_conn
         res = cls._get_cloudwatch_usage_latest([{
             'Name': 'foo',
             'Value': 'bar'
         }, {
             'Name': 'baz',
             'Value': 'blam'
         }],
                                                metric_name='MyMetric',
                                                period=3600)
     assert res == 0
     assert m_cw_conn.mock_calls == [call(cls)]
     assert mock_conn.mock_calls == [
         call.get_metric_data(MetricDataQueries=[{
             'Id': 'id',
             'MetricStat': {
                 'Metric': {
                     'Namespace':
                     'AWS/Usage',
                     'MetricName':
                     'MyMetric',
                     'Dimensions': [{
                         'Name': 'foo',
                         'Value': 'bar'
                     }, {
                         'Name': 'baz',
                         'Value': 'blam'
                     }]
                 },
                 'Period': 3600,
                 'Stat': 'Average'
             }
         }],
                              StartTime=datetime(2020, 9, 22, 11, 26, 00),
                              EndTime=datetime(2020, 9, 22, 12, 26, 00),
                              ScanBy='TimestampDescending',
                              MaxDatapoints=1)
     ]
Exemplo n.º 2
0
 def test_exception(self):
     mock_conn = Mock()
     mock_conn.get_metric_data.side_effect = ClientError(
         {
             'ResponseMetadata': {
                 'HTTPStatusCode': 503,
                 'RequestId': '7d74c6f0-c789-11e5-82fe-a96cdaa6d564'
             },
             'Error': {
                 'Message': 'Service Unavailable',
                 'Code': '503'
             }
         }, 'GetMetricData')
     cls = AwsServiceTester(1, 2, {'foo': 'bar'}, None)
     with patch(
             'awslimitchecker.services.base._AwsService._cloudwatch_connection',
             autospec=True) as m_cw_conn:
         m_cw_conn.return_value = mock_conn
         res = cls._get_cloudwatch_usage_latest([{
             'Name': 'foo',
             'Value': 'bar'
         }, {
             'Name': 'baz',
             'Value': 'blam'
         }],
                                                metric_name='MyMetric',
                                                period=3600)
     assert res == 0
     assert m_cw_conn.mock_calls == [call(cls)]
     assert mock_conn.mock_calls == [
         call.get_metric_data(MetricDataQueries=[{
             'Id': 'id',
             'MetricStat': {
                 'Metric': {
                     'Namespace':
                     'AWS/Usage',
                     'MetricName':
                     'MyMetric',
                     'Dimensions': [{
                         'Name': 'foo',
                         'Value': 'bar'
                     }, {
                         'Name': 'baz',
                         'Value': 'blam'
                     }]
                 },
                 'Period': 3600,
                 'Stat': 'Average'
             }
         }],
                              StartTime=datetime(2020, 9, 22, 11, 26, 00),
                              EndTime=datetime(2020, 9, 22, 12, 26, 00),
                              ScanBy='TimestampDescending',
                              MaxDatapoints=1)
     ]