Skip to content

Commit 68114f3

Browse files
author
Lucas McDonald
committed
sync
1 parent d68e095 commit 68114f3

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

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

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

47
from aws_dbesdk_dynamodb.encrypted.resource import EncryptedResource, EncryptedTablesCollectionManager
58
from aws_dbesdk_dynamodb.encrypted.table import EncryptedTable
69

710
from ...constants import INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME, INTEG_TEST_DEFAULT_TABLE_CONFIGS
8-
from ...items import complex_item_dict, complex_key_dict, simple_item_dict, simple_key_dict
11+
from ...items import (
12+
complex_item_ddb,
13+
complex_item_dict,
14+
complex_key_dict,
15+
simple_item_ddb,
16+
simple_item_dict,
17+
simple_key_dict,
18+
)
919
from ...requests import (
1020
basic_batch_get_item_request_dict,
1121
basic_batch_write_item_delete_request_dict,
1222
basic_batch_write_item_put_request_dict,
23+
basic_delete_item_request_ddb,
1324
)
1425

1526

@@ -42,22 +53,45 @@ def tables(resource):
4253
return resource.tables
4354

4455

56+
@pytest.fixture(scope="module")
57+
def test_run_suffix():
58+
return str(uuid.uuid4())
59+
60+
61+
@pytest.fixture
62+
def test_items(test_run_suffix):
63+
items = [deepcopy(complex_item_dict), deepcopy(simple_item_dict)]
64+
for item in items:
65+
item["partition_key"] += test_run_suffix
66+
return items
67+
68+
69+
@pytest.fixture
70+
def test_keys(test_run_suffix):
71+
keys = [deepcopy(complex_key_dict), deepcopy(simple_key_dict)]
72+
for key in keys:
73+
key["partition_key"] += test_run_suffix
74+
return keys
75+
76+
4577
def test_GIVEN_items_WHEN_batch_write_and_get_THEN_round_trip_passes(
4678
resource,
79+
test_items,
80+
test_keys,
4781
):
48-
batch_write_item_put_request = basic_batch_write_item_put_request_dict([simple_item_dict, complex_item_dict])
82+
batch_write_item_put_request = basic_batch_write_item_put_request_dict(test_items)
4983
batch_write_response = resource.batch_write_item(**batch_write_item_put_request)
5084
assert batch_write_response["ResponseMetadata"]["HTTPStatusCode"] == 200
5185

52-
batch_get_item_request = basic_batch_get_item_request_dict([simple_key_dict, complex_key_dict])
86+
batch_get_item_request = basic_batch_get_item_request_dict(test_keys)
5387
batch_get_response = resource.batch_get_item(**batch_get_item_request)
5488
assert batch_get_response["ResponseMetadata"]["HTTPStatusCode"] == 200
5589
responses = batch_get_response["Responses"][INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME]
5690
assert len(responses) == 2
5791
for response in responses:
58-
assert response in [simple_item_dict, complex_item_dict]
92+
assert response in test_items
5993

60-
batch_write_item_delete_request = basic_batch_write_item_delete_request_dict([simple_key_dict, complex_key_dict])
94+
batch_write_item_delete_request = basic_batch_write_item_delete_request_dict(test_keys)
6195
batch_write_response = resource.batch_write_item(**batch_write_item_delete_request)
6296
assert batch_write_response["ResponseMetadata"]["HTTPStatusCode"] == 200
6397

@@ -152,3 +186,14 @@ def test_GIVEN_tables_WHEN_page_size_THEN_returns_tables(
152186
tables_list.append(table)
153187
# Then: Returns tables
154188
assert len(tables_list) > 0
189+
190+
191+
# Delete the items in the table after the module runs
192+
@pytest.fixture(scope="module", autouse=True)
193+
def cleanup_after_module(test_run_suffix):
194+
yield
195+
table = boto3.client("dynamodb")
196+
items = [deepcopy(simple_item_ddb), deepcopy(complex_item_ddb)]
197+
for item in items:
198+
item["partition_key"]["S"] += test_run_suffix
199+
table.delete_item(**basic_delete_item_request_ddb(item))

0 commit comments

Comments
 (0)