@@ -72,7 +72,7 @@ def test_idempotent_lambda_already_completed(
72
72
lambda_context ,
73
73
):
74
74
"""
75
- Test idempotent decorator where event with matching event key has already been succesfully processed
75
+ Test idempotent decorator where event with matching event key has already been successfully processed
76
76
"""
77
77
78
78
stubber = stub .Stubber (persistence_store .table .meta .client )
@@ -1247,6 +1247,46 @@ def lambda_handler(event, _):
1247
1247
assert handler_result == expected_result
1248
1248
1249
1249
1250
+ @pytest .mark .parametrize ("data" , [None , 0 , False ])
1251
+ def test_idempotent_function_falsy_values (data ):
1252
+ # Scenario to validate we can use idempotent_function with any function
1253
+ # receiving a falsy value (`None`, `False`, `0`, etc.)
1254
+ # shouldn't cause a RuntimeError
1255
+ mock_event = data
1256
+ idempotency_key = f"{ TESTS_MODULE_PREFIX } .test_idempotent_function_falsy_values.<locals>.record_handler#{ hash_idempotency_key (mock_event )} " # noqa: E501
1257
+
1258
+ persistence_layer = MockPersistenceLayer (expected_idempotency_key = idempotency_key )
1259
+ expected_result = {"message" : "Foo" }
1260
+
1261
+ @idempotent_function (persistence_store = persistence_layer , data_keyword_argument = "record" )
1262
+ def record_handler (record ):
1263
+ return expected_result
1264
+
1265
+ # WHEN calling the function
1266
+ result = record_handler (record = mock_event )
1267
+ # THEN we expect the function to execute successfully
1268
+ assert result == expected_result
1269
+
1270
+
1271
+ @pytest .mark .parametrize ("data" , [None , 0 , False ])
1272
+ def test_idempotent_function_falsy_values_with_raise_on_no_idempotency_key (
1273
+ data , persistence_store : DynamoDBPersistenceLayer
1274
+ ):
1275
+ # GIVEN raise_on_no_idempotency_key is True
1276
+ idempotency_config = IdempotencyConfig (event_key_jmespath = "idemKey" , raise_on_no_idempotency_key = True )
1277
+
1278
+ @idempotent_function (data_keyword_argument = "record" , persistence_store = persistence_store , config = idempotency_config )
1279
+ def record_handler (record ):
1280
+ return ValueError ("Should not be raised" )
1281
+
1282
+ # WHEN calling the function
1283
+ with pytest .raises (IdempotencyKeyError ) as e :
1284
+ record_handler (record = data )
1285
+
1286
+ # THEN we expect an idempotency key error message
1287
+ assert "No data found to create a hashed idempotency_key" == e .value .args [0 ]
1288
+
1289
+
1250
1290
def test_idempotent_data_sorting ():
1251
1291
# Scenario to validate same data in different order hashes to the same idempotency key
1252
1292
data_one = {"data" : "test message 1" , "more_data" : "more data 1" }
0 commit comments