Skip to content

Commit 3552bae

Browse files
author
Lucas McDonald
committed
sync
1 parent c5ff19e commit 3552bae

File tree

1 file changed

+62
-15
lines changed

1 file changed

+62
-15
lines changed

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

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import uuid
2+
from copy import deepcopy
3+
14
import boto3
25
import pytest
36

@@ -18,6 +21,7 @@
1821
simple_key_dict,
1922
)
2023
from ...requests import (
24+
basic_delete_item_request_ddb,
2125
basic_put_item_request_ddb,
2226
basic_put_item_request_dict,
2327
basic_query_paginator_request,
@@ -87,36 +91,68 @@ def use_complex_item(request):
8791
return request.param
8892

8993

94+
# Append a suffix to the partition key to avoid collisions between test runs.
95+
@pytest.fixture(scope="module")
96+
def test_run_suffix():
97+
return str(uuid.uuid4())
98+
99+
90100
@pytest.fixture
91-
def test_key(expect_standard_dictionaries, use_complex_item):
101+
def test_key(expect_standard_dictionaries, use_complex_item, test_run_suffix):
92102
"""Get a single test item in the appropriate format for the client."""
93103
if expect_standard_dictionaries:
94104
if use_complex_item:
95-
return complex_key_dict
96-
return simple_key_dict
97-
if use_complex_item:
98-
return complex_key_ddb
99-
return simple_key_ddb
105+
key = deepcopy(complex_key_dict)
106+
else:
107+
key = deepcopy(simple_key_dict)
108+
else:
109+
if use_complex_item:
110+
key = deepcopy(complex_key_ddb)
111+
else:
112+
key = deepcopy(simple_key_ddb)
113+
# Add a suffix to the partition key to avoid collisions between test runs.
114+
if isinstance(key["partition_key"], dict):
115+
key["partition_key"]["S"] += test_run_suffix
116+
else:
117+
key["partition_key"] += test_run_suffix
118+
return key
100119

101120

102121
@pytest.fixture
103-
def multiple_test_keys(expect_standard_dictionaries):
122+
def multiple_test_keys(expect_standard_dictionaries, test_run_suffix):
104123
"""Get two test keys in the appropriate format for the client."""
105124
if expect_standard_dictionaries:
106-
return [simple_key_dict, complex_key_dict]
107-
return [simple_key_ddb, complex_key_ddb]
125+
keys = [deepcopy(simple_key_dict), deepcopy(complex_key_dict)]
126+
else:
127+
keys = [deepcopy(simple_key_ddb), deepcopy(complex_key_ddb)]
128+
# Add a suffix to the partition key to avoid collisions between test runs.
129+
for key in keys:
130+
if isinstance(key["partition_key"], dict):
131+
key["partition_key"]["S"] += test_run_suffix
132+
else:
133+
key["partition_key"] += test_run_suffix
134+
return keys
108135

109136

110137
@pytest.fixture
111-
def test_item(expect_standard_dictionaries, use_complex_item):
138+
def test_item(expect_standard_dictionaries, use_complex_item, test_run_suffix):
112139
"""Get a single test item in the appropriate format for the client."""
113140
if expect_standard_dictionaries:
114141
if use_complex_item:
115-
return complex_item_dict
116-
return simple_item_dict
117-
if use_complex_item:
118-
return complex_item_ddb
119-
return simple_item_ddb
142+
item = deepcopy(complex_item_dict)
143+
else:
144+
item = deepcopy(simple_item_dict)
145+
else:
146+
if use_complex_item:
147+
item = deepcopy(complex_item_ddb)
148+
else:
149+
item = deepcopy(simple_item_ddb)
150+
# Add a suffix to the partition key to avoid collisions between test runs.
151+
if isinstance(item["partition_key"], dict):
152+
item["partition_key"]["S"] += test_run_suffix
153+
else:
154+
item["partition_key"] += test_run_suffix
155+
return item
120156

121157

122158
@pytest.fixture
@@ -188,3 +224,14 @@ def test_GIVEN_scan_paginator_WHEN_paginate_THEN_returns_expected_items(
188224
actual_item = sort_dynamodb_json_lists(items[0])
189225
# Then: Items are equal
190226
assert expected_item == actual_item
227+
228+
229+
# Delete the items in the table after the module runs
230+
@pytest.fixture(scope="module", autouse=True)
231+
def cleanup_after_module(test_run_suffix):
232+
yield
233+
table = boto3.client("dynamodb")
234+
items = [deepcopy(simple_item_ddb), deepcopy(complex_item_ddb)]
235+
for item in items:
236+
item["partition_key"]["S"] += test_run_suffix
237+
table.delete_item(**basic_delete_item_request_ddb(item))

0 commit comments

Comments
 (0)