From 1152939ecd3a7c7d72d6ea64fe59dcb4d065a171 Mon Sep 17 00:00:00 2001 From: Joseph Lawson Date: Wed, 29 Oct 2014 11:59:41 -0400 Subject: [PATCH] add notification arns to cloudformation --- moto/cloudformation/models.py | 7 ++++--- moto/cloudformation/responses.py | 11 +++++++++++ .../test_cloudformation_stack_crud.py | 13 +++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/moto/cloudformation/models.py b/moto/cloudformation/models.py index 3df740e66..81fa8f840 100644 --- a/moto/cloudformation/models.py +++ b/moto/cloudformation/models.py @@ -9,9 +9,10 @@ from .exceptions import ValidationError class FakeStack(object): - def __init__(self, stack_id, name, template): + def __init__(self, stack_id, name, template, notification_arns=None): self.stack_id = stack_id self.name = name + self.notification_arns = notification_arns if notification_arns else [] self.template = template self.status = 'CREATE_COMPLETE' @@ -39,9 +40,9 @@ class CloudFormationBackend(BaseBackend): self.stacks = {} self.deleted_stacks = {} - def create_stack(self, name, template): + def create_stack(self, name, template, notification_arns=None): stack_id = generate_stack_id(name) - new_stack = FakeStack(stack_id=stack_id, name=name, template=template) + new_stack = FakeStack(stack_id=stack_id, name=name, template=template, notification_arns=notification_arns) self.stacks[stack_id] = new_stack return new_stack diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index 1e4b73764..a9f2cafee 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -12,10 +12,12 @@ class CloudFormationResponse(BaseResponse): def create_stack(self): stack_name = self._get_param('StackName') stack_body = self._get_param('TemplateBody') + stack_notification_arns = self._get_multi_param('NotificationARNs.member') stack = cloudformation_backend.create_stack( name=stack_name, template=stack_body, + notification_arns=stack_notification_arns ) stack_body = { 'CreateStackResponse': { @@ -89,6 +91,15 @@ DESCRIBE_STACKS_TEMPLATE = """ {{ stack.stack_id }} 2010-07-27T22:28:28Z {{ stack.status }} + {% if stack.notification_arns %} + + {% for notification_arn in stack.notification_arns %} + {{ notification_arn }} + {% endfor %} + + {% else %} + + {% endif %} false {% for output in stack.stack_outputs %} diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud.py b/tests/test_cloudformation/test_cloudformation_stack_crud.py index 477272a33..4ab7b2062 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud.py @@ -38,6 +38,19 @@ def test_create_stack(): stack.get_template().should.equal(dummy_template) +@mock_cloudformation +def test_create_stack_with_notification_arn(): + conn = boto.connect_cloudformation() + conn.create_stack( + "test_stack_with_notifications", + template_body=dummy_template_json, + notification_arns='arn:aws:sns:us-east-1:123456789012:fake-queue' + ) + + stack = conn.describe_stacks()[0] + [n.value for n in stack.notification_arns].should.contain('arn:aws:sns:us-east-1:123456789012:fake-queue') + + @mock_cloudformation def test_describe_stack_by_name(): conn = boto.connect_cloudformation()