#2773 - CloudFormation - Set CreationDate
This commit is contained in:
parent
60c98ca836
commit
3fab3f572f
@ -8,6 +8,7 @@ from boto3 import Session
|
||||
|
||||
from moto.compat import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import iso_8601_datetime_without_milliseconds
|
||||
|
||||
from .parsing import ResourceMap, OutputMap
|
||||
from .utils import (
|
||||
@ -240,6 +241,7 @@ class FakeStack(BaseModel):
|
||||
self.output_map = self._create_output_map()
|
||||
self._add_stack_event("CREATE_COMPLETE")
|
||||
self.status = "CREATE_COMPLETE"
|
||||
self.creation_time = datetime.utcnow()
|
||||
|
||||
def _create_resource_map(self):
|
||||
resource_map = ResourceMap(
|
||||
@ -259,6 +261,10 @@ class FakeStack(BaseModel):
|
||||
output_map.create()
|
||||
return output_map
|
||||
|
||||
@property
|
||||
def creation_time_iso_8601(self):
|
||||
return iso_8601_datetime_without_milliseconds(self.creation_time)
|
||||
|
||||
def _add_stack_event(
|
||||
self, resource_status, resource_status_reason=None, resource_properties=None
|
||||
):
|
||||
|
@ -662,7 +662,7 @@ DESCRIBE_STACKS_TEMPLATE = """<DescribeStacksResponse>
|
||||
<member>
|
||||
<StackName>{{ stack.name }}</StackName>
|
||||
<StackId>{{ stack.stack_id }}</StackId>
|
||||
<CreationTime>2010-07-27T22:28:28Z</CreationTime>
|
||||
<CreationTime>{{ stack.creation_time_iso_8601 }}</CreationTime>
|
||||
<StackStatus>{{ stack.status }}</StackStatus>
|
||||
{% if stack.notification_arns %}
|
||||
<NotificationARNs>
|
||||
@ -803,7 +803,7 @@ LIST_STACKS_RESPONSE = """<ListStacksResponse>
|
||||
<StackId>{{ stack.stack_id }}</StackId>
|
||||
<StackStatus>{{ stack.status }}</StackStatus>
|
||||
<StackName>{{ stack.name }}</StackName>
|
||||
<CreationTime>2011-05-23T15:47:44Z</CreationTime>
|
||||
<CreationTime>{{ stack.creation_time_iso_8601 }}</CreationTime>
|
||||
<TemplateDescription>{{ stack.description }}</TemplateDescription>
|
||||
</member>
|
||||
{% endfor %}
|
||||
|
@ -2,6 +2,8 @@ from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime, timedelta
|
||||
import pytz
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
@ -911,6 +913,10 @@ def test_describe_stack_by_name():
|
||||
|
||||
stack = cf_conn.describe_stacks(StackName="test_stack")["Stacks"][0]
|
||||
stack["StackName"].should.equal("test_stack")
|
||||
two_secs_ago = datetime.now(tz=pytz.UTC) - timedelta(seconds=2)
|
||||
assert (
|
||||
two_secs_ago < stack["CreationTime"] < datetime.now(tz=pytz.UTC)
|
||||
), "Stack should have been created recently"
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
|
Loading…
Reference in New Issue
Block a user