23
23
import boto3
24
24
import pytest
25
25
from boto3 .dynamodb .types import Binary
26
+ from botocore .exceptions import NoRegionError
26
27
from moto import mock_dynamodb2
27
28
28
29
from dynamodb_encryption_sdk .delegated_keys .jce import JceNameLocalDelegatedKey
43
44
RUNNING_IN_TRAVIS = "TRAVIS" in os .environ
44
45
_DELEGATED_KEY_CACHE = defaultdict (lambda : defaultdict (dict ))
45
46
TEST_TABLE_NAME = "my_table"
47
+ TEST_REGION_NAME = "us-west-2"
46
48
TEST_INDEX = {
47
49
"partition_attribute" : {"type" : "S" , "value" : "test_value" },
48
50
"sort_attribute" : {"type" : "N" , "value" : Decimal ("99.233" )},
49
51
}
50
- SECONARY_INDEX = {
52
+ SECONDARY_INDEX = {
51
53
"secondary_index_1" : {"type" : "B" , "value" : Binary (b"\x00 \x01 \x02 " )},
52
54
"secondary_index_2" : {"type" : "S" , "value" : "another_value" },
53
55
}
76
78
@pytest .fixture
77
79
def example_table ():
78
80
mock_dynamodb2 ().start (reset = False )
79
- ddb = boto3 .client ("dynamodb" , region_name = "us-west-2" )
81
+ ddb = boto3 .client ("dynamodb" , region_name = TEST_REGION_NAME )
80
82
ddb .create_table (
81
83
TableName = TEST_TABLE_NAME ,
82
84
KeySchema = [
@@ -94,9 +96,9 @@ def example_table():
94
96
95
97
96
98
@pytest .fixture
97
- def table_with_local_seconary_indexes ():
99
+ def table_with_local_secondary_indexes ():
98
100
mock_dynamodb2 ().start (reset = False )
99
- ddb = boto3 .client ("dynamodb" , region_name = "us-west-2" )
101
+ ddb = boto3 .client ("dynamodb" , region_name = TEST_REGION_NAME )
100
102
ddb .create_table (
101
103
TableName = TEST_TABLE_NAME ,
102
104
KeySchema = [
@@ -117,7 +119,7 @@ def table_with_local_seconary_indexes():
117
119
],
118
120
AttributeDefinitions = [
119
121
{"AttributeName" : name , "AttributeType" : value ["type" ]}
120
- for name , value in list (TEST_INDEX .items ()) + list (SECONARY_INDEX .items ())
122
+ for name , value in list (TEST_INDEX .items ()) + list (SECONDARY_INDEX .items ())
121
123
],
122
124
ProvisionedThroughput = {"ReadCapacityUnits" : 100 , "WriteCapacityUnits" : 100 },
123
125
)
@@ -129,7 +131,7 @@ def table_with_local_seconary_indexes():
129
131
@pytest .fixture
130
132
def table_with_global_secondary_indexes ():
131
133
mock_dynamodb2 ().start (reset = False )
132
- ddb = boto3 .client ("dynamodb" , region_name = "us-west-2" )
134
+ ddb = boto3 .client ("dynamodb" , region_name = TEST_REGION_NAME )
133
135
ddb .create_table (
134
136
TableName = TEST_TABLE_NAME ,
135
137
KeySchema = [
@@ -152,7 +154,7 @@ def table_with_global_secondary_indexes():
152
154
],
153
155
AttributeDefinitions = [
154
156
{"AttributeName" : name , "AttributeType" : value ["type" ]}
155
- for name , value in list (TEST_INDEX .items ()) + list (SECONARY_INDEX .items ())
157
+ for name , value in list (TEST_INDEX .items ()) + list (SECONDARY_INDEX .items ())
156
158
],
157
159
ProvisionedThroughput = {"ReadCapacityUnits" : 100 , "WriteCapacityUnits" : 100 },
158
160
)
@@ -649,19 +651,19 @@ def client_cycle_batch_items_check_paginators(
649
651
650
652
651
653
def build_metastore ():
652
- client = boto3 .client ("dynamodb" , region_name = "us-west-2" )
654
+ client = boto3 .client ("dynamodb" , region_name = TEST_REGION_NAME )
653
655
table_name = base64 .urlsafe_b64encode (os .urandom (32 )).decode ("utf-8" ).replace ("=" , "." )
654
656
655
657
MetaStore .create_table (client , table_name , 1 , 1 )
656
658
waiter = client .get_waiter ("table_exists" )
657
659
waiter .wait (TableName = table_name )
658
660
659
- table = boto3 .resource ("dynamodb" , region_name = "us-west-2" ).Table (table_name )
661
+ table = boto3 .resource ("dynamodb" , region_name = TEST_REGION_NAME ).Table (table_name )
660
662
return MetaStore (table , build_static_jce_cmp ("AES" , 256 , "HmacSHA256" , 256 )), table_name
661
663
662
664
663
665
def delete_metastore (table_name ):
664
- client = boto3 .client ("dynamodb" , region_name = "us-west-2" )
666
+ client = boto3 .client ("dynamodb" , region_name = TEST_REGION_NAME )
665
667
client .delete_table (TableName = table_name )
666
668
# It sometimes takes a long time to delete a table.
667
669
# If hanging, asynchronously deleting tables becomes an issue,
@@ -698,7 +700,10 @@ def _count_gets(records, table_name):
698
700
699
701
700
702
def check_metastore_cache_use_encrypt (metastore , table_name , log_capture ):
701
- table = boto3 .resource ("dynamodb" ).Table (table_name )
703
+ try :
704
+ table = boto3 .resource ("dynamodb" ).Table (table_name )
705
+ except NoRegionError :
706
+ table = boto3 .resource ("dynamodb" , region_name = TEST_REGION_NAME ).Table (table_name )
702
707
703
708
most_recent_provider = MostRecentProvider (provider_store = metastore , material_name = "test" , version_ttl = 600.0 )
704
709
e_table = EncryptedTable (table = table , materials_provider = most_recent_provider )
0 commit comments