Skip to content

Commit a42e500

Browse files
author
Lucas McDonald
committed
m
1 parent cadec72 commit a42e500

File tree

4 files changed

+198
-39
lines changed

4 files changed

+198
-39
lines changed

DynamoDbEncryption/runtimes/python/test/requests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ def base_exhaustive_scan_request(item):
260260
}
261261

262262

263+
# No exhaustive requests for:
264+
# - transact_write_items
265+
# - transact_get_items
266+
# - batch_write_item
267+
# - batch_get_item
268+
# - batch_execute_statement
269+
# - execute_statement
270+
# - execute_transaction
271+
# The base requests sufficiently test the conversion of the request between client and resource formats
272+
# for items.
273+
263274
# DDB format request functions
264275

265276

DynamoDbEncryption/runtimes/python/test/responses.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,98 @@ def basic_transact_write_items_response(items):
153153
},
154154
}
155155

156+
# No exhaustive response for transact_write_items;
157+
# The basic_transact_write_items_response is sufficient
156158

157159
def basic_transact_get_items_response(items):
158160
"""Get a transact_get_items response in resource (ddb) format for any items."""
159161
return {"Responses": [{"Item": item} for item in items]}
160162

163+
# No exhaustive response for transact_get_items;
164+
# The basic_transact_get_items_response is sufficient
161165

162166
def basic_update_item_response(item):
163167
"""Get an update_item response in resource (ddb) format for any item."""
164168
return {"Attributes": item}
165169

170+
def exhaustive_update_item_response(item):
171+
"""
172+
Get an update_item response in resource (ddb) format for any item.
173+
This is not intended to be a real response that DynamoDB would return,
174+
but the response should contain additional attributes that DynamoDB could return.
175+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
176+
"""
177+
base = basic_update_item_response(item)
178+
additional_keys = {
179+
"ItemCollectionMetrics": {
180+
"ItemCollectionKey": {"partition_key": item["partition_key"]},
181+
},
182+
}
183+
return {**base, **additional_keys}
166184

167185
def basic_delete_item_response(item):
168186
"""Get a delete_item response in resource (ddb) format for any item."""
169187
return {"Attributes": item}
188+
189+
def exhaustive_delete_item_response(item):
190+
"""
191+
Get a delete_item response in resource (ddb) format for any item.
192+
This is not intended to be a real response that DynamoDB would return,
193+
but the response should contain additional attributes that DynamoDB could return.
194+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
195+
"""
196+
base = basic_delete_item_response(item)
197+
additional_keys = {
198+
"ItemCollectionMetrics": {
199+
"ItemCollectionKey": {"partition_key": item["partition_key"]},
200+
},
201+
}
202+
return {**base, **additional_keys}
203+
204+
205+
def basic_execute_statement_response(items):
206+
"""Get an execute_statement response in resource (ddb) format for any items."""
207+
return {"Items": items}
208+
209+
def exhaustive_execute_statement_response(items):
210+
"""
211+
Get an execute_statement response in resource (ddb) format for any items.
212+
This is not intended to be a real response that DynamoDB would return,
213+
but the response should contain additional attributes that DynamoDB could return.
214+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
215+
"""
216+
base = basic_execute_statement_response(items)
217+
additional_keys = {
218+
"LastEvaluatedKey": {
219+
"partition_key": items[-1]["partition_key"],
220+
"sort_key": items[-1]["sort_key"],
221+
},
222+
}
223+
return {**base, **additional_keys}
224+
225+
def basic_execute_transaction_response(items):
226+
"""Get an execute_transaction response in resource (ddb) format for any items."""
227+
return {"Responses": [{"Item": item} for item in items]}
228+
229+
# No exhaustive response for execute_transaction;
230+
# The basic_execute_transaction_response is sufficient
231+
232+
def basic_batch_execute_statement_response(items):
233+
"""Get a batch_execute_statement response in resource (ddb) format for any items."""
234+
return {"Responses": [{"Item": item} for item in items]}
235+
236+
def exhaustive_batch_execute_statement_response(items):
237+
"""
238+
Get a batch_execute_statement response in resource (ddb) format for any items.
239+
This is not intended to be a real response that DynamoDB would return,
240+
but the response should contain additional attributes that DynamoDB could return.
241+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
242+
"""
243+
base = basic_batch_execute_statement_response(items)
244+
base["Responses"][0]["Error"] = {
245+
"Item": {
246+
"partition_key": items[0]["partition_key"],
247+
"sort_key": items[0]["sort_key"],
248+
}
249+
}
250+
return base

DynamoDbEncryption/runtimes/python/test/unit/internal/test_client_to_resource.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,26 @@
5858
basic_batch_get_item_response,
5959
basic_batch_write_item_put_response,
6060
basic_delete_item_response,
61+
exhaustive_delete_item_response,
6162
basic_get_item_response,
6263
basic_put_item_response,
6364
basic_query_response,
6465
basic_scan_response,
6566
basic_transact_get_items_response,
6667
basic_transact_write_items_response,
6768
basic_update_item_response,
69+
exhaustive_update_item_response,
6870
exhaustive_batch_get_item_response,
6971
exhaustive_batch_write_item_put_response,
7072
exhaustive_get_item_response,
7173
exhaustive_put_item_response,
7274
exhaustive_query_response,
7375
exhaustive_scan_response,
76+
exhaustive_execute_statement_response,
77+
basic_execute_statement_response,
78+
basic_execute_transaction_response,
79+
basic_batch_execute_statement_response,
80+
exhaustive_batch_execute_statement_response,
7481
)
7582

