Skip to content

Commit d335a02

Browse files
committed
fix names and add handling for region selection
1 parent b0500ab commit d335a02

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

test/functional/functional_test_utils.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import boto3
2424
import pytest
2525
from boto3.dynamodb.types import Binary
26+
from botocore.exceptions import NoRegionError
2627
from moto import mock_dynamodb2
2728

2829
from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey
@@ -43,11 +44,12 @@
4344
RUNNING_IN_TRAVIS = "TRAVIS" in os.environ
4445
_DELEGATED_KEY_CACHE = defaultdict(lambda: defaultdict(dict))
4546
TEST_TABLE_NAME = "my_table"
47+
TEST_REGION_NAME = "us-west-2"
4648
TEST_INDEX = {
4749
"partition_attribute": {"type": "S", "value": "test_value"},
4850
"sort_attribute": {"type": "N", "value": Decimal("99.233")},
4951
}
50-
SECONARY_INDEX = {
52+
SECONDARY_INDEX = {
5153
"secondary_index_1": {"type": "B", "value": Binary(b"\x00\x01\x02")},
5254
"secondary_index_2": {"type": "S", "value": "another_value"},
5355
}
@@ -76,7 +78,7 @@
7678
@pytest.fixture
7779
def example_table():
7880
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)
8082
ddb.create_table(
8183
TableName=TEST_TABLE_NAME,
8284
KeySchema=[
@@ -94,9 +96,9 @@ def example_table():
9496

9597

9698
@pytest.fixture
97-
def table_with_local_seconary_indexes():
99+
def table_with_local_secondary_indexes():
98100
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)
100102
ddb.create_table(
101103
TableName=TEST_TABLE_NAME,
102104
KeySchema=[
@@ -117,7 +119,7 @@ def table_with_local_seconary_indexes():
117119
],
118120
AttributeDefinitions=[
119121
{"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())
121123
],
122124
ProvisionedThroughput={"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
123125
)
@@ -129,7 +131,7 @@ def table_with_local_seconary_indexes():
129131
@pytest.fixture
130132
def table_with_global_secondary_indexes():
131133
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)
133135
ddb.create_table(
134136
TableName=TEST_TABLE_NAME,
135137
KeySchema=[
@@ -152,7 +154,7 @@ def table_with_global_secondary_indexes():
152154
],
153155
AttributeDefinitions=[
154156
{"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())
156158
],
157159
ProvisionedThroughput={"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
158160
)
@@ -649,19 +651,19 @@ def client_cycle_batch_items_check_paginators(
649651

650652

651653
def build_metastore():
652-
client = boto3.client("dynamodb", region_name="us-west-2")
654+
client = boto3.client("dynamodb", region_name=TEST_REGION_NAME)
653655
table_name = base64.urlsafe_b64encode(os.urandom(32)).decode("utf-8").replace("=", ".")
654656

655657
MetaStore.create_table(client, table_name, 1, 1)
656658
waiter = client.get_waiter("table_exists")
657659
waiter.wait(TableName=table_name)
658660

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)
660662
return MetaStore(table, build_static_jce_cmp("AES", 256, "HmacSHA256", 256)), table_name
661663

662664

663665
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)
665667
client.delete_table(TableName=table_name)
666668
# It sometimes takes a long time to delete a table.
667669
# If hanging, asynchronously deleting tables becomes an issue,
@@ -698,7 +700,10 @@ def _count_gets(records, table_name):
698700

699701

700702
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)
702707

703708
most_recent_provider = MostRecentProvider(provider_store=metastore, material_name="test", version_ttl=600.0)
704709
e_table = EncryptedTable(table=table, materials_provider=most_recent_provider)

test/functional/test_structures.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
TEST_TABLE_NAME,
2323
example_table,
2424
table_with_global_secondary_indexes,
25-
table_with_local_seconary_indexes,
25+
table_with_local_secondary_indexes,
2626
)
2727

2828
pytestmark = [pytest.mark.functional, pytest.mark.local]
@@ -37,14 +37,14 @@ def test_tableinfo_refresh_indexes_no_secondary_indexes(example_table):
3737
table.refresh_indexed_attributes(client)
3838

3939

40-
def test_tableinfo_refresh_indexes_with_gsis(table_with_global_seconary_indexes):
40+
def test_tableinfo_refresh_indexes_with_gsis(table_with_global_secondary_indexes):
4141
client = boto3.client("dynamodb", region_name="us-west-2")
4242
table = TableInfo(name=TEST_TABLE_NAME)
4343

4444
table.refresh_indexed_attributes(client)
4545

4646

47-
def test_tableinfo_refresh_indexes_with_lsis(table_with_local_seconary_indexes):
47+
def test_tableinfo_refresh_indexes_with_lsis(table_with_local_secondary_indexes):
4848
client = boto3.client("dynamodb", region_name="us-west-2")
4949
table = TableInfo(name=TEST_TABLE_NAME)
5050

0 commit comments

Comments
 (0)