From 3d5d477f7fe620669394cd9df41254262d30465b Mon Sep 17 00:00:00 2001 From: gruebel Date: Sat, 16 Nov 2019 14:46:05 +0100 Subject: [PATCH] Fix sns.publish with number type and 0 value --- moto/sns/responses.py | 2 +- tests/test_sns/test_publishing_boto3.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/moto/sns/responses.py b/moto/sns/responses.py index 23964c54a..c2eb3e7c3 100644 --- a/moto/sns/responses.py +++ b/moto/sns/responses.py @@ -77,7 +77,7 @@ class SNSResponse(BaseResponse): transform_value = value["StringValue"] elif "BinaryValue" in value: transform_value = value["BinaryValue"] - if not transform_value: + if transform_value == "": raise InvalidParameterValue( "The message attribute '{0}' must contain non-empty " "message attribute value for message attribute " diff --git a/tests/test_sns/test_publishing_boto3.py b/tests/test_sns/test_publishing_boto3.py index 64669d5e0..5bda0720c 100644 --- a/tests/test_sns/test_publishing_boto3.py +++ b/tests/test_sns/test_publishing_boto3.py @@ -173,6 +173,27 @@ def test_publish_to_sqs_msg_attr_byte_value(): ) +@mock_sqs +@mock_sns +def test_publish_to_sqs_msg_attr_number_type(): + sns = boto3.resource("sns", region_name="us-east-1") + topic = sns.create_topic(Name="test-topic") + sqs = boto3.resource("sqs", region_name="us-east-1") + queue = sqs.create_queue(QueueName="test-queue") + topic.subscribe(Protocol="sqs", Endpoint=queue.attributes["QueueArn"]) + + topic.publish( + Message="test message", + MessageAttributes={"retries": {"DataType": "Number", "StringValue": "0"}}, + ) + + message = json.loads(queue.receive_messages()[0].body) + message["Message"].should.equal("test message") + message["MessageAttributes"].should.equal( + {"retries": {"Type": "Number", "Value": 0}} + ) + + @mock_sns def test_publish_sms(): client = boto3.client("sns", region_name="us-east-1")