7683
client_to_resource_converter = ClientShapeToResourceShapeConverter()
@@ -560,15 +567,13 @@ def test_GIVEN_test_transact_get_items_response_WHEN_client_to_resource_THEN_ret
560567
def test_update_item_request_ddb():
561568
# Select unsigned attribute without loss of generality;
562569
# resource/client logic doesn't care about signed attributes
563-
# TODO: Add exhaustive request
564570
return basic_update_item_request_ddb_unsigned_attribute
565571

566572

567573
@pytest.fixture
568574
def test_update_item_request_dict():
569575
# Select unsigned attribute without loss of generality;
570576
# resource/client logic doesn't care about signed attributes
571-
# TODO: Add exhaustive request
572577
return basic_update_item_request_dict_unsigned_attribute
573578

574579

@@ -584,8 +589,9 @@ def test_GIVEN_test_update_item_request_WHEN_client_to_resource_THEN_returns_dic
584589

585590

586591
@pytest.fixture
587-
def test_update_item_response():
588-
# TODO: Add exhaustive response
592+
def test_update_item_response(use_exhaustive_request):
593+
if use_exhaustive_request:
594+
return exhaustive_update_item_response
589595
return basic_update_item_response
590596

591597

@@ -616,14 +622,20 @@ def test_GIVEN_test_execute_statement_request_WHEN_client_to_resource_THEN_retur
616622
assert dict_item == test_execute_statement_request(test_dict_item)
617623

618624

619-
def test_GIVEN_test_execute_statement_response_WHEN_client_to_resource_THEN_raises_NotImplementedError():
625+
@pytest.fixture
626+
def test_execute_statement_response(use_exhaustive_request):
627+
if use_exhaustive_request:
628+
return exhaustive_execute_statement_response
629+
return basic_execute_statement_response
630+
631+
632+
def test_GIVEN_test_execute_statement_response_WHEN_client_to_resource_THEN_returns_dict_value(test_execute_statement_response, test_ddb_item, test_dict_item):
620633
# Given: Execute statement response
621-
# TODO: this
622-
ddb_response = {}
634+
ddb_response = test_execute_statement_response([test_ddb_item])
623635
# When: Converting to resource format
624636
resource_response = client_to_resource_converter.execute_statement_response(ddb_response)
625637
# Then: Returns dict value
626-
assert resource_response == {}
638+
assert resource_response == test_execute_statement_response([test_dict_item])
627639

628640

629641
@pytest.fixture
@@ -641,19 +653,22 @@ def test_GIVEN_test_execute_transaction_request_WHEN_client_to_resource_THEN_ret
641653
# Then: Returns dict value (here, request is not modified)
642654
assert dict_item == test_execute_transaction_request(test_dict_item)
643655

656+
@pytest.fixture
657+
def test_execute_transaction_response():
658+
return basic_execute_transaction_response
659+
644660

645-
def test_GIVEN_test_execute_transaction_response_WHEN_client_to_resource_THEN_returns_dict_value():
661+
def test_GIVEN_test_execute_transaction_response_WHEN_client_to_resource_THEN_returns_dict_value(test_execute_transaction_response, test_ddb_item, test_dict_item):
646662
# Given: Execute transaction response
647-
# TODO: this
648-
ddb_response = {}
663+
ddb_response = test_execute_transaction_response([test_ddb_item])
649664
# When: Converting to resource format
650665
resource_response = client_to_resource_converter.execute_transaction_response(ddb_response)
651666
# Then: Returns dict value
652-
assert resource_response == {}
667+
assert resource_response == test_execute_transaction_response([test_dict_item])
653668

654669

655670
@pytest.fixture
656-
def test_batch_execute_statement_request():
671+
def test_batch_execute_statement_request(use_exhaustive_request):
657672
return basic_batch_execute_statement_request_encrypted_table
658673

659674

@@ -668,14 +683,20 @@ def test_GIVEN_test_batch_execute_statement_request_WHEN_client_to_resource_THEN
668683
assert dict_item == test_batch_execute_statement_request()
669684

670685

671-
def test_GIVEN_test_batch_execute_statement_response_WHEN_client_to_resource_THEN_raises_NotImplementedError():
686+
@pytest.fixture
687+
def test_batch_execute_statement_response(use_exhaustive_request):
688+
if use_exhaustive_request:
689+
return exhaustive_batch_execute_statement_response
690+
return basic_batch_execute_statement_response
691+
692+
693+
def test_GIVEN_test_batch_execute_statement_response_WHEN_client_to_resource_THEN_returns_dict_value(test_batch_execute_statement_response, test_ddb_item, test_dict_item):
672694
# Given: Batch execute statement response
673-
# TODO: this
674-
ddb_response = {}
695+
ddb_response = test_batch_execute_statement_response([test_ddb_item])
675696
# When: Converting to resource format
676697
resource_response = client_to_resource_converter.batch_execute_statement_response(ddb_response)
677698
# Then: Returns dict value
678-
assert resource_response == {}
699+
assert resource_response == test_batch_execute_statement_response([test_dict_item])
679700

680701

681702
@pytest.fixture
@@ -700,7 +721,9 @@ def test_GIVEN_test_delete_item_request_WHEN_client_to_resource_THEN_returns_dic
700721

701722

702723
@pytest.fixture
703-
def test_delete_item_response():
724+
def test_delete_item_response(use_exhaustive_request):
725+
if use_exhaustive_request:
726+
return exhaustive_delete_item_response
704727
return basic_delete_item_response
705728

706729

0 commit comments

Comments
 (0)