Skip to content

Commit 2a13acd

Browse files
author
Lucas McDonald
committed
m
1 parent 381b4f5 commit 2a13acd

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
import uuid
4+
from copy import deepcopy
5+
36
import boto3
47
import pytest
58

@@ -8,8 +11,6 @@
811
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
912
DynamoDbEncryptionTransformsException,
1013
)
11-
import uuid
12-
from copy import deepcopy
1314

1415
from ...constants import (
1516
INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME,
@@ -112,11 +113,13 @@ def client(encrypted, expect_standard_dictionaries):
112113
def use_complex_item(request):
113114
return request.param
114115

116+
115117
# Append a suffix to the partition key to avoid collisions between test runs.
116118
@pytest.fixture(scope="module")
117119
def test_run_suffix():
118120
return str(uuid.uuid4())
119121

122+
120123
@pytest.fixture
121124
def test_item(expect_standard_dictionaries, use_complex_item, test_run_suffix):
122125
"""Get a single test item in the appropriate format for the client."""
@@ -137,6 +140,7 @@ def test_item(expect_standard_dictionaries, use_complex_item, test_run_suffix):
137140
item["partition_key"] += test_run_suffix
138141
return item
139142

143+
140144
@pytest.fixture
141145
def test_key(expect_standard_dictionaries, use_complex_item, test_run_suffix):
142146
"""Get a single test item in the appropriate format for the client."""
@@ -635,6 +639,7 @@ def test_WHEN_call_passthrough_method_THEN_correct_response_is_returned():
635639
# Then: Correct response is returned, i.e. EncryptedClient forwards the call to the underlying boto3 client
636640
assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
637641

642+
638643
# Delete the items in the table after the module runs
639644
@pytest.fixture(scope="module", autouse=True)
640645
def cleanup_after_module(test_run_suffix):

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import boto3
2-
import pytest
31
import uuid
42
from copy import deepcopy
53

4+
import boto3
5+
import pytest
6+
67
from aws_dbesdk_dynamodb.encrypted.client import EncryptedClient
78

89
from ...constants import (
@@ -20,6 +21,7 @@
2021
simple_key_dict,
2122
)
2223
from ...requests import (
24+
basic_delete_item_request_ddb,
2325
basic_put_item_request_ddb,
2426
basic_put_item_request_dict,
2527
basic_query_paginator_request,
@@ -88,11 +90,13 @@ def scan_paginator(client):
8890
def use_complex_item(request):
8991
return request.param
9092

93+
9194
# Append a suffix to the partition key to avoid collisions between test runs.
9295
@pytest.fixture(scope="module")
9396
def test_run_suffix():
9497
return str(uuid.uuid4())
9598

99+
96100
@pytest.fixture
97101
def test_key(expect_standard_dictionaries, use_complex_item, test_run_suffix):
98102
"""Get a single test item in the appropriate format for the client."""
@@ -113,6 +117,7 @@ def test_key(expect_standard_dictionaries, use_complex_item, test_run_suffix):
113117
key["partition_key"] += test_run_suffix
114118
return key
115119

120+
116121
@pytest.fixture
117122
def multiple_test_keys(expect_standard_dictionaries, test_run_suffix):
118123
"""Get two test keys in the appropriate format for the client."""
@@ -128,6 +133,7 @@ def multiple_test_keys(expect_standard_dictionaries, test_run_suffix):
128133
key["partition_key"] += test_run_suffix
129134
return keys
130135

136+
131137
@pytest.fixture
132138
def test_item(expect_standard_dictionaries, use_complex_item, test_run_suffix):
133139
"""Get a single test item in the appropriate format for the client."""
@@ -218,3 +224,14 @@ def test_GIVEN_scan_paginator_WHEN_paginate_THEN_returns_expected_items(
218224
actual_item = sort_dynamodb_json_lists(items[0])
219225
# Then: Items are equal
220226
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))

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
import boto3
2-
import pytest
31
import uuid
42
from copy import deepcopy
53

4+
import boto3
5+
import pytest
6+
67
from aws_dbesdk_dynamodb.encrypted.resource import EncryptedResource, EncryptedTablesCollectionManager
78
from aws_dbesdk_dynamodb.encrypted.table import EncryptedTable
89

910
from ...constants import INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME, INTEG_TEST_DEFAULT_TABLE_CONFIGS
10-
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+
)
1119
from ...requests import (
1220
basic_batch_get_item_request_dict,
1321
basic_batch_write_item_delete_request_dict,
1422
basic_batch_write_item_put_request_dict,
23+
basic_delete_item_request_ddb,
1524
)
1625

1726

@@ -43,17 +52,20 @@ def resource(encrypted):
4352
def tables(resource):
4453
return resource.tables
4554

55+
4656
@pytest.fixture(scope="module")
4757
def test_run_suffix():
4858
return str(uuid.uuid4())
4959

60+
5061
@pytest.fixture
5162
def test_items(test_run_suffix):
5263
items = [deepcopy(complex_item_dict), deepcopy(simple_item_dict)]
5364
for item in items:
5465
item["partition_key"] += test_run_suffix
5566
return items
5667

68+
5769
@pytest.fixture
5870
def test_keys(test_run_suffix):
5971
keys = [deepcopy(complex_key_dict), deepcopy(simple_key_dict)]
@@ -174,3 +186,14 @@ def test_GIVEN_tables_WHEN_page_size_THEN_returns_tables(
174186
tables_list.append(table)
175187
# Then: Returns tables
176188
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))

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import boto3
2-
import pytest
31
import uuid
42
from copy import deepcopy
53

4+
import boto3
5+
import pytest
6+
67
from aws_dbesdk_dynamodb.encrypted.table import EncryptedTable
78
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_transforms.errors import (
89
DynamoDbEncryptionTransformsException,
@@ -59,10 +60,12 @@ def table(encrypted):
5960
else:
6061
return plaintext_table()
6162

63+
6264
@pytest.fixture(scope="module")
6365
def test_run_suffix():
6466
return str(uuid.uuid4())
6567

68+
6669
# Creates a matrix of tests for each value in param,
6770
# with a user-friendly string for test output:
6871
# use_complex_item = True -> "complex_item"
@@ -239,6 +242,7 @@ def test_WHEN_call_passthrough_method_THEN_correct_response_is_returned():
239242
# Then: Correct response is returned, i.e. EncryptedTable forwards the call to the underlying boto3 table
240243
assert response == INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME
241244

245+
242246
# Delete the items in the table after the module runs
243247
@pytest.fixture(scope="module", autouse=True)
244248
def cleanup_after_module(test_run_suffix):

0 commit comments

Comments
 (0)