Skip to content

Commit bf3633e

Browse files
authored
Merge pull request #21 from mattsb42-aws/tests-linting
Tests linting
2 parents a0d0bce + 8c3bab0 commit bf3633e

30 files changed

+117
-87
lines changed

test/acceptance/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Dummy stub to make linters work better."""

test/acceptance/acceptance_test_utils.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,31 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Helper tools for use with acceptance tests."""
1314
import base64
1415
from collections import defaultdict
1516
import json
1617
import os
1718
import sys
18-
sys.path.append(os.path.join(
19-
os.path.abspath(os.path.dirname(__file__)),
20-
'..',
21-
'functional'
22-
))
2319

2420
import pytest
25-
from six.moves.urllib.parse import urlparse
26-
21+
from six.moves.urllib.parse import urlparse # moves confuse pylint: disable=wrong-import-order
2722

23+
from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey
24+
from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, KeyEncodingType
2825
from dynamodb_encryption_sdk.material_providers.static import StaticCryptographicMaterialsProvider
2926
from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider
30-
from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials, RawEncryptionMaterials
31-
from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey
32-
from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, ItemAction, KeyEncodingType
27+
from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials
3328
from dynamodb_encryption_sdk.structures import AttributeActions
3429

35-
import functional_test_vector_generators
30+
sys.path.append(os.path.join(
31+
os.path.abspath(os.path.dirname(__file__)),
32+
'..',
33+
'functional'
34+
))
35+
36+
# Convenience imports
37+
import functional_test_vector_generators # noqa: E402,I100 pylint: disable=import-error,wrong-import-position
3638

3739
_ENCRYPTED_ITEM_VECTORS_DIR = os.path.join(
3840
os.path.abspath(os.path.dirname(__file__)),
@@ -64,7 +66,7 @@ def _decode_item(item):
6466

6567

6668
def _build_plaintext_items(plaintext_file, version):
67-
""""""
69+
# pylint: disable=too-many-locals
6870
with open(plaintext_file) as f:
6971
plaintext_data = json.load(f)
7072

@@ -208,6 +210,7 @@ def _expand_items(ciphertext_items, plaintext_items):
208210

209211

210212
def load_scenarios():
213+
# pylint: disable=too-many-locals
211214
with open(_SCENARIO_FILE) as f:
212215
scenarios = json.load(f)
213216
keys_file = _filename_from_uri(scenarios['keys'])

test/acceptance/encrypted/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Dummy stub to make linters work better."""

test/acceptance/encrypted/test_item.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Acceptance tests for ``dynamodb_encryption_sdk.encrypted.item``."""
1314
import pytest
1415

1516
from dynamodb_encryption_sdk.encrypted import CryptoConfig
1617
from dynamodb_encryption_sdk.encrypted.item import decrypt_dynamodb_item
1718
from dynamodb_encryption_sdk.structures import EncryptionContext
18-
1919
from ..acceptance_test_utils import load_scenarios
2020

2121
pytestmark = [pytest.mark.acceptance, pytest.mark.local]

test/functional/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Dummy stub to make linters work better."""

test/functional/encrypted/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Dummy stub to make linters work better."""

test/functional/encrypted/test_client.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
""""""
13+
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.client``."""
1414
import boto3
1515
import hypothesis
1616
import pytest
1717

18+
from dynamodb_encryption_sdk.encrypted.client import EncryptedClient
19+
from dynamodb_encryption_sdk.internal.formatting.transform import ddb_to_dict, dict_to_ddb
1820
from ..functional_test_utils import (
19-
check_encrypted_item, example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
20-
cycle_batch_item_check, TEST_KEY, TEST_TABLE_NAME
21+
check_encrypted_item, cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp,
22+
set_parametrized_item, TEST_KEY, TEST_TABLE_NAME
2123
)
24+
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import
2225
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
23-
from dynamodb_encryption_sdk.encrypted.client import EncryptedClient
24-
from dynamodb_encryption_sdk.internal.formatting.transform import ddb_to_dict, dict_to_ddb
2526

2627
pytestmark = [pytest.mark.functional, pytest.mark.local]
2728

@@ -47,7 +48,7 @@ def _client_cycle_single_item_check(materials_provider, initial_actions, initial
4748
attribute_actions=initial_actions
4849
)
4950

50-
_put_result = e_client.put_item(
51+
_put_result = e_client.put_item( # noqa
5152
TableName=TEST_TABLE_NAME,
5253
Item=ddb_item
5354
)

test/functional/encrypted/test_item.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.item``."""
1314
import hypothesis
1415
import pytest
1516

16-
from ..functional_test_utils import (
17-
build_static_jce_cmp, cycle_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item
18-
)
19-
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
2017
from dynamodb_encryption_sdk.encrypted import CryptoConfig
2118
from dynamodb_encryption_sdk.encrypted.item import decrypt_python_item, encrypt_python_item
2219
from dynamodb_encryption_sdk.exceptions import DecryptionError, EncryptionError
2320
from dynamodb_encryption_sdk.internal.identifiers import ReservedAttributes
2421
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
22+
from ..functional_test_utils import (
23+
build_static_jce_cmp, cycle_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item
24+
)
25+
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
2526

2627
pytestmark = [pytest.mark.functional, pytest.mark.local]
2728

test/functional/encrypted/test_resource.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
""""""
13+
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.resource``."""
1414
import boto3
1515
import pytest
1616

17+
from dynamodb_encryption_sdk.encrypted.resource import EncryptedResource
1718
from ..functional_test_utils import (
18-
example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
19-
cycle_batch_item_check, TEST_TABLE_NAME
19+
cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_TABLE_NAME
2020
)
21-
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
22-
from dynamodb_encryption_sdk.encrypted.resource import EncryptedResource
21+
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import
2322

2423
pytestmark = [pytest.mark.functional, pytest.mark.local]
2524

test/functional/encrypted/test_table.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
""""""
13+
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.table``."""
1414
import boto3
1515
import hypothesis
1616
import pytest
1717

18+
from dynamodb_encryption_sdk.encrypted.table import EncryptedTable
1819
from ..functional_test_utils import (
19-
check_encrypted_item, example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
20+
check_encrypted_item, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
2021
TEST_KEY, TEST_TABLE_NAME
2122
)
23+
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import
2224
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
23-
from dynamodb_encryption_sdk.encrypted.table import EncryptedTable
2425

2526
pytestmark = [pytest.mark.functional, pytest.mark.local]
2627

@@ -44,7 +45,7 @@ def _table_cycle_check(materials_provider, initial_actions, initial_item):
4445
attribute_actions=initial_actions,
4546
)
4647

