Skip to content

Commit

Permalink
SQS: delete_message_batch() now validates there's at least one entry (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Aug 30, 2024
1 parent 93d18e4 commit 2e52eac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions moto/sqs/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def __init__(self, message: str):
class EmptyBatchRequest(RESTError):
code = 400

def __init__(self) -> None:
def __init__(self, action: str = "Send") -> None:
super().__init__(
"EmptyBatchRequest",
"There should be at least one SendMessageBatchRequestEntry in the request.",
"AWS.SimpleQueueService.EmptyBatchRequest",
f"There should be at least one {action}MessageBatchRequestEntry in the request.",
)


Expand Down
3 changes: 3 additions & 0 deletions moto/sqs/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ def delete_message_batch(self) -> str:
else:
receipts = self._get_multi_param("DeleteMessageBatchRequestEntry")

if not receipts:
raise EmptyBatchRequest(action="Delete")

for r in receipts:
for key in list(r.keys()):
if key == "Id":
Expand Down
14 changes: 14 additions & 0 deletions tests/test_sqs/test_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,20 @@ def test_delete_message_batch_with_invalid_receipt_id():
]


@sqs_aws_verified()
@pytest.mark.aws_verified
def test_delete_message_batch_with_zero_entries(queue_name=None, queue_url=None):
sqs = boto3.client("sqs", "us-east-1")
with pytest.raises(ClientError) as exc:
sqs.delete_message_batch(QueueUrl=queue_url, Entries=[])
err = exc.value.response["Error"]
assert err["Code"] == "AWS.SimpleQueueService.EmptyBatchRequest"
assert (
err["Message"]
== "There should be at least one DeleteMessageBatchRequestEntry in the request."
)


@mock_aws
def test_message_attributes_in_receive_message():
sqs = boto3.resource("sqs", region_name=REGION)
Expand Down

0 comments on commit 2e52eac

Please sign in to comment.