From 89bad393132da86421368ff823138497ab51d771 Mon Sep 17 00:00:00 2001 From: Dan W Anderson Date: Thu, 18 Jan 2018 15:23:27 -0800 Subject: [PATCH 1/3] add redrivepolicy attribute to sqs --- moto/sqs/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 85b69ab0e..dbc170387 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -166,6 +166,7 @@ class Queue(BaseModel): 'MessageRetentionPeriod', 'QueueArn', 'ReceiveMessageWaitTimeSeconds', + 'RedrivePolicy', 'VisibilityTimeout', 'WaitTimeSeconds'] ALLOWED_PERMISSIONS = ('*', 'ChangeMessageVisibility', 'DeleteMessage', 'GetQueueAttributes', From 8959643e5666872bda234efc1c3c94244a5183c4 Mon Sep 17 00:00:00 2001 From: Dan W Anderson Date: Thu, 18 Jan 2018 15:58:11 -0800 Subject: [PATCH 2/3] return redrivepolicy attribute as string --- moto/sqs/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index dbc170387..0a268e9eb 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -286,6 +286,8 @@ class Queue(BaseModel): attr = getattr(self, camelcase_to_underscores(attribute)) if isinstance(attr, bool): attr = str(attr).lower() + elif attribute == 'RedrivePolicy': + attr = json.dumps(attr) result[attribute] = attr return result From 616095602ae0c2e7301687529c1e96723ff20f65 Mon Sep 17 00:00:00 2001 From: Dan W Anderson Date: Thu, 18 Jan 2018 15:58:20 -0800 Subject: [PATCH 3/3] test for redrive policy --- tests/test_sqs/test_sqs.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index c761ec8d9..b91fd7bc7 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -932,3 +932,27 @@ def test_queue_with_dlq(): resp = sqs.list_dead_letter_source_queues(QueueUrl=queue_url1) resp['queueUrls'][0].should.equal(queue_url2) + +@mock_sqs +def test_redrive_policy_available(): + sqs = boto3.client('sqs', region_name='us-east-1') + + resp = sqs.create_queue(QueueName='test-deadletter') + queue_url1 = resp['QueueUrl'] + queue_arn1 = sqs.get_queue_attributes(QueueUrl=queue_url1)['Attributes']['QueueArn'] + redrive_policy = { + 'deadLetterTargetArn': queue_arn1, + 'maxReceiveCount': 1, + } + + resp = sqs.create_queue( + QueueName='test-queue', + Attributes={ + 'RedrivePolicy': json.dumps(redrive_policy) + } + ) + + queue_url2 = resp['QueueUrl'] + attributes = sqs.get_queue_attributes(QueueUrl=queue_url2)['Attributes'] + assert 'RedrivePolicy' in attributes + assert json.loads(attributes['RedrivePolicy']) == redrive_policy