From fcc85a96453d7aa346ddd43e8fa4cbdf9dd120e9 Mon Sep 17 00:00:00 2001 From: usmangani1 Date: Mon, 19 Oct 2020 13:34:38 +0530 Subject: [PATCH] Including Message attributes when ALL is passed (#3393) * Including Message attributes when ALL is passes * Added tests Co-authored-by: usmankb --- moto/sqs/models.py | 3 ++- tests/test_sqs/test_sqs.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index a837aacdc..34e81be8a 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -537,8 +537,9 @@ class Queue(CloudFormationModel): def _filter_message_attributes(message, input_message_attributes): filtered_message_attributes = {} + return_all = "All" in input_message_attributes for key, value in message.message_attributes.items(): - if key in input_message_attributes: + if return_all or key in input_message_attributes: filtered_message_attributes[key] = value message.message_attributes = filtered_message_attributes diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index 05f4bffab..6305a163a 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -1320,6 +1320,28 @@ def test_message_attributes_in_receive_message(): messages[0].get("MessageAttributes").should.equal(None) + queue.send_message( + MessageBody=body_one, + MessageAttributes={ + "timestamp": { + "StringValue": "1493147359900", + "DataType": "Number.java.lang.Long", + } + }, + ) + messages = conn.receive_message( + QueueUrl=queue.url, MaxNumberOfMessages=2, MessageAttributeNames=["All"] + )["Messages"] + + messages[0]["MessageAttributes"].should.equal( + { + "timestamp": { + "StringValue": "1493147359900", + "DataType": "Number.java.lang.Long", + } + } + ) + @mock_sqs def test_send_message_batch_errors():