Skip to content

Commit 8517dd1

Browse files
author
Tom McCarthy
committed
chore: add test for sqs_batch_processor interface
1 parent 6619ff8 commit 8517dd1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tests/functional/test_utilities_batch.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Callable
2+
from unittest.mock import patch
23

34
import pytest
45
from botocore.config import Config
56
from botocore.stub import Stubber
67

7-
from aws_lambda_powertools.utilities.batch import PartialSQSProcessor, batch_processor
8+
from aws_lambda_powertools.utilities.batch import PartialSQSProcessor, batch_processor, sqs_batch_processor
89

910

1011
@pytest.fixture(scope="module")
@@ -46,6 +47,13 @@ def partial_processor(config) -> PartialSQSProcessor:
4647
return PartialSQSProcessor(config=config)
4748

4849

50+
@pytest.fixture(scope="function")
51+
def stubbed_partial_processor(config) -> PartialSQSProcessor:
52+
processor = PartialSQSProcessor(config=config)
53+
with Stubber(processor.client) as stubber:
54+
yield stubber, processor
55+
56+
4957
def test_partial_sqs_processor_context_with_failure(sqs_event_factory, record_handler, partial_processor):
5058
"""
5159
Test processor with one failing record
@@ -131,6 +139,32 @@ def lambda_handler(event, context):
131139
assert result is True
132140

133141

142+
@patch("aws_lambda_powertools.utilities.batch.middlewares.PartialSQSProcessor")
143+
def test_sqs_batch_processor_middleware(
144+
patched_sqs_processor, sqs_event_factory, record_handler, stubbed_partial_processor
145+
):
146+
"""
147+
Test middleware's integration with PartialSQSProcessor
148+
"""
149+
150+
@sqs_batch_processor(record_handler=record_handler)
151+
def lambda_handler(event, context):
152+
return True
153+
154+
stubber, processor = stubbed_partial_processor
155+
patched_sqs_processor.return_value = processor
156+
157+
fail_record = sqs_event_factory("fail")
158+
159+
event = {"Records": [sqs_event_factory("fail"), sqs_event_factory("success")]}
160+
response = {"Successful": [{"Id": fail_record["messageId"]}], "Failed": []}
161+
stubber.add_response("delete_message_batch", response)
162+
result = lambda_handler(event, {})
163+
stubber.assert_no_pending_responses()
164+
165+
assert result is True
166+
167+
134168
def test_batch_processor_middleware_with_custom_processor(capsys, sqs_event_factory, record_handler, config):
135169
"""
136170
Test middlewares' integration with custom batch processor

0 commit comments

Comments
 (0)