@@ -98,9 +98,9 @@ def expected_params_update_item(serialized_lambda_response, hashed_idempotency_k
98
98
99
99
@pytest .fixture
100
100
def expected_params_update_item_with_validation (
101
- serialized_lambda_response , hashed_idempotency_key , hashed_validation_key
101
+ serialized_lambda_response , hashed_idempotency_key , hashed_validation_key , idempotency_config
102
102
):
103
- return {
103
+ params = {
104
104
"ExpressionAttributeNames" : {
105
105
"#expiry" : "expiration" ,
106
106
"#response_data" : "data" ,
@@ -122,41 +122,48 @@ def expected_params_update_item_with_validation(
122
122
),
123
123
}
124
124
125
+ if idempotency_config .expires_in_progress :
126
+ params ["ExpressionAttributeNames" ]["#in_progress_expiry" ] = "in_progress_expiration"
127
+ params ["ExpressionAttributeValues" ][":in_progress_expiry" ] = stub .ANY
128
+ params ["UpdateExpression" ] += ", #in_progress_expiry = :in_progress_expiry"
129
+
130
+ return params
131
+
125
132
126
133
@pytest .fixture
127
- def expected_params_put_item (hashed_idempotency_key ):
128
- return {
129
- "ConditionExpression" : (
130
- "attribute_not_exists(#id) OR #now < :now OR "
131
- "(attribute_exists(#in_progress_expiry) AND #in_progress_expiry < :now AND #status = :inprogress)"
132
- ),
134
+ def expected_params_put_item (hashed_idempotency_key , idempotency_config ):
135
+ params = {
136
+ "ConditionExpression" : "attribute_not_exists(#id) OR #now < :now" ,
133
137
"ExpressionAttributeNames" : {
134
138
"#id" : "id" ,
135
139
"#now" : "expiration" ,
136
- "#in_progress_expiry" : "in_progress_expiration" ,
137
140
"#status" : "status" ,
138
141
},
139
- "ExpressionAttributeValues" : {":now" : stub .ANY , ":inprogress" : "INPROGRESS" },
142
+ "ExpressionAttributeValues" : {":now" : stub .ANY },
140
143
"Item" : {"expiration" : stub .ANY , "id" : hashed_idempotency_key , "status" : "INPROGRESS" },
141
144
"TableName" : "TEST_TABLE" ,
142
145
}
143
146
147
+ if idempotency_config .expires_in_progress :
148
+ params [
149
+ "ConditionExpression"
150
+ ] += " OR (attribute_exists(#in_progress_expiry) AND #in_progress_expiry < :now AND #status = :inprogress)"
151
+ params ["ExpressionAttributeNames" ]["#in_progress_expiry" ] = "in_progress_expiration"
152
+ params ["ExpressionAttributeValues" ][":inprogress" ] = "INPROGRESS"
153
+
154
+ return params
155
+
144
156
145
157
@pytest .fixture
146
- def expected_params_put_item_with_validation (hashed_idempotency_key , hashed_validation_key ):
147
- return {
148
- "ConditionExpression" : (
149
- "attribute_not_exists(#id) OR #now < :now OR "
150
- "(attribute_exists(#in_progress_expiry) AND "
151
- "#in_progress_expiry < :now AND #status = :inprogress)"
152
- ),
158
+ def expected_params_put_item_with_validation (hashed_idempotency_key , hashed_validation_key , idempotency_config ):
159
+ params = {
160
+ "ConditionExpression" : "attribute_not_exists(#id) OR #now < :now" ,
153
161
"ExpressionAttributeNames" : {
154
162
"#id" : "id" ,
155
- "#in_progress_expiry" : stub .ANY ,
156
- "#now" : stub .ANY ,
163
+ "#now" : "expiration" ,
157
164
"#status" : "status" ,
158
165
},
159
- "ExpressionAttributeValues" : {":now" : stub .ANY , ":inprogress" : "INPROGRESS" },
166
+ "ExpressionAttributeValues" : {":now" : stub .ANY },
160
167
"Item" : {
161
168
"expiration" : stub .ANY ,
162
169
"id" : hashed_idempotency_key ,
@@ -166,6 +173,15 @@ def expected_params_put_item_with_validation(hashed_idempotency_key, hashed_vali
166
173
"TableName" : "TEST_TABLE" ,
167
174
}
168
175
176
+ if idempotency_config .expires_in_progress :
177
+ params [
178
+ "ConditionExpression"
179
+ ] += " OR (attribute_exists(#in_progress_expiry) AND #in_progress_expiry < :now AND #status = :inprogress)"
180
+ params ["ExpressionAttributeNames" ]["#in_progress_expiry" ] = "in_progress_expiration"
181
+ params ["ExpressionAttributeValues" ][":inprogress" ] = "INPROGRESS"
182
+
183
+ return params
184
+
169
185
170
186
@pytest .fixture
171
187
def hashed_idempotency_key (lambda_apigw_event , default_jmespath , lambda_context ):
@@ -203,6 +219,7 @@ def idempotency_config(config, request, default_jmespath):
203
219
event_key_jmespath = request .param .get ("event_key_jmespath" ) or default_jmespath ,
204
220
use_local_cache = request .param ["use_local_cache" ],
205
221
expires_in_progress = request .param .get ("expires_in_progress" ) or False ,
222
+ payload_validation_jmespath = request .param .get ("payload_validation_jmespath" ) or "" ,
206
223
)
207
224
208
225
@@ -211,15 +228,6 @@ def config_without_jmespath(config, request):
211
228
return IdempotencyConfig (use_local_cache = request .param ["use_local_cache" ])
212
229
213
230
214
- @pytest .fixture
215
- def config_with_validation (config , request , default_jmespath ):
216
- return IdempotencyConfig (
217
- event_key_jmespath = default_jmespath ,
218
- use_local_cache = request .param ,
219
- payload_validation_jmespath = "requestContext" ,
220
- )
221
-
222
-
223
231
@pytest .fixture
224
232
def config_with_expires_in_progress (config , request , default_jmespath ):
225
233
return IdempotencyConfig (
0 commit comments