Skip to content

Tests linting #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/acceptance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Dummy stub to make linters work better."""
27 changes: 15 additions & 12 deletions test/acceptance/acceptance_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Helper tools for use with acceptance tests."""
import base64
from collections import defaultdict
import json
import os
import sys
sys.path.append(os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'..',
'functional'
))

import pytest
from six.moves.urllib.parse import urlparse

from six.moves.urllib.parse import urlparse # moves confuse pylint: disable=wrong-import-order

from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey
from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, KeyEncodingType
from dynamodb_encryption_sdk.material_providers.static import StaticCryptographicMaterialsProvider
from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider
from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials, RawEncryptionMaterials
from dynamodb_encryption_sdk.delegated_keys.jce import JceNameLocalDelegatedKey
from dynamodb_encryption_sdk.identifiers import EncryptionKeyTypes, ItemAction, KeyEncodingType
from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials
from dynamodb_encryption_sdk.structures import AttributeActions

import functional_test_vector_generators
sys.path.append(os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'..',
'functional'
))

# Convenience imports
import functional_test_vector_generators # noqa: E402,I100 pylint: disable=import-error,wrong-import-position

_ENCRYPTED_ITEM_VECTORS_DIR = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
Expand Down Expand Up @@ -64,7 +66,7 @@ def _decode_item(item):


def _build_plaintext_items(plaintext_file, version):
""""""
# pylint: disable=too-many-locals
with open(plaintext_file) as f:
plaintext_data = json.load(f)

Expand Down Expand Up @@ -208,6 +210,7 @@ def _expand_items(ciphertext_items, plaintext_items):


def load_scenarios():
# pylint: disable=too-many-locals
with open(_SCENARIO_FILE) as f:
scenarios = json.load(f)
keys_file = _filename_from_uri(scenarios['keys'])
Expand Down
1 change: 1 addition & 0 deletions test/acceptance/encrypted/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Dummy stub to make linters work better."""
2 changes: 1 addition & 1 deletion test/acceptance/encrypted/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Acceptance tests for ``dynamodb_encryption_sdk.encrypted.item``."""
import pytest

from dynamodb_encryption_sdk.encrypted import CryptoConfig
from dynamodb_encryption_sdk.encrypted.item import decrypt_dynamodb_item
from dynamodb_encryption_sdk.structures import EncryptionContext

from ..acceptance_test_utils import load_scenarios

pytestmark = [pytest.mark.acceptance, pytest.mark.local]
Expand Down
1 change: 1 addition & 0 deletions test/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Dummy stub to make linters work better."""
1 change: 1 addition & 0 deletions test/functional/encrypted/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Dummy stub to make linters work better."""
13 changes: 7 additions & 6 deletions test/functional/encrypted/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
""""""
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.client``."""
import boto3
import hypothesis
import pytest

from dynamodb_encryption_sdk.encrypted.client import EncryptedClient
from dynamodb_encryption_sdk.internal.formatting.transform import ddb_to_dict, dict_to_ddb
from ..functional_test_utils import (
check_encrypted_item, example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
cycle_batch_item_check, TEST_KEY, TEST_TABLE_NAME
check_encrypted_item, cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp,
set_parametrized_item, TEST_KEY, TEST_TABLE_NAME
)
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
from dynamodb_encryption_sdk.encrypted.client import EncryptedClient
from dynamodb_encryption_sdk.internal.formatting.transform import ddb_to_dict, dict_to_ddb

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

Expand All @@ -47,7 +48,7 @@ def _client_cycle_single_item_check(materials_provider, initial_actions, initial
attribute_actions=initial_actions
)

