From b2570d901edcbcaf850f430c7eda1bc45b2ca280 Mon Sep 17 00:00:00 2001 From: Jot Date: Sun, 2 Aug 2015 16:27:08 +0200 Subject: [PATCH] Enabled cloudformation in server mode with some tests --- moto/backends.py | 2 ++ moto/cloudformation/responses.py | 2 +- tests/test_cloudformation/test_server.py | 38 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/moto/backends.py b/moto/backends.py index de323a442..b45e0fa5e 100644 --- a/moto/backends.py +++ b/moto/backends.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from moto.autoscaling import autoscaling_backend from moto.cloudwatch import cloudwatch_backend +from moto.cloudformation import cloudformation_backend from moto.dynamodb import dynamodb_backend from moto.dynamodb2 import dynamodb_backend2 from moto.ec2 import ec2_backend @@ -20,6 +21,7 @@ from moto.route53 import route53_backend BACKENDS = { 'autoscaling': autoscaling_backend, + 'cloudformation': cloudformation_backend, 'cloudwatch': cloudwatch_backend, 'dynamodb': dynamodb_backend, 'dynamodb2': dynamodb_backend2, diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index fe0af6640..e0afa5fa3 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -161,7 +161,7 @@ LIST_STACKS_RESPONSE = """ {% for stack in stacks %} - {{ stack.id }} + {{ stack.stack_id }} {{ stack.status }} {{ stack.name }} 2011-05-23T15:47:44Z diff --git a/tests/test_cloudformation/test_server.py b/tests/test_cloudformation/test_server.py index baffc4882..d45c3dc4a 100644 --- a/tests/test_cloudformation/test_server.py +++ b/tests/test_cloudformation/test_server.py @@ -1 +1,39 @@ from __future__ import unicode_literals + +import json +import urllib +import re +import sure # noqa + +import moto.server as server + +''' +Test the different server responses +''' + +def test_cloudformation_server_get(): + backend = server.create_backend_app("cloudformation") + stack_name = 'test stack' + test_client = backend.test_client() + template_body = { + "Resources": {}, + } + res = test_client.get( + '/?{0}'.format( + urllib.urlencode({ + "Action": "CreateStack", + "StackName": stack_name, + "TemplateBody": json.dumps(template_body) + })), + headers={"Host":"cloudformation.us-east-1.amazonaws.com"} + ) + stack_id = json.loads(res.data)["CreateStackResponse"]["CreateStackResult"]["StackId"] + + res = test_client.get( + '/?Action=ListStacks', + headers={"Host":"cloudformation.us-east-1.amazonaws.com"} + ) + stacks = re.search("(.*)", res.data.decode('utf-8')) + + list_stack_id = stacks.groups()[0] + assert stack_id == list_stack_id