From 9970be2309da2456e5f80cb558c62aa277dc99e0 Mon Sep 17 00:00:00 2001 From: usmangani1 Date: Mon, 2 Nov 2020 14:26:18 +0530 Subject: [PATCH] Fix: Adding alarm arn to describe alarms response (#3409) * Fix: adding alarm arn to describe alarms response * Fix:Delete subscriptions on delete topic * modified tests Co-authored-by: usmankb --- moto/cloudwatch/models.py | 7 ++++++- moto/cloudwatch/responses.py | 5 +++-- moto/cloudwatch/utils.py | 4 ++++ tests/test_cloudwatch/test_cloudwatch.py | 3 +++ tests/test_cloudwatch/test_cloudwatch_boto3.py | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/moto/cloudwatch/models.py b/moto/cloudwatch/models.py index b81347313..772672e0e 100644 --- a/moto/cloudwatch/models.py +++ b/moto/cloudwatch/models.py @@ -9,7 +9,7 @@ from moto.logs import logs_backends from datetime import datetime, timedelta from dateutil.tz import tzutc from uuid import uuid4 -from .utils import make_arn_for_dashboard +from .utils import make_arn_for_dashboard, make_arn_for_alarm from dateutil import parser from moto.core import ACCOUNT_ID as DEFAULT_ACCOUNT_ID @@ -106,8 +106,10 @@ class FakeAlarm(BaseModel): insufficient_data_actions, unit, actions_enabled, + region="us-east-1", ): self.name = name + self.alarm_arn = make_arn_for_alarm(region, DEFAULT_ACCOUNT_ID, name) self.namespace = namespace self.metric_name = metric_name self.metric_data_queries = metric_data_queries @@ -280,6 +282,7 @@ class CloudWatchBackend(BaseBackend): insufficient_data_actions, unit, actions_enabled, + region="us-east-1", ): alarm = FakeAlarm( name, @@ -299,7 +302,9 @@ class CloudWatchBackend(BaseBackend): insufficient_data_actions, unit, actions_enabled, + region, ) + self.alarms[name] = alarm return alarm diff --git a/moto/cloudwatch/responses.py b/moto/cloudwatch/responses.py index c4b427dc6..159e24425 100644 --- a/moto/cloudwatch/responses.py +++ b/moto/cloudwatch/responses.py @@ -80,6 +80,7 @@ class CloudWatchResponse(BaseResponse): insufficient_data_actions, unit, actions_enabled, + self.region, ) template = self.response_template(PUT_METRIC_ALARM_TEMPLATE) return template.render(alarm=alarm) @@ -287,7 +288,7 @@ DESCRIBE_ALARMS_TEMPLATE = """