|
13 | 13 | INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME,
|
14 | 14 | INTEG_TEST_DEFAULT_TABLE_CONFIGS,
|
15 | 15 | )
|
16 |
| -from ...items import complex_item_dict, simple_item_dict |
| 16 | +from ...items import complex_item_dict, simple_item_dict, simple_key_dict, complex_key_dict |
17 | 17 | from ...requests import (
|
18 | 18 | basic_delete_item_request_dict,
|
19 | 19 | basic_get_item_request_dict,
|
@@ -63,7 +63,7 @@ def table(encrypted):
|
63 | 63 |
|
64 | 64 | @pytest.fixture(scope="module")
|
65 | 65 | def test_run_suffix():
|
66 |
| - return str(uuid.uuid4()) |
| 66 | + return "-" + str(uuid.uuid4()) |
67 | 67 |
|
68 | 68 |
|
69 | 69 | # Creates a matrix of tests for each value in param,
|
@@ -109,51 +109,57 @@ def test_GIVEN_item_WHEN_basic_put_AND_basic_get_AND_basic_delete_THEN_round_tri
|
109 | 109 | assert "Item" not in get_response
|
110 | 110 |
|
111 | 111 |
|
| 112 | +@pytest.fixture |
| 113 | +def multiple_test_items(test_run_suffix): |
| 114 | + """Get two test items in the appropriate format for the client.""" |
| 115 | + items = [deepcopy(simple_item_dict), deepcopy(complex_item_dict)] |
| 116 | + for item in items: |
| 117 | + item["partition_key"] += test_run_suffix |
| 118 | + return items |
| 119 | + |
| 120 | + |
| 121 | +@pytest.fixture |
| 122 | +def multiple_test_keys(test_run_suffix): |
| 123 | + """Get two test keys in the appropriate format for the client.""" |
| 124 | + keys = [deepcopy(simple_key_dict), deepcopy(complex_key_dict)] |
| 125 | + for key in keys: |
| 126 | + key["partition_key"] += test_run_suffix |
| 127 | + return keys |
| 128 | + |
| 129 | + |
112 | 130 | def test_GIVEN_items_WHEN_batch_write_and_get_THEN_round_trip_passes(
|
113 | 131 | table,
|
| 132 | + multiple_test_items, |
| 133 | + multiple_test_keys, |
114 | 134 | ):
|
115 | 135 | # Given: Simple and complex items in appropriate format for client
|
116 | 136 | # When: Batch put items
|
117 | 137 | with table.batch_writer() as batch_writer:
|
118 | 138 | # boto3 documentation for batch_writer.put_item() is incorrect;
|
119 | 139 | # the method accepts the item directly, not the item inside an "Item" key.
|
120 |
| - batch_writer.put_item(simple_item_dict) |
121 |
| - batch_writer.put_item(complex_item_dict) |
| 140 | + for item in multiple_test_items: |
| 141 | + batch_writer.put_item(item) |
122 | 142 |
|
123 | 143 | # When: Get items
|
124 |
| - get_item_request_dict = basic_get_item_request_dict(simple_item_dict) |
125 |
| - get_response = table.get_item(**get_item_request_dict) |
126 |
| - # Then: All items are encrypted and decrypted correctly |
127 |
| - assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
128 |
| - assert get_response["Item"] == simple_item_dict |
129 |
| - |
130 |
| - get_item_request_dict = basic_get_item_request_dict(complex_item_dict) |
131 |
| - get_response = table.get_item(**get_item_request_dict) |
132 |
| - # Then: All items are encrypted and decrypted correctly |
133 |
| - assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
134 |
| - assert get_response["Item"] == complex_item_dict |
| 144 | + for item in multiple_test_items: |
| 145 | + get_item_request_dict = basic_get_item_request_dict(item) |
| 146 | + get_response = table.get_item(**get_item_request_dict) |
| 147 | + # Then: All items are encrypted and decrypted correctly |
| 148 | + assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
| 149 | + assert get_response["Item"] == item |
135 | 150 |
|
136 | 151 | # When: Batch delete items
|
137 | 152 | with table.batch_writer() as batch_writer:
|
138 |
| - batch_writer.delete_item( |
139 |
| - {"partition_key": simple_item_dict["partition_key"], "sort_key": simple_item_dict["sort_key"]} |
140 |
| - ) |
141 |
| - batch_writer.delete_item( |
142 |
| - {"partition_key": complex_item_dict["partition_key"], "sort_key": complex_item_dict["sort_key"]} |
143 |
| - ) |
| 153 | + for key in multiple_test_keys: |
| 154 | + batch_writer.delete_item(key) |
144 | 155 |
|
145 | 156 | # When: Get items
|
146 |
| - get_item_request_dict = basic_get_item_request_dict(simple_item_dict) |
147 |
| - get_response = table.get_item(**get_item_request_dict) |
148 |
| - # Then: All items are encrypted and decrypted correctly |
149 |
| - assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
150 |
| - assert "Item" not in get_response |
151 |
| - |
152 |
| - get_item_request_dict = basic_get_item_request_dict(complex_item_dict) |
153 |
| - get_response = table.get_item(**get_item_request_dict) |
154 |
| - # Then: All items are encrypted and decrypted correctly |
155 |
| - assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
156 |
| - assert "Item" not in get_response |
| 157 | + for item in multiple_test_items: |
| 158 | + get_item_request_dict = basic_get_item_request_dict(item) |
| 159 | + get_response = table.get_item(**get_item_request_dict) |
| 160 | + # Then: All items are encrypted and decrypted correctly |
| 161 | + assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
| 162 | + assert "Item" not in get_response |
157 | 163 |
|
158 | 164 |
|
159 | 165 | def test_GIVEN_items_in_table_WHEN_query_THEN_items_are_decrypted_correctly(table, test_item):
|
|
0 commit comments