From 9b25d56a3585fcc5a90a8e606b63cacf170d4351 Mon Sep 17 00:00:00 2001 From: Jon Beilke Date: Sat, 6 Oct 2018 01:18:26 -0500 Subject: [PATCH] need datetime for tests since thats what boto3 returns and add default for PendingWindowInDays --- moto/kms/models.py | 2 +- moto/kms/responses.py | 5 ++++- tests/test_kms/test_kms.py | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/moto/kms/models.py b/moto/kms/models.py index 113bd1733..01b3d9711 100644 --- a/moto/kms/models.py +++ b/moto/kms/models.py @@ -160,7 +160,7 @@ class KmsBackend(BaseBackend): self.keys[key_id].key_state = 'Disabled' self.keys[key_id].deletion_date = None - def schedule_key_deletion(self, key_id, pending_window_in_days=30): + def schedule_key_deletion(self, key_id, pending_window_in_days): if key_id in self.keys: if 7 <= pending_window_in_days <= 30: self.keys[key_id].enabled = False diff --git a/moto/kms/responses.py b/moto/kms/responses.py index 831045e3c..7caeafcaa 100644 --- a/moto/kms/responses.py +++ b/moto/kms/responses.py @@ -269,7 +269,10 @@ class KmsResponse(BaseResponse): def schedule_key_deletion(self): key_id = self.parameters.get('KeyId') - pending_window_in_days = self.parameters.get('PendingWindowInDays') + if self.parameters.get('PendingWindowInDays') is None: + pending_window_in_days = 30 + else: + pending_window_in_days = self.parameters.get('PendingWindowInDays') _assert_valid_key_id(self.kms_backend.get_key_id(key_id)) try: return json.dumps({ diff --git a/tests/test_kms/test_kms.py b/tests/test_kms/test_kms.py index b09459e1d..e16bd2cea 100644 --- a/tests/test_kms/test_kms.py +++ b/tests/test_kms/test_kms.py @@ -9,6 +9,7 @@ import sure # noqa from moto import mock_kms, mock_kms_deprecated from nose.tools import assert_raises from freezegun import freeze_time +from datetime import datetime, timedelta @mock_kms_deprecated @@ -658,7 +659,7 @@ def test_schedule_key_deletion(): KeyId=key['KeyMetadata']['KeyId'] ) assert response['KeyId'] == key['KeyMetadata']['KeyId'] - assert response['DeletionDate'] == '2015-01-31T12:00:00.000Z' + assert response['DeletionDate'] == datetime(2015, 1, 31, 12, 0, tzinfo=tzlocal()) result = client.describe_key(KeyId=key['KeyMetadata']['KeyId']) assert result["KeyMetadata"]["Enabled"] == False @@ -676,7 +677,7 @@ def test_schedule_key_deletion_custom(): PendingWindowInDays=7 ) assert response['KeyId'] == key['KeyMetadata']['KeyId'] - assert response['DeletionDate'] == '2015-01-08T12:00:00.000Z' + assert response['DeletionDate'] == datetime(2015, 1, 8, 12, 0, tzinfo=tzlocal()) result = client.describe_key(KeyId=key['KeyMetadata']['KeyId']) assert result["KeyMetadata"]["Enabled"] == False