From 143134816155bc70e4c17a2a594394b2b4335737 Mon Sep 17 00:00:00 2001 From: usmankb Date: Sat, 2 May 2020 01:33:58 +0530 Subject: [PATCH] Fix SQS send_message_batch empty array Exception handling --- moto/sqs/responses.py | 3 +++ tests/test_sqs/test_sqs.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 8acea0799..f5481cc10 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -285,6 +285,9 @@ class SQSResponse(BaseResponse): "MessageAttributes": message_attributes, } + if entries == {}: + raise EmptyBatchRequest() + messages = self.sqs_backend.send_message_batch(queue_name, entries) template = self.response_template(SEND_MESSAGE_BATCH_RESPONSE) diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index f2ab8c37c..9deb8d8e2 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -1147,6 +1147,21 @@ def test_send_message_batch_errors(): ) +@mock_sqs +def test_send_message_batch_with_empty_list(): + client = boto3.client("sqs", region_name="us-east-1") + + response = client.create_queue(QueueName="test-queue") + queue_url = response["QueueUrl"] + + client.send_message_batch.when.called_with( + QueueUrl=queue_url, Entries=[] + ).should.throw( + ClientError, + "There should be at least one SendMessageBatchRequestEntry in the request.", + ) + + @mock_sqs def test_batch_change_message_visibility(): if os.environ.get("TEST_SERVER_MODE", "false").lower() == "true":