Merge pull request #433 from spulec/fix-cloudformation-get-template

Change CloudFormationResponse.get_template() to return `GetTemplateResponse/GetTemplateResult/TemplateBody`
This commit is contained in:
Steve Pulec 2015-10-05 18:10:43 -04:00
commit 468f231734
2 changed files with 56 additions and 6 deletions

View File

@ -86,9 +86,19 @@ class CloudFormationResponse(BaseResponse):
def get_template(self): def get_template(self):
name_or_stack_id = self.querystring.get('StackName')[0] name_or_stack_id = self.querystring.get('StackName')[0]
stack = self.cloudformation_backend.get_stack(name_or_stack_id) 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): def update_stack(self):
stack_name = self._get_param('StackName') stack_name = self._get_param('StackName')

View File

@ -40,7 +40,17 @@ def test_create_stack():
stack = conn.describe_stacks()[0] stack = conn.describe_stacks()[0]
stack.stack_name.should.equal('test_stack') 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 @mock_cloudformation
@ -83,7 +93,18 @@ def test_create_stack_from_s3_url():
stack = conn.describe_stacks()[0] stack = conn.describe_stacks()[0]
stack.stack_name.should.equal('new-stack') 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 @mock_cloudformation
@ -138,7 +159,17 @@ def test_get_template_by_name():
) )
template = conn.get_template("test_stack") 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 @mock_cloudformation
@ -243,4 +274,13 @@ def test_stack_tags():
# conn.update_stack("test_stack", dummy_template_json2) # conn.update_stack("test_stack", dummy_template_json2)
# stack = conn.describe_stacks()[0] # 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'
# }
# }
# }
# })