|
| 1 | +import uuid |
| 2 | +from copy import deepcopy |
| 3 | + |
1 | 4 | import boto3
|
2 | 5 | import pytest
|
3 | 6 |
|
4 | 7 | from aws_dbesdk_dynamodb.encrypted.resource import EncryptedResource, EncryptedTablesCollectionManager
|
5 | 8 | from aws_dbesdk_dynamodb.encrypted.table import EncryptedTable
|
6 | 9 |
|
7 | 10 | 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 | +) |
9 | 19 | from ...requests import (
|
10 | 20 | basic_batch_get_item_request_dict,
|
11 | 21 | basic_batch_write_item_delete_request_dict,
|
12 | 22 | basic_batch_write_item_put_request_dict,
|
| 23 | + basic_delete_item_request_ddb, |
13 | 24 | )
|
14 | 25 |
|
15 | 26 |
|
@@ -42,22 +53,45 @@ def tables(resource):
|
42 | 53 | return resource.tables
|
43 | 54 |
|
44 | 55 |
|
| 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 | + |
45 | 77 | def test_GIVEN_items_WHEN_batch_write_and_get_THEN_round_trip_passes(
|
46 | 78 | resource,
|
| 79 | + test_items, |
| 80 | + test_keys, |
47 | 81 | ):
|
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) |
49 | 83 | batch_write_response = resource.batch_write_item(**batch_write_item_put_request)
|
50 | 84 | assert batch_write_response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
51 | 85 |
|
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) |
53 | 87 | batch_get_response = resource.batch_get_item(**batch_get_item_request)
|
54 | 88 | assert batch_get_response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
55 | 89 | responses = batch_get_response["Responses"][INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME]
|
56 | 90 | assert len(responses) == 2
|
57 | 91 | for response in responses:
|
58 |
| - assert response in [simple_item_dict, complex_item_dict] |
| 92 | + assert response in test_items |
59 | 93 |
|
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) |
61 | 95 | batch_write_response = resource.batch_write_item(**batch_write_item_delete_request)
|
62 | 96 | assert batch_write_response["ResponseMetadata"]["HTTPStatusCode"] == 200
|
63 | 97 |
|
@@ -152,3 +186,14 @@ def test_GIVEN_tables_WHEN_page_size_THEN_returns_tables(
|
152 | 186 | tables_list.append(table)
|
153 | 187 | # Then: Returns tables
|
154 | 188 | 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