Skip to content

Commit 834db1c

Browse files
author
Tom McCarthy
committed
chore: improve test coverage, refactor fixtures
1 parent 523535f commit 834db1c

File tree

2 files changed

+227
-58
lines changed

2 files changed

+227
-58
lines changed

tests/functional/idempotency/conftest.py

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,54 @@ def expected_params_update_item(lambda_response, hashed_idempotency_key):
5858
}
5959

6060

61+
@pytest.fixture
62+
def expected_params_update_item_with_validation(lambda_response, hashed_idempotency_key, hashed_validation_key):
63+
return {
64+
"ExpressionAttributeNames": {
65+
"#expiry": "expiration",
66+
"#response_data": "data",
67+
"#status": "status",
68+
"#validation_key": "validation",
69+
},
70+
"ExpressionAttributeValues": {
71+
":expiry": stub.ANY,
72+
":response_data": json.dumps(lambda_response),
73+
":status": "COMPLETED",
74+
":validation_key": hashed_validation_key,
75+
},
76+
"Key": {"id": hashed_idempotency_key},
77+
"TableName": "TEST_TABLE",
78+
"UpdateExpression": "SET #response_data = :response_data, "
79+
"#expiry = :expiry, #status = :status, "
80+
"#validation_key = :validation_key",
81+
}
82+
83+
84+
@pytest.fixture
85+
def expected_params_put_item(hashed_idempotency_key):
86+
return {
87+
"ConditionExpression": "attribute_not_exists(id) OR expiration < :now",
88+
"ExpressionAttributeValues": {":now": stub.ANY},
89+
"Item": {"expiration": stub.ANY, "id": hashed_idempotency_key, "status": "INPROGRESS"},
90+
"TableName": "TEST_TABLE",
91+
}
92+
93+
94+
@pytest.fixture
95+
def expected_params_put_item_with_validation(hashed_idempotency_key, hashed_validation_key):
96+
return {
97+
"ConditionExpression": "attribute_not_exists(id) OR expiration < :now",
98+
"ExpressionAttributeValues": {":now": stub.ANY},
99+
"Item": {
100+
"expiration": stub.ANY,
101+
"id": hashed_idempotency_key,
102+
"status": "INPROGRESS",
103+
"validation": hashed_validation_key,
104+
},
105+
"TableName": "TEST_TABLE",
106+
}
107+
108+
61109
@pytest.fixture
62110
def hashed_idempotency_key(lambda_apigw_event):
63111
return hashlib.md5(json.dumps(lambda_apigw_event["body"]).encode()).hexdigest()
@@ -69,26 +117,23 @@ def hashed_validation_key(lambda_apigw_event):
69117

70118

71119
@pytest.fixture
72-
def persistence_store(config):
73-
persistence_store = DynamoDBPersistenceLayer(event_key_jmespath="body", table_name=TABLE_NAME, boto_config=config)
74-
return persistence_store
75-
76-
77-
@pytest.fixture
78-
def persistence_store_with_cache(config):
120+
def persistence_store(config, request):
79121
persistence_store = DynamoDBPersistenceLayer(
80-
event_key_jmespath="body", table_name=TABLE_NAME, boto_config=config, use_local_cache=True
122+
event_key_jmespath="body",
123+
table_name=TABLE_NAME,
124+
boto_config=config,
125+
use_local_cache=request.param["use_local_cache"],
81126
)
82127
return persistence_store
83128

84129

85130
@pytest.fixture
86-
def persistence_store_with_validation(config):
131+
def persistence_store_with_validation(config, request):
87132
persistence_store = DynamoDBPersistenceLayer(
88133
event_key_jmespath="body",
89134
table_name=TABLE_NAME,
90135
boto_config=config,
91-
use_local_cache=True,
136+
use_local_cache=request.param,
92137
payload_validation_jmespath="requestContext",
93138
)
94139
return persistence_store

0 commit comments

Comments
 (0)