_put_result = e_client.put_item(
_put_result = e_client.put_item( # noqa
TableName=TEST_TABLE_NAME,
Item=ddb_item
)
Expand Down
9 changes: 5 additions & 4 deletions test/functional/encrypted/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.item``."""
import hypothesis
import pytest

from ..functional_test_utils import (
build_static_jce_cmp, cycle_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item
)
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
from dynamodb_encryption_sdk.encrypted import CryptoConfig
from dynamodb_encryption_sdk.encrypted.item import decrypt_python_item, encrypt_python_item
from dynamodb_encryption_sdk.exceptions import DecryptionError, EncryptionError
from dynamodb_encryption_sdk.internal.identifiers import ReservedAttributes
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
from ..functional_test_utils import (
build_static_jce_cmp, cycle_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item
)
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS

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

Expand Down
9 changes: 4 additions & 5 deletions test/functional/encrypted/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
""""""
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.resource``."""
import boto3
import pytest

from dynamodb_encryption_sdk.encrypted.resource import EncryptedResource
from ..functional_test_utils import (
example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
cycle_batch_item_check, TEST_TABLE_NAME
cycle_batch_item_check, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item, TEST_TABLE_NAME
)
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
from dynamodb_encryption_sdk.encrypted.resource import EncryptedResource
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import

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

Expand Down
9 changes: 5 additions & 4 deletions test/functional/encrypted/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
""""""
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.table``."""
import boto3
import hypothesis
import pytest

from dynamodb_encryption_sdk.encrypted.table import EncryptedTable
from ..functional_test_utils import (
check_encrypted_item, example_table, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
check_encrypted_item, set_parametrized_actions, set_parametrized_cmp, set_parametrized_item,
TEST_KEY, TEST_TABLE_NAME
)
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import
from ..hypothesis_strategies import ddb_items, SLOW_SETTINGS, VERY_SLOW_SETTINGS
from dynamodb_encryption_sdk.encrypted.table import EncryptedTable

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

Expand All @@ -44,7 +45,7 @@ def _table_cycle_check(materials_provider, initial_actions, initial_item):
attribute_actions=initial_actions,
)

_put_result = e_table.put_item(Item=item)
_put_result = e_table.put_item(Item=item) # noqa

encrypted_result = table.get_item(Key=TEST_KEY)
check_encrypted_item(item, encrypted_result['Item'], check_attribute_actions)
Expand Down
40 changes: 21 additions & 19 deletions test/functional/functional_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Helper tools for use in tests."""
from __future__ import division
import copy

from collections import defaultdict
import copy
from decimal import Decimal
import itertools

Expand All @@ -28,7 +30,7 @@
from dynamodb_encryption_sdk.material_providers.static import StaticCryptographicMaterialsProvider
from dynamodb_encryption_sdk.material_providers.wrapped import WrappedCryptographicMaterialsProvider
from dynamodb_encryption_sdk.materials.raw import RawDecryptionMaterials, RawEncryptionMaterials
from dynamodb_encryption_sdk.structures import AttributeActions, EncryptionContext
from dynamodb_encryption_sdk.structures import AttributeActions

_DELEGATED_KEY_CACHE = defaultdict(lambda: defaultdict(dict))
TEST_TABLE_NAME = 'my_table'
Expand All @@ -39,7 +41,7 @@
},
'sort_attribute': {
'type': 'N',
'value': Decimal('99.233')
'value': Decimal('99.233')
}
}
TEST_KEY = {name: value['value'] for name, value in TEST_INDEX.items()}
Expand All @@ -51,7 +53,7 @@
},
'sort_attribute': {
'type': 'N',
'value': Decimal('99.233')
'value': Decimal('99.233')
}
},
{
Expand All @@ -61,7 +63,7 @@
},
'sort_attribute': {
'type': 'N',
'value': Decimal('92986745')
'value': Decimal('92986745')
}
},
{
Expand All @@ -71,7 +73,7 @@
},
'sort_attribute': {
'type': 'N',
'value': Decimal('2231.0001')
'value': Decimal('2231.0001')
}
},
{
Expand All @@ -81,7 +83,7 @@
},
'sort_attribute': {
'type': 'N',
'value': Decimal('732342')
'value': Decimal('732342')
}
}
]
Expand Down Expand Up @@ -301,7 +303,7 @@ def set_parametrized_cmp(metafunc):


def set_parametrized_actions(metafunc):
"""Set parametrized values for attribute actions"""
"""Set parametrized values for attribute actions."""
for name, actions in _ACTIONS.items():
if name in metafunc.fixturenames:
metafunc.parametrize(name, actions)
Expand Down Expand Up @@ -360,13 +362,13 @@ def check_encrypted_item(plaintext_item, ciphertext_item, attribute_actions):


def _matching_key(actual_item, expected):
expected_item = [
i for i in expected
if i['partition_attribute'] == actual_item['partition_attribute']
and i['sort_attribute'] == actual_item['sort_attribute']
]
assert len(expected_item) == 1
return expected_item[0]
expected_item = [
i for i in expected
if i['partition_attribute'] == actual_item['partition_attribute'] and
i['sort_attribute'] == actual_item['sort_attribute']
]
assert len(expected_item) == 1
return expected_item[0]


def _nop_transformer(item):
Expand Down Expand Up @@ -401,7 +403,7 @@ def cycle_batch_item_check(
write_transformer=_nop_transformer,
read_transformer=_nop_transformer
):
"""Common logic for cycling batch items."""
"""Check that cycling (plaintext->encrypted->decrypted) item batch has the expected results."""
check_attribute_actions = initial_actions.copy()
check_attribute_actions.set_index_keys(*list(TEST_KEY.keys()))
items = []
Expand All @@ -410,7 +412,7 @@ def cycle_batch_item_check(
_item.update(key)
items.append(write_transformer(_item))

_put_result = encrypted.batch_write_item(
_put_result = encrypted.batch_write_item( # noqa
RequestItems={
TEST_TABLE_NAME: [
{'PutRequest': {'Item': _item}}
Expand Down Expand Up @@ -447,7 +449,7 @@ def cycle_batch_item_check(
transformer=read_transformer
)

_delete_result = encrypted.batch_write_item(
_delete_result = encrypted.batch_write_item( # noqa
RequestItems={
TEST_TABLE_NAME: [
{'DeleteRequest': {'Key': _key}}
Expand All @@ -461,7 +463,7 @@ def cycle_batch_item_check(


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

check_encrypted_item(plaintext_item, ciphertext_item, crypto_config.attribute_actions)
Expand Down
7 changes: 4 additions & 3 deletions test/functional/functional_test_vector_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Helper tools for attribute de/serialization functional tests."""
"""Helper tools for collecting test vectors for use in functional tests."""
import base64
from decimal import Decimal
import codecs
from decimal import Decimal
import json
import os

from boto3.dynamodb.types import Binary

from dynamodb_encryption_sdk.identifiers import ItemAction
from dynamodb_encryption_sdk.structures import AttributeActions

Expand All @@ -41,7 +42,7 @@
)


def decode_value(value, transform_binary=False):
def decode_value(value, transform_binary=False): # noqa: C901
def _decode_string(_value):
return _value

Expand Down
Loading