Skip to content

Commit 29ccb72

Browse files
author
Lucas McDonald
committed
m
1 parent 0442ea8 commit 29ccb72

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def use_complex_item(request):
117117
# Append a suffix to the partition key to avoid collisions between test runs.
118118
@pytest.fixture(scope="module")
119119
def test_run_suffix():
120-
return str(uuid.uuid4())
120+
return "-" + str(uuid.uuid4())
121121

122122

123123
@pytest.fixture

DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_paginator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def use_complex_item(request):
9494
# Append a suffix to the partition key to avoid collisions between test runs.
9595
@pytest.fixture(scope="module")
9696
def test_run_suffix():
97-
return str(uuid.uuid4())
97+
return "-" + str(uuid.uuid4())
9898

9999

100100
@pytest.fixture

DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def tables(resource):
5555

5656
@pytest.fixture(scope="module")
5757
def test_run_suffix():
58-
return str(uuid.uuid4())
58+
return "-" + str(uuid.uuid4())
5959

6060

6161
@pytest.fixture

DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_table.py

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME,
1414
INTEG_TEST_DEFAULT_TABLE_CONFIGS,
1515
)
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
1717
from ...requests import (
1818
basic_delete_item_request_dict,
1919
basic_get_item_request_dict,
@@ -63,7 +63,7 @@ def table(encrypted):
6363

6464
@pytest.fixture(scope="module")
6565
def test_run_suffix():
66-
return str(uuid.uuid4())
66+
return "-" + str(uuid.uuid4())
6767

6868

6969
# 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
109109
assert "Item" not in get_response
110110

111111

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+
112130
def test_GIVEN_items_WHEN_batch_write_and_get_THEN_round_trip_passes(
113131
table,
132+
multiple_test_items,
133+
multiple_test_keys,
114134
):
115135
# Given: Simple and complex items in appropriate format for client
116136
# When: Batch put items
117137
with table.batch_writer() as batch_writer:
118138
# boto3 documentation for batch_writer.put_item() is incorrect;
119139
# 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)
122142

123143
# 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
135150

136151
# When: Batch delete items
137152
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)
144155

145156
# 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
157163

158164

159165
def test_GIVEN_items_in_table_WHEN_query_THEN_items_are_decrypted_correctly(table, test_item):

0 commit comments

Comments
 (0)