From 81f3cbb54880bdf68fd6f52b9aa30ea25a4b7bd9 Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Tue, 5 Dec 2017 01:25:08 -0800 Subject: [PATCH] fix cloudwatch bug (#1374) * bugfix + add tests --- moto/cloudwatch/models.py | 8 ++-- moto/cloudwatch/responses.py | 12 ++--- tests/test_cloudwatch/test_cloudwatch.py | 3 ++ .../test_cloudwatch/test_cloudwatch_boto3.py | 48 +++++++++++++++++++ 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/moto/cloudwatch/models.py b/moto/cloudwatch/models.py index 74499f61e..395f4f0ba 100644 --- a/moto/cloudwatch/models.py +++ b/moto/cloudwatch/models.py @@ -10,6 +10,8 @@ from .utils import make_arn_for_dashboard DEFAULT_ACCOUNT_ID = 123456789012 +_EMPTY_LIST = tuple() + class Dimension(object): @@ -146,14 +148,14 @@ class Statistics: return sum(self.values) @property - def min(self): + def minimum(self): if 'Minimum' not in self.stats: return None return min(self.values) @property - def max(self): + def maximum(self): if 'Maximum' not in self.stats: return None @@ -228,7 +230,7 @@ class CloudWatchBackend(BaseBackend): def put_metric_data(self, namespace, metric_data): for metric_member in metric_data: self.metric_data.append(MetricDatum( - namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member['Dimensions.member'], metric_member.get('Timestamp'))) + namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member.get('Dimensions.member', _EMPTY_LIST), metric_member.get('Timestamp'))) def get_metric_statistics(self, namespace, metric_name, start_time, end_time, period, stats): period_delta = timedelta(seconds=period) diff --git a/moto/cloudwatch/responses.py b/moto/cloudwatch/responses.py index ccb53337c..c080d4620 100644 --- a/moto/cloudwatch/responses.py +++ b/moto/cloudwatch/responses.py @@ -276,27 +276,27 @@ GET_METRIC_STATISTICS_TEMPLATE = """