Skip to content

Commit b704961

Browse files
author
Lucas McDonald
committed
sync
1 parent b183d0b commit b704961

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

DynamoDbEncryption/runtimes/python/test/requests.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
)
1111

1212
# Base request structures that are shared between DDB and dict formats
13+
# Use ConsistentRead: True for all requests;
14+
# many of these are used in integ tests, where consistent reads reduce test flakiness.
1315

1416

1517
def base_put_item_request(item):
@@ -19,7 +21,7 @@ def base_put_item_request(item):
1921

2022
def base_get_item_request(item):
2123
"""Base structure for get_item requests."""
22-
return {"Key": {"partition_key": item["partition_key"], "sort_key": item["sort_key"]}}
24+
return {"Key": {"partition_key": item["partition_key"], "sort_key": item["sort_key"]}, "ConsistentRead": True}
2325

2426

2527
def base_delete_item_request(item):
@@ -32,6 +34,7 @@ def base_query_request(item):
3234
return {
3335
"KeyConditionExpression": "partition_key = :pk",
3436
"ExpressionAttributeValues": {":pk": item["partition_key"]},
37+
"ConsistentRead": True,
3538
}
3639

3740

@@ -40,6 +43,7 @@ def base_scan_request(item):
4043
return {
4144
"FilterExpression": "attribute2 = :a2",
4245
"ExpressionAttributeValues": {":a2": item["attribute2"]},
46+
"ConsistentRead": True,
4347
}
4448

4549

@@ -50,7 +54,7 @@ def base_batch_write_item_request(actions_with_items):
5054

5155
def base_batch_get_item_request(keys):
5256
"""Base structure for batch_get_item requests."""
53-
return {"RequestItems": {INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: {"Keys": keys}}}
57+
return {"RequestItems": {INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME: {"Keys": keys, "ConsistentRead": True}}}
5458

5559

5660
def base_transact_write_item_request(actions_with_items):
@@ -142,15 +146,15 @@ def basic_batch_execute_statement_request_plaintext_table():
142146

143147
# No exhaustive requests are intended to be able to be used as real requests.
144148
# Some parameters conflict with each other when sent to DynamoDB.
145-
# These are only intended to test the conversion of the structure from client to resource format.
149+
# These are only intended to test the conversion of the structure between client and resource formats.
146150

147151