47-
_put_result = e_table.put_item(Item=item)
48+
_put_result = e_table.put_item(Item=item) # noqa
4849

4950
encrypted_result = table.get_item(Key=TEST_KEY)
5051
check_encrypted_item(item, encrypted_result['Item'], check_attribute_actions)

test/functional/functional_test_utils.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Helper tools for use in tests."""
1314
from __future__ import division
14-
import copy
15+
1516
from collections import defaultdict
17+
import copy
1618
from decimal import Decimal
1719
import itertools
1820

@@ -28,7 +30,7 @@
2830
from dynamodb_encryption_sdk.material_providers.static import StaticCryptographicMaterialsProvider
2931
from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider
3032
from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials, RawEncryptionMaterials
31-
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
33+
from dynamodb_encryption_sdk.structures import AttributeActions
3234

3335
_DELEGATED_KEY_CACHE = defaultdict(lambda: defaultdict(dict))
3436
TEST_TABLE_NAME = 'my_table'
@@ -39,7 +41,7 @@
3941
},
4042
'sort_attribute': {
4143
'type': 'N',
42-
'value': Decimal('99.233')
44+
'value': Decimal('99.233')
4345
}
4446
}
4547
TEST_KEY = {name: value['value'] for name, value in TEST_INDEX.items()}
@@ -51,7 +53,7 @@
5153
},
5254
'sort_attribute': {
5355
'type': 'N',
54-
'value': Decimal('99.233')
56+
'value': Decimal('99.233')
5557
}
5658
},
5759
{
@@ -61,7 +63,7 @@
6163
},
6264
'sort_attribute': {
6365
'type': 'N',
64-
'value': Decimal('92986745')
66+
'value': Decimal('92986745')
6567
}
6668
},
6769
{
@@ -71,7 +73,7 @@
7173
},
7274
'sort_attribute': {
7375
'type': 'N',
74-
'value': Decimal('2231.0001')
76+
'value': Decimal('2231.0001')
7577
}
7678
},
7779
{
@@ -81,7 +83,7 @@
8183
},
8284
'sort_attribute': {
8385
'type': 'N',
84-
'value': Decimal('732342')
86+
'value': Decimal('732342')
8587
}
8688
}
8789
]
@@ -301,7 +303,7 @@ def set_parametrized_cmp(metafunc):
301303

302304

303305
def set_parametrized_actions(metafunc):
304-
"""Set parametrized values for attribute actions"""
306+
"""Set parametrized values for attribute actions."""
305307
for name, actions in _ACTIONS.items():
306308
if name in metafunc.fixturenames:
307309
metafunc.parametrize(name, actions)
@@ -360,13 +362,13 @@ def check_encrypted_item(plaintext_item, ciphertext_item, attribute_actions):
360362

361363

362364
def _matching_key(actual_item, expected):
363-
expected_item = [
364-
i for i in expected
365-
if i['partition_attribute'] == actual_item['partition_attribute']
366-
and i['sort_attribute'] == actual_item['sort_attribute']
367-
]
368-
assert len(expected_item) == 1
369-
return expected_item[0]
365+
expected_item = [
366+
i for i in expected
367+
if i['partition_attribute'] == actual_item['partition_attribute'] and
368+
i['sort_attribute'] == actual_item['sort_attribute']
369+
]
370+
assert len(expected_item) == 1
371+
return expected_item[0]
370372

371373

372374
def _nop_transformer(item):
@@ -401,7 +403,7 @@ def cycle_batch_item_check(
401403
write_transformer=_nop_transformer,
402404
read_transformer=_nop_transformer
403405
):
404-
"""Common logic for cycling batch items."""
406+
"""Check that cycling (plaintext->encrypted->decrypted) item batch has the expected results."""
405407
check_attribute_actions = initial_actions.copy()
406408
check_attribute_actions.set_index_keys(*list(TEST_KEY.keys()))
407409
items = []
@@ -410,7 +412,7 @@ def cycle_batch_item_check(
410412
_item.update(key)
411413
items.append(write_transformer(_item))
412414

413-
_put_result = encrypted.batch_write_item(
415+
_put_result = encrypted.batch_write_item( # noqa
414416
RequestItems={
415417
TEST_TABLE_NAME: [
416418
{'PutRequest': {'Item': _item}}
@@ -447,7 +449,7 @@ def cycle_batch_item_check(
447449
transformer=read_transformer
448450
)
449451

450-
_delete_result = encrypted.batch_write_item(
452+
_delete_result = encrypted.batch_write_item( # noqa
451453
RequestItems={
452454
TEST_TABLE_NAME: [
453455
{'DeleteRequest': {'Key': _key}}
@@ -461,7 +463,7 @@ def cycle_batch_item_check(
461463

462464

463465
def cycle_item_check(plaintext_item, crypto_config):
464-
"""Common logic for cycled item (plaintext->encrypted->decrypted) tests: used by many test suites."""
466+
"""Check that cycling (plaintext->encrypted->decrypted) an item has the expected results."""
465467
ciphertext_item = encrypt_python_item(plaintext_item, crypto_config)
466468

467469
check_encrypted_item(plaintext_item, ciphertext_item, crypto_config.attribute_actions)

test/functional/functional_test_vector_generators.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""Helper tools for attribute de/serialization functional tests."""
13+
"""Helper tools for collecting test vectors for use in functional tests."""
1414
import base64
15-
from decimal import Decimal
1615
import codecs
16+
from decimal import Decimal
1717
import json
1818
import os
1919

2020
from boto3.dynamodb.types import Binary
21+
2122
from dynamodb_encryption_sdk.identifiers import ItemAction
2223
from dynamodb_encryption_sdk.structures import AttributeActions
2324

@@ -41,7 +42,7 @@
4142
)
4243

4344

44-
def decode_value(value, transform_binary=False):
45+
def decode_value(value, transform_binary=False): # noqa: C901
4546
def _decode_string(_value):
4647
return _value
4748

0 commit comments

Comments
 (0)