diff --git a/moto/core/utils.py b/moto/core/utils.py index fb333ccdc..98d6bdc23 100644 --- a/moto/core/utils.py +++ b/moto/core/utils.py @@ -80,8 +80,8 @@ class convert_flask_to_httpretty_response(object): return response, status, headers -def iso_8601_datetime(datetime): - return datetime.strftime("%Y-%m-%dT%H:%M:%SZ") +def iso_8601_datetime_with_milliseconds(datetime): + return datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + 'Z' def rfc_1123_datetime(datetime): diff --git a/moto/s3/models.py b/moto/s3/models.py index 6e003edda..bbfd571bc 100644 --- a/moto/s3/models.py +++ b/moto/s3/models.py @@ -9,7 +9,7 @@ import codecs import six from moto.core import BaseBackend -from moto.core.utils import iso_8601_datetime, rfc_1123_datetime +from moto.core.utils import iso_8601_datetime_with_milliseconds, rfc_1123_datetime from .exceptions import BucketAlreadyExists, MissingBucket from .utils import clean_key_name, _VersionedKeyStore @@ -71,7 +71,7 @@ class FakeKey(object): @property def last_modified_ISO8601(self): - return iso_8601_datetime(self.last_modified) + return iso_8601_datetime_with_milliseconds(self.last_modified) @property def last_modified_RFC1123(self): diff --git a/moto/sns/models.py b/moto/sns/models.py index 4897c5762..b51d197c3 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -9,7 +9,7 @@ import six from moto.compat import OrderedDict from moto.core import BaseBackend -from moto.core.utils import iso_8601_datetime +from moto.core.utils import iso_8601_datetime_with_milliseconds from moto.sqs import sqs_backends from .utils import make_arn_for_topic, make_arn_for_subscription @@ -69,7 +69,7 @@ class Subscription(object): "TopicArn": self.topic.arn, "Subject": "my subject", "Message": message, - "Timestamp": iso_8601_datetime(datetime.datetime.now()), + "Timestamp": iso_8601_datetime_with_milliseconds(datetime.datetime.now()), "SignatureVersion": "1", "Signature": "EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVSw7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIKRnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc=", "SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem", diff --git a/moto/sts/models.py b/moto/sts/models.py index 3ea6cbd05..224512963 100644 --- a/moto/sts/models.py +++ b/moto/sts/models.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import datetime from moto.core import BaseBackend -from moto.core.utils import iso_8601_datetime +from moto.core.utils import iso_8601_datetime_with_milliseconds class Token(object): @@ -13,7 +13,7 @@ class Token(object): @property def expiration_ISO8601(self): - return iso_8601_datetime(self.expiration) + return iso_8601_datetime_with_milliseconds(self.expiration) class AssumedRole(object): @@ -27,7 +27,7 @@ class AssumedRole(object): @property def expiration_ISO8601(self): - return iso_8601_datetime(self.expiration) + return iso_8601_datetime_with_milliseconds(self.expiration) class STSBackend(BaseBackend): diff --git a/tests/test_ec2/test_spot_instances.py b/tests/test_ec2/test_spot_instances.py index d914b663b..52e430c15 100644 --- a/tests/test_ec2/test_spot_instances.py +++ b/tests/test_ec2/test_spot_instances.py @@ -6,7 +6,7 @@ import sure # noqa from moto import mock_ec2 from moto.backends import get_model -from moto.core.utils import iso_8601_datetime +from moto.core.utils import iso_8601_datetime_with_milliseconds @mock_ec2 @@ -16,8 +16,8 @@ def test_request_spot_instances(): conn.create_security_group('group1', 'description') conn.create_security_group('group2', 'description') - start = iso_8601_datetime(datetime.datetime(2013, 1, 1)) - end = iso_8601_datetime(datetime.datetime(2013, 1, 2)) + start = iso_8601_datetime_with_milliseconds(datetime.datetime(2013, 1, 1)) + end = iso_8601_datetime_with_milliseconds(datetime.datetime(2013, 1, 2)) request = conn.request_spot_instances( price=0.5, image_id='ami-abcd1234', count=1, type='one-time', @@ -145,7 +145,7 @@ def test_tag_spot_instance_request(): request = requests[0] tag_dict = dict(request.tags) - tag_dict.should.equal({'tag1' : 'value1', 'tag2' : 'value2'}) + tag_dict.should.equal({'tag1': 'value1', 'tag2': 'value2'}) @mock_ec2 @@ -161,7 +161,7 @@ def test_get_all_spot_instance_requests_filtering(): request2 = conn.request_spot_instances( price=0.5, image_id='ami-abcd1234', ) - request3 = conn.request_spot_instances( + conn.request_spot_instances( price=0.5, image_id='ami-abcd1234', ) request1[0].add_tag('tag1', 'value1') @@ -169,16 +169,16 @@ def test_get_all_spot_instance_requests_filtering(): request2[0].add_tag('tag1', 'value1') request2[0].add_tag('tag2', 'wrong') - requests = conn.get_all_spot_instance_requests(filters={'state' : 'active'}) + requests = conn.get_all_spot_instance_requests(filters={'state': 'active'}) requests.should.have.length_of(0) - requests = conn.get_all_spot_instance_requests(filters={'state' : 'open'}) + requests = conn.get_all_spot_instance_requests(filters={'state': 'open'}) requests.should.have.length_of(3) - requests = conn.get_all_spot_instance_requests(filters={'tag:tag1' : 'value1'}) + requests = conn.get_all_spot_instance_requests(filters={'tag:tag1': 'value1'}) requests.should.have.length_of(2) - requests = conn.get_all_spot_instance_requests(filters={'tag:tag1' : 'value1', 'tag:tag2' : 'value2'}) + requests = conn.get_all_spot_instance_requests(filters={'tag:tag1': 'value1', 'tag:tag2': 'value2'}) requests.should.have.length_of(1) diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 4f09c406f..4d7df5e05 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -273,7 +273,7 @@ def test_last_modified(): key.set_contents_from_string("some value") rs = bucket.get_all_keys() - rs[0].last_modified.should.equal('2012-01-01T12:00:00Z') + rs[0].last_modified.should.equal('2012-01-01T12:00:00.000Z') bucket.get_key("the-key").last_modified.should.equal('Sun, 01 Jan 2012 12:00:00 GMT') diff --git a/tests/test_s3bucket_path/test_s3bucket_path.py b/tests/test_s3bucket_path/test_s3bucket_path.py index ed26805bf..9b33efe89 100644 --- a/tests/test_s3bucket_path/test_s3bucket_path.py +++ b/tests/test_s3bucket_path/test_s3bucket_path.py @@ -133,7 +133,7 @@ def test_last_modified(): key.set_contents_from_string("some value") rs = bucket.get_all_keys() - rs[0].last_modified.should.equal('2012-01-01T12:00:00Z') + rs[0].last_modified.should.equal('2012-01-01T12:00:00.000Z') bucket.get_key("the-key").last_modified.should.equal('Sun, 01 Jan 2012 12:00:00 GMT') diff --git a/tests/test_sns/test_publishing.py b/tests/test_sns/test_publishing.py index 7566f8d4d..a7d051b63 100644 --- a/tests/test_sns/test_publishing.py +++ b/tests/test_sns/test_publishing.py @@ -75,7 +75,7 @@ def test_publish_to_http(): "TopicArn": ["arn:aws:sns:us-east-1:123456789012:some-topic"], "Subject": ["my subject"], "Message": ["my message"], - "Timestamp": ["2013-01-01T00:00:00Z"], + "Timestamp": ["2013-01-01T00:00:00.000Z"], "SignatureVersion": ["1"], "Signature": ["EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVSw7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIKRnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc="], "SigningCertURL": ["https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"], diff --git a/tests/test_sts/test_sts.py b/tests/test_sts/test_sts.py index dbc0bc439..067ebcce2 100644 --- a/tests/test_sts/test_sts.py +++ b/tests/test_sts/test_sts.py @@ -14,7 +14,7 @@ def test_get_session_token(): conn = boto.connect_sts() token = conn.get_session_token(duration=123) - token.expiration.should.equal('2012-01-01T12:02:03Z') + token.expiration.should.equal('2012-01-01T12:02:03.000Z') token.session_token.should.equal("AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT+FvwqnKwRcOIfrRh3c/LTo6UDdyJwOOvEVPvLXCrrrUtdnniCEXAMPLE/IvU1dYUg2RVAJBanLiHb4IgRmpRV3zrkuWJOgQs8IZZaIv2BXIa2R4OlgkBN9bkUDNCJiBeb/AXlzBBko7b15fjrBs2+cTQtpZ3CYWFXG8C5zqx37wnOE49mRl/+OtkIKGO7fAE") token.access_key.should.equal("AKIAIOSFODNN7EXAMPLE") token.secret_key.should.equal("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY") @@ -26,7 +26,7 @@ def test_get_federation_token(): conn = boto.connect_sts() token = conn.get_federation_token(duration=123, name="Bob") - token.credentials.expiration.should.equal('2012-01-01T12:02:03Z') + token.credentials.expiration.should.equal('2012-01-01T12:02:03.000Z') token.credentials.session_token.should.equal("AQoDYXdzEPT//////////wEXAMPLEtc764bNrC9SAPBSM22wDOk4x4HIZ8j4FZTwdQWLWsKWHGBuFqwAeMicRXmxfpSPfIeoIYRqTflfKD8YUuwthAx7mSEI/qkPpKPi/kMcGdQrmGdeehM4IC1NtBmUpp2wUE8phUZampKsburEDy0KPkyQDYwT7WZ0wq5VSXDvp75YU9HFvlRd8Tx6q6fE8YQcHNVXAkiY9q6d+xo0rKwT38xVqr7ZD0u0iPPkUL64lIZbqBAz+scqKmlzm8FDrypNC9Yjc8fPOLn9FX9KSYvKTr4rvx3iSIlTJabIQwj2ICCR/oLxBA==") token.credentials.access_key.should.equal("AKIAIOSFODNN7EXAMPLE") token.credentials.secret_key.should.equal("wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY") @@ -57,7 +57,7 @@ def test_assume_role(): role = conn.assume_role(s3_role, "session-name", policy, duration_seconds=123) credentials = role.credentials - credentials.expiration.should.equal('2012-01-01T12:02:03Z') + credentials.expiration.should.equal('2012-01-01T12:02:03.000Z') credentials.session_token.should.equal("BQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT+FvwqnKwRcOIfrRh3c/LTo6UDdyJwOOvEVPvLXCrrrUtdnniCEXAMPLE/IvU1dYUg2RVAJBanLiHb4IgRmpRV3zrkuWJOgQs8IZZaIv2BXIa2R4OlgkBN9bkUDNCJiBeb/AXlzBBko7b15fjrBs2+cTQtpZ3CYWFXG8C5zqx37wnOE49mRl/+OtkIKGO7fAE") credentials.access_key.should.equal("AKIAIOSFODNN7EXAMPLE") credentials.secret_key.should.equal("aJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY")