From e5675e953315a8d5b651f07d14bd2871afc99fca Mon Sep 17 00:00:00 2001 From: Hugo Lopes Tavares Date: Mon, 5 Oct 2015 15:21:30 -0400 Subject: [PATCH] Change CloudFormationResponse.get_template() to return `GetTemplateResponse/GetTemplateResult/TemplateBody` --- moto/cloudformation/responses.py | 14 +++++- .../test_cloudformation_stack_crud.py | 48 +++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/moto/cloudformation/responses.py b/moto/cloudformation/responses.py index 28db697cf..c5196b2df 100644 --- a/moto/cloudformation/responses.py +++ b/moto/cloudformation/responses.py @@ -86,9 +86,19 @@ class CloudFormationResponse(BaseResponse): def get_template(self): name_or_stack_id = self.querystring.get('StackName')[0] - stack = self.cloudformation_backend.get_stack(name_or_stack_id) - return stack.template + + response = { + "GetTemplateResponse": { + "GetTemplateResult": { + "TemplateBody": stack.template, + "ResponseMetadata": { + "RequestId": "2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE" + } + } + } + } + return json.dumps(response) def update_stack(self): stack_name = self._get_param('StackName') diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud.py b/tests/test_cloudformation/test_cloudformation_stack_crud.py index 236c33e7d..5ca20fe04 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud.py @@ -40,7 +40,17 @@ def test_create_stack(): stack = conn.describe_stacks()[0] stack.stack_name.should.equal('test_stack') - stack.get_template().should.equal(dummy_template) + stack.get_template().should.equal({ + 'GetTemplateResponse': { + 'GetTemplateResult': { + 'TemplateBody': dummy_template_json, + 'ResponseMetadata': { + 'RequestId': '2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE' + } + } + } + + }) @mock_cloudformation @@ -83,7 +93,18 @@ def test_create_stack_from_s3_url(): stack = conn.describe_stacks()[0] stack.stack_name.should.equal('new-stack') - stack.get_template().should.equal(dummy_template) + stack.get_template().should.equal( + { + 'GetTemplateResponse': { + 'GetTemplateResult': { + 'TemplateBody': dummy_template_json, + 'ResponseMetadata': { + 'RequestId': '2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE' + } + } + } + + }) @mock_cloudformation @@ -138,7 +159,17 @@ def test_get_template_by_name(): ) template = conn.get_template("test_stack") - template.should.equal(dummy_template) + template.should.equal({ + 'GetTemplateResponse': { + 'GetTemplateResult': { + 'TemplateBody': dummy_template_json, + 'ResponseMetadata': { + 'RequestId': '2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE' + } + } + } + + }) @mock_cloudformation @@ -243,4 +274,13 @@ def test_stack_tags(): # conn.update_stack("test_stack", dummy_template_json2) # stack = conn.describe_stacks()[0] -# stack.get_template().should.equal(dummy_template2) +# stack.get_template().should.equal({ +# 'GetTemplateResponse': { +# 'GetTemplateResult': { +# 'TemplateBody': dummy_template_json2, +# 'ResponseMetadata': { +# 'RequestId': '2d06e36c-ac1d-11e0-a958-f9382b6eb86bEXAMPLE' +# } +# } +# } +# })