1
1
from typing import Callable
2
- import pytest
3
2
3
+ import pytest
4
4
from botocore .stub import Stubber
5
5
6
6
from aws_lambda_powertools .utilities .batch import PartialSQSProcessor , partial_sqs_processor
@@ -36,15 +36,17 @@ def handler(record):
36
36
37
37
38
38
def test_partial_sqs_processor_context_with_failure (sqs_event_factory , record_handler ):
39
- """ Test processor with one record failing """
39
+ """
40
+ Test processor with one failing record
41
+ """
40
42
processor = PartialSQSProcessor ()
41
43
42
44
fail_record = sqs_event_factory ("fail" )
43
45
success_record = sqs_event_factory ("success" )
44
46
45
47
records = [fail_record , success_record ]
46
48
47
- response = {"Successful" : [{"Id" : fail_record ["messageId" ]}, ], "Failed" : []}
49
+ response = {"Successful" : [{"Id" : fail_record ["messageId" ]}], "Failed" : []}
48
50
49
51
with Stubber (processor .client ) as stubber :
50
52
stubber .add_response ("delete_message_batch" , response )
@@ -61,7 +63,10 @@ def test_partial_sqs_processor_context_with_failure(sqs_event_factory, record_ha
61
63
62
64
63
65
def test_partial_sqs_processor_context_only_success (sqs_event_factory , record_handler ):
64
- """ Test processor without failure """
66
+ """
67
+ Test processor without failure
68
+ """
69
+
65
70
processor = PartialSQSProcessor ()
66
71
67
72
first_record = sqs_event_factory ("success" )
@@ -79,7 +84,10 @@ def test_partial_sqs_processor_context_only_success(sqs_event_factory, record_ha
79
84
80
85
81
86
def test_partial_sqs_processor_context_multiple_calls (sqs_event_factory , record_handler ):
82
- """ Test processor without failure """
87
+ """
88
+ Test processor without failure
89
+ """
90
+
83
91
processor = PartialSQSProcessor ()
84
92
85
93
first_record = sqs_event_factory ("success" )
@@ -97,7 +105,10 @@ def test_partial_sqs_processor_context_multiple_calls(sqs_event_factory, record_
97
105
98
106
99
107
def test_partial_sqs_processor_middleware_with_default (sqs_event_factory , record_handler ):
100
- """ Test middleware with default partial processor """
108
+ """
109
+ Test middleware with default partial processor
110
+ """
111
+
101
112
processor = PartialSQSProcessor ()
102
113
103
114
@partial_sqs_processor (record_handler = record_handler , processor = processor )
@@ -107,7 +118,7 @@ def lambda_handler(event, context):
107
118
fail_record = sqs_event_factory ("fail" )
108
119
109
120
event = {"Records" : [sqs_event_factory ("fail" ), sqs_event_factory ("success" )]}
110
- response = {"Successful" : [{"Id" : fail_record ["messageId" ]}, ], "Failed" : []}
121
+ response = {"Successful" : [{"Id" : fail_record ["messageId" ]}], "Failed" : []}
111
122
112
123
with Stubber (processor .client ) as stubber :
113
124
stubber .add_response ("delete_message_batch" , response )
@@ -120,7 +131,10 @@ def lambda_handler(event, context):
120
131
121
132
122
133
def test_partial_sqs_processor_middleware_with_custom (capsys , sqs_event_factory , record_handler ):
123
- """ Test middle with custom partial processor """
134
+ """
135
+ Test middle with custom partial processor
136
+ """
137
+
124
138
class CustomProcessor (PartialSQSProcessor ):
125
139
def failure_handler (self , record , exception ):
126
140
print ("Oh no ! It's a failure." )
@@ -135,7 +149,7 @@ def lambda_handler(event, context):
135
149
fail_record = sqs_event_factory ("fail" )
136
150
137
151
event = {"Records" : [sqs_event_factory ("fail" ), sqs_event_factory ("success" )]}
138
- response = {"Successful" : [{"Id" : fail_record ["messageId" ]}, ], "Failed" : []}
152
+ response = {"Successful" : [{"Id" : fail_record ["messageId" ]}], "Failed" : []}
139
153
140
154
with Stubber (processor .client ) as stubber :
141
155
stubber .add_response ("delete_message_batch" , response )
0 commit comments