148152
def base_exhaustive_put_item_request(item):
149153
"""
150154
Base structure for exhaustive put_item requests.
151155
This is not intended to be able to be used as a real request.
152156
Some parameters conflict with each other when sent to DynamoDB.
153-
This is only intended to test the conversion of the request from client to resource format.
157+
This is only intended to test the conversion of the request between client and resource formats.
154158
"""
155159
return {
156160
# Expected is legacy, but still in the boto3 docs.
@@ -174,7 +178,7 @@ def base_exhaustive_get_item_request(item):
174178
Base structure for exhaustive get_item requests.
175179
This is not intended to be able to be used as a real request.
176180
Some parameters conflict with each other when sent to DynamoDB.
177-
This is only intended to test the conversion of the request from client to resource format.
181+
This is only intended to test the conversion of the request between client and resource formats.
178182
"""
179183
return {
180184
"ReturnConsumedCapacity": "TOTAL",
@@ -196,7 +200,7 @@ def base_exhaustive_delete_item_request(item):
196200
Base structure for exhaustive delete_item requests.
197201
This is not intended to be able to be used as a real request.
198202
Some parameters conflict with each other when sent to DynamoDB.
199-
This is only intended to test the conversion of the request from client to resource format.
203+
This is only intended to test the conversion of the request between client and resource formats.
200204
"""
201205
return {
202206
"ReturnConsumedCapacity": "TOTAL",
@@ -211,7 +215,7 @@ def base_exhaustive_query_request(item):
211215
Base structure for exhaustive query requests.
212216
This is not intended to be able to be used as a real request.
213217
Some parameters conflict with each other when sent to DynamoDB.
214-
This is only intended to test the conversion of the request from client to resource format.
218+
This is only intended to test the conversion of the request between client and resource formats.
215219
"""
216220
return {
217221
"IndexName": "index_name",
@@ -240,7 +244,7 @@ def base_exhaustive_scan_request(item):
240244
Base structure for exhaustive scan requests.
241245
This is not intended to be able to be used as a real request.
242246
Some parameters conflict with each other when sent to DynamoDB.
243-
This is only intended to test the conversion of the request from client to resource format.
247+
This is only intended to test the conversion of the request between client and resource formats.
244248
"""
245249
return {
246250
"IndexName": "index_name",
@@ -310,7 +314,7 @@ def exhaustive_query_request_ddb(item):
310314
Query request with all possible parameters.
311315
This is not intended to be able to be used as a real request.
312316
Some parameters conflict with each other when sent to DynamoDB.
313-
This is only intended to test the conversion of the request from client to resource format.
317+
This is only intended to test the conversion of the request between client and resource formats.
314318
"""
315319
base = basic_query_request_ddb(item)
316320
additional_keys = base_exhaustive_query_request(item)
@@ -390,6 +394,7 @@ def basic_query_paginator_request(key):
390394
"TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME,
391395
"KeyConditionExpression": "partition_key = :pk AND sort_key = :sk",
392396
"ExpressionAttributeValues": {":pk": key["partition_key"], ":sk": key["sort_key"]},
397+
"ConsistentRead": True,
393398
}
394399

395400

@@ -399,6 +404,7 @@ def basic_scan_paginator_request(item):
399404
"TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME,
400405
"FilterExpression": "partition_key = :pk AND sort_key = :sk",
401406
"ExpressionAttributeValues": {":pk": item["partition_key"], ":sk": item["sort_key"]},
407+
"ConsistentRead": True,
402408
}
403409

404410

@@ -427,7 +433,7 @@ def exhaustive_put_item_request_dict(item):
427433
Get a put_item request in dict format for any item.
428434
This is not intended to be able to be used as a real request.
429435
Some parameters conflict with each other when sent to DynamoDB.
430-
This is only intended to test the conversion of the request from client to resource format.
436+
This is only intended to test the conversion of the request between client and resource formats.
431437
"""
432438
base = basic_put_item_request_dict(item)
433439
# Replace the default ConditionExpression string with a ConditionExpression object
@@ -452,7 +458,7 @@ def exhaustive_get_item_request_dict(item):
452458
Get a get_item request in dict format for any item.
453459
This is not intended to be able to be used as a real request.
454460
Some parameters conflict with each other when sent to DynamoDB.
455-
This is only intended to test the conversion of the request from client to resource format.
461+
This is only intended to test the conversion of the request between client and resource formats.
456462
"""
457463
base = basic_get_item_request_dict(item)
458464
additional_keys = base_exhaustive_get_item_request(item)
@@ -478,7 +484,7 @@ def exhaustive_query_request_dict(item):
478484
Get a query request in dict format for any item.
479485
This is not intended to be able to be used as a real request.
480486
Some parameters conflict with each other when sent to DynamoDB.
481-
This is only intended to test the conversion of the request from client to resource format.
487+
This is only intended to test the conversion of the request between client and resource formats.
482488
"""
483489
base = basic_query_request_dict(item)
484490
additional_keys = base_exhaustive_query_request(item)
@@ -495,7 +501,7 @@ def exhaustive_scan_request_dict(item):
495501
Get a scan request in dict format for any item.
496502
This is not intended to be able to be used as a real request.
497503
Some parameters conflict with each other when sent to DynamoDB.
498-
This is only intended to test the conversion of the request from client to resource format.
504+
This is only intended to test the conversion of the request between client and resource formats.
499505
"""
500506
base = basic_scan_request_dict(item)
501507
additional_keys = base_exhaustive_scan_request(item)

DynamoDbEncryption/runtimes/python/test/responses.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def exhaustive_put_item_response(item):
1313
Get a put_item response in resource (ddb) format for any item.
1414
This is not intended to be a real response that DynamoDB would return,
1515
but the response should contain additional attributes that DynamoDB could return.
16-
This is only intended to exhaustively test the conversion of the request from client to resource format.
16+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
1717
"""
1818
base = basic_put_item_response(item)
1919
additional_keys = {
@@ -38,7 +38,7 @@ def exhaustive_get_item_response(item):
3838
Get a get_item response in resource (ddb) format for any item.
3939
This is not intended to be a real response that DynamoDB would return,
4040
but the response should contain additional attributes that DynamoDB could return.
41-
This is only intended to exhaustively test the conversion of the request from client to resource format.
41+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
4242
"""
4343
base = basic_get_item_response(item)
4444
additional_keys = {
@@ -62,7 +62,7 @@ def exhaustive_query_response(items):
6262
Get a query response in resource (ddb) format for any items.
6363
This is not intended to be a real response that DynamoDB would return,
6464
but the response should contain additional attributes that DynamoDB could return.
65-
This is only intended to exhaustively test the conversion of the request from client to resource format.
65+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
6666
"""
6767
base = basic_query_response(items)
6868
additional_keys = {
@@ -83,7 +83,7 @@ def exhaustive_scan_response(items, keys):
8383
Get a scan response in resource (ddb) format for any items.
8484
This is not intended to be a real response that DynamoDB would return,
8585
but the response should contain additional attributes that DynamoDB could return.
86-
This is only intended to exhaustively test the conversion of the request from client to resource format.
86+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
8787
"""
8888
base = basic_scan_response(items, keys)
8989
additional_keys = {
@@ -105,7 +105,7 @@ def exhaustive_batch_get_item_response(items):
105105
Get a batch_get_item response in resource (ddb) format for any items.
106106
This is not intended to be a real response that DynamoDB would return,
107107
but the response should contain additional attributes that DynamoDB could return.
108-
This is only intended to exhaustively test the conversion of the request from client to resource format.
108+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
109109
"""
110110
base = basic_batch_get_item_response(items)
111111
additional_keys = {
@@ -130,7 +130,7 @@ def exhaustive_batch_write_item_put_response(items):
130130
Get a batch_write_item response in resource (ddb) format for any items.
131131
This is not intended to be a real response that DynamoDB would return,
132132
but the response should contain additional attributes that DynamoDB could return.
133-
This is only intended to exhaustively test the conversion of the request from client to resource format.
133+
This is only intended to exhaustively test the conversion of the request between client and resource formats.
134134
"""
135135
base = basic_batch_write_item_put_response(items)
136136
additional_keys = {

DynamoDbEncryption/runtimes/python/test/unit/internal/test_client_to_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
import pytest
4+
from boto3.dynamodb.conditions import ConditionExpressionBuilder
45

56
from aws_dbesdk_dynamodb.internal.client_to_resource import ClientShapeToResourceShapeConverter
6-
from boto3.dynamodb.conditions import ConditionExpressionBuilder
77

88
from ...items import (
99
complex_item_ddb,

0 commit comments

Comments
 (0)