Skip to content

Commit 025cf87

Browse files
author
Lucas McDonald
committed
m
1 parent 12d7dad commit 025cf87

File tree

6 files changed

+97
-23
lines changed

6 files changed

+97
-23
lines changed

DynamoDbEncryption/runtimes/python/test/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
INTEG_TEST_DEFAULT_ALGORITHM_SUITE_ID = (
4040
DBEAlgorithmSuiteId.ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384_SYMSIG_HMAC_SHA384
4141
)
42-
# 4. Create the DynamoDb Encryption configuration for the table we will be writing to.
4342
INTEG_TEST_DEFAULT_TABLE_CONFIG = DynamoDbTableEncryptionConfig(
4443
logical_table_name=INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME,
4544
partition_key_name=INTEG_TEST_DEFAULT_PARTITION_KEY_NAME,

DynamoDbEncryption/runtimes/python/test/requests.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ def base_transact_get_item_request(keys):
5757

5858
# Base exhaustive request structures that are shared between DDB and dict formats
5959

60+
# No exhaustive requests are intended to be able to be used as real requests.
61+
# Some parameters conflict with each other when sent to DynamoDB.
62+
# These are only intended to test the conversion of the request from client to resource format.
6063

6164
def base_exhaustive_put_item_request(item):
62-
"""Base structure for exhaustive put_item requests."""
65+
"""Base structure for exhaustive put_item requests.
66+
This is not intended to be able to be used as a real request.
67+
Some parameters conflict with each other when sent to DynamoDB.
68+
This is only intended to test the conversion of the request from client to resource format.
69+
"""
6370
return {
6471
# Expected is legacy, but still in the boto3 docs.
6572
"Expected": {
@@ -78,7 +85,11 @@ def base_exhaustive_put_item_request(item):
7885

7986

8087
def base_exhaustive_get_item_request(item):
81-
"""Base structure for exhaustive get_item requests."""
88+
"""Base structure for exhaustive get_item requests.
89+
This is not intended to be able to be used as a real request.
90+
Some parameters conflict with each other when sent to DynamoDB.
91+
This is only intended to test the conversion of the request from client to resource format.
92+
"""
8293
return {
8394
"ReturnConsumedCapacity": "TOTAL",
8495
"ReturnItemCollectionMetrics": "SIZE",
@@ -95,7 +106,11 @@ def base_exhaustive_get_item_request(item):
95106

96107

97108
def base_exhaustive_query_request(item):
98-
"""Base structure for exhaustive query requests."""
109+
"""Base structure for exhaustive query requests.
110+
This is not intended to be able to be used as a real request.
111+
Some parameters conflict with each other when sent to DynamoDB.
112+
This is only intended to test the conversion of the request from client to resource format.
113+
"""
99114
return {
100115
"IndexName": "index_name",
101116
"Select": "SPECIFIC_ATTRIBUTES",
@@ -119,7 +134,11 @@ def base_exhaustive_query_request(item):
119134

120135

121136
def base_exhaustive_scan_request(item):
122-
"""Base structure for exhaustive scan requests."""
137+
"""Base structure for exhaustive scan requests.
138+
This is not intended to be able to be used as a real request.
139+
Some parameters conflict with each other when sent to DynamoDB.
140+
This is only intended to test the conversion of the request from client to resource format.
141+
"""
123142
return {
124143
"IndexName": "index_name",
125144
"AttributesToGet": ["partition_key", "sort_key", "attribute1", "attribute2"],
@@ -267,8 +286,14 @@ def basic_put_item_request_dict(item):
267286

268287

269288
def exhaustive_put_item_request_dict(item):
270-
"""Get a put_item request in dict format for any item."""
289+
"""Get a put_item request in dict format for any item.
290+
This is not intended to be able to be used as a real request.
291+
Some parameters conflict with each other when sent to DynamoDB.
292+
This is only intended to test the conversion of the request from client to resource format.
293+
"""
271294
base = basic_put_item_request_dict(item)
295+
# Replace the default ConditionExpression string with a ConditionExpression object
296+
# to increase test coverage.
272297
additional_keys = base_exhaustive_put_item_request(item)
273298
additional_keys["ConditionExpression"] = Attr("#pk").not_exists() & Attr("#sk").not_exists()
274299
return {**base, **additional_keys}
@@ -280,7 +305,11 @@ def basic_get_item_request_dict(item):
280305

281306

282307
def exhaustive_get_item_request_dict(item):
283-
"""Get a get_item request in dict format for any item."""
308+
"""Get a get_item request in dict format for any item.
309+
This is not intended to be able to be used as a real request.
310+
Some parameters conflict with each other when sent to DynamoDB.
311+
This is only intended to test the conversion of the request from client to resource format.
312+
"""
284313
base = basic_get_item_request_dict(item)
285314
additional_keys = base_exhaustive_get_item_request(item)
286315
return {**base, **additional_keys}
@@ -296,12 +325,17 @@ def basic_query_request_dict(item):
296325
def basic_query_request_dict_condition_expression(item):
297326
"""Get a query request in dict format for any item."""
298327
base = base_query_request(item)
299-
# Override base KeyConditionExpression to use ConditionExpressions
328+
# Replace the default KeyConditionExpression string with a ConditionExpression object
329+
# to increase test coverage.
300330
return {"KeyConditionExpression": Key("partition_key").eq(item["partition_key"]), **base}
301331

302332

303333
def exhaustive_query_request_dict(item):
304-
"""Get a query request in dict format for any item."""
334+
"""Get a query request in dict format for any item.
335+
This is not intended to be able to be used as a real request.
336+
Some parameters conflict with each other when sent to DynamoDB.
337+
This is only intended to test the conversion of the request from client to resource format.
338+
"""
305339
base = basic_query_request_dict(item)
306340
additional_keys = base_exhaustive_query_request(item)
307341
return {**base, **additional_keys}
@@ -313,7 +347,11 @@ def basic_scan_request_dict(item):
313347

314348

315349
def exhaustive_scan_request_dict(item):
316-
"""Get a scan request in dict format for any item."""
350+
"""Get a scan request in dict format for any item.
351+
This is not intended to be able to be used as a real request.
352+
Some parameters conflict with each other when sent to DynamoDB.
353+
This is only intended to test the conversion of the request from client to resource format.
354+
"""
317355
base = basic_scan_request_dict(item)
318356
additional_keys = base_exhaustive_scan_request(item)
319357
return {**base, **additional_keys}

DynamoDbEncryption/runtimes/python/test/responses.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ def basic_put_item_response(item):
77

88

99
def exhaustive_put_item_response(item):
10-
"""Get a put_item response in resource (ddb) format for any item."""
10+
"""Get a put_item response in resource (ddb) format for any item.
11+
This is not intended to be a real response that DynamoDB would return,
12+
but the response should contain additional attributes that DynamoDB could return.
13+
This is only intended to exhaustively test the conversion of the request from client to resource format.
14+
"""
1115
base = basic_put_item_response(item)
1216
additional_keys = {
1317
"ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME},
@@ -27,7 +31,11 @@ def basic_get_item_response(item):
2731

2832

2933
def exhaustive_get_item_response(item):
30-
"""Get a get_item response in resource (ddb) format for any item."""
34+
"""Get a get_item response in resource (ddb) format for any item.
35+
This is not intended to be a real response that DynamoDB would return,
36+
but the response should contain additional attributes that DynamoDB could return.
37+
This is only intended to exhaustively test the conversion of the request from client to resource format.
38+
"""
3139
base = basic_get_item_response(item)
3240
additional_keys = {
3341
"ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME},
@@ -46,7 +54,11 @@ def basic_query_response(items):
4654

4755

4856
def exhaustive_query_response(items):
49-
"""Get a query response in resource (ddb) format for any items."""
57+
"""Get a query response in resource (ddb) format for any items.
58+
This is not intended to be a real response that DynamoDB would return,
59+
but the response should contain additional attributes that DynamoDB could return.
60+
This is only intended to exhaustively test the conversion of the request from client to resource format.
61+
"""
5062
base = basic_query_response(items)
5163
additional_keys = {
5264
"LastEvaluatedKey": {"partition_key": items[-1]["partition_key"]},
@@ -62,7 +74,11 @@ def basic_scan_response(items, keys):
6274

6375

6476
def exhaustive_scan_response(items, keys):
65-
"""Get a scan response in resource (ddb) format for any items."""
77+
"""Get a scan response in resource (ddb) format for any items.
78+
This is not intended to be a real response that DynamoDB would return,
79+
but the response should contain additional attributes that DynamoDB could return.
80+
This is only intended to exhaustively test the conversion of the request from client to resource format.
81+
"""
6682
base = basic_scan_response(items, keys)
6783
additional_keys = {
6884
"ConsumedCapacity": {"CapacityUnits": 1, "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME},
@@ -79,7 +95,11 @@ def basic_batch_get_item_response(items):
7995

8096

8197
def exhaustive_batch_get_item_response(items):
82-
"""Get a batch_get_item response in resource (ddb) format for any items."""
98+
"""Get a batch_get_item response in resource (ddb) format for any items.
99+
This is not intended to be a real response that DynamoDB would return,
100+
but the response should contain additional attributes that DynamoDB could return.
101+
This is only intended to exhaustively test the conversion of the request from client to resource format.
102+
"""
83103
base = basic_batch_get_item_response(items)
84104
additional_keys = {
85105
"UnprocessedKeys": {
@@ -99,7 +119,11 @@ def basic_batch_write_item_put_response(items):
99119

100120

101121
def exhaustive_batch_write_item_put_response(items):
102-
"""Get a batch_write_item response in resource (ddb) format for any items."""
122+
"""Get a batch_write_item response in resource (ddb) format for any items.
123+
This is not intended to be a real response that DynamoDB would return,
124+
but the response should contain additional attributes that DynamoDB could return.
125+
This is only intended to exhaustively test the conversion of the request from client to resource format.
126+
"""
103127
base = basic_batch_write_item_put_response(items)
104128
additional_keys = {
105129
"ItemCollectionMetrics": {

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateInterceptedDDBTable.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@ def get_item(self, **kwargs):
130130

131131
def batch_write_item(self, **kwargs):
132132
table_input = self._client_shape_to_resource_shape_converter.batch_write_item_request(kwargs)
133-
table_output = self._table.batch_write_item(**table_input)
133+
# table_output = self._table.batch_write_item(**table_input)
134+
batch_writer = self._table.batch_writer()
135+
for item in table_input["Items"]:
136+
if "PutRequest" in item:
137+
batch_writer.put_item(item["PutRequest"]["Item"])
138+
elif "DeleteRequest" in item:
139+
batch_writer.delete_item(item["DeleteRequest"]["Key"])
140+
table_output = batch_writer.close()
134141
client_output = self._resource_shape_to_client_shape_converter.batch_write_item_response(table_output)
135142
return client_output
136143

TestVectors/runtimes/python/test/resource/test_dafny_wrapper.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import sys
12+
from functools import partial
1213

1314
# Different from standard test_dafny_wrapper due to weird test structure.
1415
test_dir = '/'.join(__file__.split("/")[:-2])
@@ -48,11 +49,13 @@
4849
def EmptyTest(*args, **kwargs):
4950
print(f"Skipping test {kwargs['test_name']} because {kwargs['reason']}")
5051

51-
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactWriteItems = EmptyTest(
52+
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactWriteItems = partial(
53+
EmptyTest,
5254
test_name="BasicIoTestTransactWriteItems",
5355
reason="neither DDB resources nor DDB tables support transact_write_items"
5456
)
55-
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactGetItems = EmptyTest(
57+
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactGetItems = partial(
58+
EmptyTest,
5659
test_name="BasicIoTestTransactGetItems",
5760
reason="neither DDB resources nor DDB tables support transact_get_items"
5861
)

TestVectors/runtimes/python/test/table/test_dafny_wrapper.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
import sys
12-
12+
from functools import partial
1313
# Different from standard test_dafny_wrapper due to weird test structure.
1414
test_dir = '/'.join(__file__.split("/")[:-2])
1515

@@ -39,15 +39,18 @@
3939
def EmptyTest(*args, **kwargs):
4040
print(f"Skipping test {kwargs['test_name']} because {kwargs['reason']}")
4141

42-
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactGetItems = EmptyTest(
42+
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactGetItems = partial(
43+
EmptyTest,
4344
test_name="BasicIoTestTransactGetItems",
4445
reason="DDB tables do not support transact_get_items"
4546
)
46-
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactWriteItems = EmptyTest(
47+
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestTransactWriteItems = partial(
48+
EmptyTest,
4749
test_name="BasicIoTestTransactWriteItems",
4850
reason="DDB tables do not support transact_write_items"
4951
)
50-
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestBatchGetItems = EmptyTest(
52+
aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.DdbEncryptionTestVectors.TestVectorConfig.BasicIoTestBatchGetItems = partial(
53+
EmptyTest,
5154
test_name="BasicIoTestBatchGetItems",
5255
reason="DDB tables do not support batch_get_item"
5356
)

0 commit comments

Comments
 (0)