Skip to content

Commit ac34729

Browse files
author
Michael Brewer
committed
tests(idempotency): add missing fail test
1 parent 32a4ca2 commit ac34729

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

aws_lambda_powertools/utilities/idempotency/persistence/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class BasePersistenceLayer(ABC):
112112

113113
def __init__(self):
114114
"""Initialize the defaults"""
115+
self.function_name = None
115116
self.configured = False
116117
self.event_key_jmespath: Optional[str] = None
117118
self.event_key_compiled_jmespath = None

tests/functional/idempotency/test_idempotency.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,3 +1036,24 @@ def dummy_handler(event, context):
10361036
dummy_handler(mock_event, lambda_context)
10371037

10381038
assert len(persistence_store.table.method_calls) == 0
1039+
1040+
1041+
@pytest.mark.parametrize("idempotency_config", [{"use_local_cache": True}], indirect=True)
1042+
def test_idempotent_function_duplicates(
1043+
idempotency_config: IdempotencyConfig, persistence_store: DynamoDBPersistenceLayer
1044+
):
1045+
# Scenario to validate the both methods are called
1046+
mock_event = {"data": "value"}
1047+
persistence_store.table = MagicMock()
1048+
1049+
@idempotent_function(data_keyword_argument="data", persistence_store=persistence_store, config=idempotency_config)
1050+
def one(data):
1051+
return "one"
1052+
1053+
@idempotent_function(data_keyword_argument="data", persistence_store=persistence_store, config=idempotency_config)
1054+
def two(data):
1055+
return "two"
1056+
1057+
assert one(data=mock_event) == "one"
1058+
assert two(data=mock_event) == "two"
1059+
assert len(persistence_store.table.method_calls) == 4

0 commit comments

Comments
 (0)