Skip to content

Commit 677d51d

Browse files
authored
Merge pull request #41 from mattsb42-aws/dev-23
moving test selection to pytest markers
2 parents 5d7160a + a3d7a59 commit 677d51d

File tree

58 files changed

+188
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+188
-62
lines changed

.travis.yml

+28-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,37 @@ language: python
33
matrix:
44
include:
55
- python: 2.7
6-
env: TOXENV=py27
6+
env: TOXENV=py27-local
7+
- python: 2.7
8+
env: TOXENV=py27-integ
9+
- python: 2.7
10+
env: TOXENV=py27-accept
11+
- python: 2.7
12+
env: TOXENV=py27-examples
13+
- python: 3.4
14+
env: TOXENV=py34-local
715
- python: 3.4
8-
env: TOXENV=py34
16+
env: TOXENV=py34-integ
17+
- python: 3.4
18+
env: TOXENV=py34-accept
19+
- python: 3.4
20+
env: TOXENV=py34-examples
21+
- python: 3.5
22+
env: TOXENV=py35-local
923
- python: 3.5
10-
env: TOXENV=py35
24+
env: TOXENV=py35-integ
25+
- python: 3.5
26+
env: TOXENV=py35-accept
27+
- python: 3.5
28+
env: TOXENV=py35-examples
29+
- python: 3.6
30+
env: TOXENV=py36-local
1131
- python: 3.6
12-
env: TOXENV=py36
32+
env: TOXENV=py36-integ
33+
- python: 3.6
34+
env: TOXENV=py36-accept
35+
- python: 3.6
36+
env: TOXENV=py36-examples
1337
- python: 3.6
1438
env: TOXENV=bandit
1539
- python: 3.6
@@ -27,8 +51,6 @@ matrix:
2751
env: TOXENV=flake8-tests
2852
- python: 3.6
2953
env: TOXENV=pylint-tests
30-
- python: 3.6
31-
env: TOXENV=examples
3254
- python: 3.6
3355
env: TOXENV=flake8-examples
3456
- python: 3.6

examples/test/test_i_basic_encryption.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import pytest
2323

2424
from basic_encryption import cycle_string
25-
from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests
25+
from integration_test_utils import get_cmk_arn
26+
27+
pytestmark = [pytest.mark.examples]
2628

2729

28-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
2930
def test_cycle_string():
3031
plaintext = os.urandom(1024)
3132
cmk_arn = get_cmk_arn()

examples/test/test_i_basic_file_encryption_with_multiple_providers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import pytest
2424

2525
from basic_file_encryption_with_multiple_providers import cycle_file
26-
from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests
26+
from integration_test_utils import get_cmk_arn
27+
28+
pytestmark = [pytest.mark.examples]
2729

2830

29-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
3031
def test_cycle_file():
3132
cmk_arn = get_cmk_arn()
3233
_handle, filename = tempfile.mkstemp()

examples/test/test_i_basic_file_encryption_with_raw_key_provider.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import pytest
2323

2424
from basic_file_encryption_with_raw_key_provider import cycle_file
25-
from integration_test_utils import SKIP_MESSAGE, skip_tests
25+
26+
pytestmark = [pytest.mark.examples]
2627

2728

28-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
2929
def test_cycle_file():
3030
_handle, filename = tempfile.mkstemp()
3131
with open(filename, 'wb') as f:

examples/test/test_i_data_key_caching_basic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
import pytest
2222

2323
from data_key_caching_basic import encrypt_with_caching
24-
from integration_test_utils import get_cmk_arn, SKIP_MESSAGE, skip_tests
24+
from integration_test_utils import get_cmk_arn
25+
26+
pytestmark = [pytest.mark.examples]
2527

2628

27-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
2829
def test_encrypt_with_caching():
2930
cmk_arn = get_cmk_arn()
3031
encrypt_with_caching(

setup.cfg

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ branch = True
1010
[coverage:report]
1111
show_missing = True
1212

13+
[tool:pytest]
14+
markers =
15+
local: superset of unit and functional (does not require network access)
16+
unit: mark test as a unit test (does not require network access)
17+
functional: mark test as a functional test (does not require network access)
18+
integ: mark a test as an integration test (requires network access)
19+
accept: mark a test as an acceptance test (requires network access)
20+
examples: mark a test as an examples test (requires network access)
21+
1322
# Flake8 Configuration
1423
[flake8]
1524
max_complexity = 10

test/functional/test_f_aws_encryption_sdk_client.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider
3535
from aws_encryption_sdk.materials_managers import DecryptionMaterialsRequest, EncryptionMaterialsRequest
3636

37+
pytestmark = [pytest.mark.functional, pytest.mark.local]
38+
3739
VALUES = {
3840
'frame_lengths': ( # Assuming 1280 byte plaintext:
3941
0, # Non-framed
@@ -347,7 +349,10 @@ def test_encryption_cycle_raw_mkp(wrapping_algorithm, encryption_key_type, decry
347349
assert plaintext == VALUES['plaintext_128']
348350

349351

350-
@pytest.mark.skipif(not _mgf1_sha256_supported(), reason='MGF1-SHA256 not supported by this backend')
352+
@pytest.mark.skipif(
353+
not _mgf1_sha256_supported(),
354+
reason='MGF1-SHA256 not supported by this backend: OpenSSL required v1.0.2+'
355+
)
351356
@pytest.mark.parametrize('wrapping_algorithm, encryption_key_type, decryption_key_type', (
352357
(WrappingAlgorithm.RSA_OAEP_SHA256_MGF1, EncryptionKeyType.PRIVATE, EncryptionKeyType.PRIVATE),
353358
(WrappingAlgorithm.RSA_OAEP_SHA256_MGF1, EncryptionKeyType.PUBLIC, EncryptionKeyType.PRIVATE)

test/functional/test_f_crypto.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from aws_encryption_sdk.internal.crypto.authentication import Signer
2121
from aws_encryption_sdk.internal.crypto.elliptic_curve import _ecc_static_length_signature
2222

23+
pytestmark = [pytest.mark.functional, pytest.mark.local]
24+
2325

2426
# Run several of each type to make get a high probability of forcing signature length correction
2527
@pytest.mark.parametrize('algorithm', [

test/functional/test_f_crypto_iv.py

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from aws_encryption_sdk.internal.crypto.iv import frame_iv, header_auth_iv, non_framed_body_iv
1818
from aws_encryption_sdk.internal.defaults import ALGORITHM, MAX_FRAME_COUNT
1919

20+
pytestmark = [pytest.mark.functional, pytest.mark.local]
21+
2022
VALUES = {
2123
'ivs': {
2224
'header_auth': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',

test/functional/test_f_xcompat.py

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from aws_encryption_sdk.internal.str_ops import to_bytes
3030
from aws_encryption_sdk.key_providers.raw import RawMasterKeyProvider
3131

32+
pytestmark = [pytest.mark.accept]
33+
3234

3335
# Environment-specific test file locator. May not always exist.
3436
def _file_root():

test/integration/README.rst

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ In order to run these integration tests successfully, these things must be confi
77
#. Ensure that AWS credentials are available in one of the `automatically discoverable credential locations`_.
88
#. Set environment variable ``AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID`` to valid
99
`AWS KMS key id`_ to use for integration tests.
10-
#. Set environment variable ``AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL`` to ``RUN``.
1110

1211
.. _automatically discoverable credential locations: http://boto3.readthedocs.io/en/latest/guide/configuration.html
1312
.. _AWS KMS key id: http://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html

test/integration/integration_test_utils.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,26 @@
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-
"""Utility functions to handle configuration, credentials setup, and test skip
14-
decision making for integration tests."""
13+
"""Utility functions to handle configuration and credentials setup for integration tests."""
1514
import os
1615

1716
from aws_encryption_sdk.key_providers.kms import KMSMasterKeyProvider
1817

19-
SKIP_MESSAGE = (
20-
'Required environment variables not found. Skipping integration tests.'
21-
' See integration tests README.rst for more information.'
22-
)
23-
TEST_CONTROL = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_CONTROL'
2418
AWS_KMS_KEY_ID = 'AWS_ENCRYPTION_SDK_PYTHON_INTEGRATION_TEST_AWS_KMS_KEY_ID'
2519

2620

27-
def skip_tests():
28-
"""Only run tests if both required environment variables are found."""
29-
test_control = os.environ.get(TEST_CONTROL, None)
30-
key_id = os.environ.get(AWS_KMS_KEY_ID, None)
31-
return not (test_control == 'RUN' and key_id is not None)
32-
33-
3421
def get_cmk_arn():
3522
"""Retrieves the target CMK ARN from environment variable."""
36-
return os.environ.get(AWS_KMS_KEY_ID)
23+
arn = os.environ.get(AWS_KMS_KEY_ID, None)
24+
if arn is None:
25+
raise ValueError(
26+
'Environment variable "{}" must be set to a valid KMS CMK ARN for integration tests to run'.format(
27+
AWS_KMS_KEY_ID
28+
)
29+
)
30+
if arn.startswith('arn:') and ':alias/' not in arn:
31+
return arn
32+
raise ValueError('KMS CMK ARN provided for integration tests much be a key not an alias')
3733

3834

3935
def setup_kms_master_key_provider():

test/integration/test_i_aws_encrytion_sdk_client.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
import io
1515
import unittest
1616

17+
import pytest
18+
1719
import aws_encryption_sdk
1820
from aws_encryption_sdk.identifiers import Algorithm
19-
from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests
21+
from .integration_test_utils import setup_kms_master_key_provider
22+
23+
pytestmark = [pytest.mark.integ]
2024

2125

2226
VALUES = {
@@ -39,8 +43,6 @@
3943
class TestKMSThickClientIntegration(unittest.TestCase):
4044

4145
def setUp(self):
42-
if skip_tests():
43-
self.skipTest(SKIP_MESSAGE)
4446
self.kms_master_key_provider = setup_kms_master_key_provider()
4547

4648
def test_encryption_cycle_default_algorithm_framed_stream(self):

test/integration/test_i_thread_safety.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
from six.moves import queue # six.moves confuses pylint: disable=import-error
2323

2424
import aws_encryption_sdk
25-
from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests
25+
from .integration_test_utils import setup_kms_master_key_provider
26+
27+
pytestmark = [pytest.mark.integ]
2628

2729

2830
PLAINTEXT = (
@@ -101,7 +103,6 @@ def random_pause_time(max_seconds=3):
101103
return SystemRandom().random() * 10 % max_seconds
102104

103105

104-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
105106
def test_threading_loop():
106107
"""Test thread safety of client."""
107108
rounds = 20
@@ -127,7 +128,6 @@ def test_threading_loop():
127128
assert all(value == PLAINTEXT for value in decrypted_values)
128129

129130

130-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
131131
def test_threading_loop_with_common_cache():
132132
"""Test thread safety of client while using common cryptographic materials cache across all threads."""
133133
rounds = 20

test/integration/test_i_xcompat_kms.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import pytest
1818

1919
import aws_encryption_sdk
20-
from .integration_test_utils import setup_kms_master_key_provider, SKIP_MESSAGE, skip_tests
20+
from .integration_test_utils import setup_kms_master_key_provider
21+
22+
pytestmark = [pytest.mark.accept]
2123

2224

2325
# Environment-specific test file locator. May not always exist.
@@ -32,9 +34,6 @@ def _file_root():
3234

3335

3436
def _generate_test_cases():
35-
if skip_tests():
36-
return []
37-
3837
kms_key_provider = setup_kms_master_key_provider()
3938
try:
4039
root_dir = os.path.abspath(file_root())
@@ -73,7 +72,6 @@ def _generate_test_cases():
7372
return _test_cases
7473

7574

76-
@pytest.mark.skipif(skip_tests(), reason=SKIP_MESSAGE)
7775
@pytest.mark.parametrize('plaintext_filename,ciphertext_filename,key_provider', _generate_test_cases())
7876
def test_decrypt_from_file(plaintext_filename, ciphertext_filename, key_provider):
7977
"""Tests decrypt from known good files."""

test/unit/test_aws_encryption_sdk.py

+3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
import unittest
1515

1616
from mock import MagicMock, patch, sentinel
17+
import pytest
1718
import six
1819

1920
import aws_encryption_sdk
2021
import aws_encryption_sdk.internal.defaults
2122

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2225

2326
class TestAwsEncryptionSdk(unittest.TestCase):
2427

test/unit/test_caches.py

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from aws_encryption_sdk.materials_managers import DecryptionMaterialsRequest, EncryptionMaterialsRequest
2727
from aws_encryption_sdk.structures import DataKey, MasterKeyInfo
2828

29+
pytestmark = [pytest.mark.unit, pytest.mark.local]
30+
2931

3032
VALUES = {
3133
'basic': {

test/unit/test_caches_base.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from aws_encryption_sdk.caches.base import CryptoMaterialsCache
1717

18+
pytestmark = [pytest.mark.unit, pytest.mark.local]
19+
1820

1921
def test_abstracts():
2022
with pytest.raises(TypeError) as excinfo:

test/unit/test_caches_crypto_cache_entry.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from aws_encryption_sdk.exceptions import NotSupportedError
2323
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
2424

25+
pytestmark = [pytest.mark.unit, pytest.mark.local]
26+
2527
_VALID_KWARGS = {
2628
'CryptoMaterialsCacheEntryHints': dict(lifetime=5.0),
2729
'CryptoMaterialsCacheEntry': dict(

test/unit/test_caches_local.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from aws_encryption_sdk.caches.local import _OPPORTUNISTIC_EVICTION_ROUNDS, LocalCryptoMaterialsCache
2323
from aws_encryption_sdk.exceptions import CacheKeyError, NotSupportedError
2424

25+
pytestmark = [pytest.mark.unit, pytest.mark.local]
26+
2527

2628
def build_lcmc(**custom_kwargs):
2729
kwargs = dict(capacity=10)

test/unit/test_caches_null.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from aws_encryption_sdk.exceptions import CacheKeyError
2020
from aws_encryption_sdk.materials_managers import DecryptionMaterials, EncryptionMaterials
2121

22+
pytestmark = [pytest.mark.unit, pytest.mark.local]
23+
2224

2325
def test_put_encryption_materials():
2426
cache_key = b'ex_cache_key'

test/unit/test_crypto_authentication_signer.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from aws_encryption_sdk.internal.defaults import ALGORITHM
2121
from .test_crypto import VALUES
2222

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2325

2426
@pytest.yield_fixture
2527
def patch_default_backend(mocker):

test/unit/test_crypto_authentication_verifier.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from aws_encryption_sdk.internal.defaults import ALGORITHM
2121
from .test_crypto import VALUES
2222

23+
pytestmark = [pytest.mark.unit, pytest.mark.local]
24+
2325

2426
@pytest.yield_fixture
2527
def patch_default_backend(mocker):

test/unit/test_crypto_data_keys.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import aws_encryption_sdk.internal.crypto.data_keys
1919
from aws_encryption_sdk.internal.crypto.data_keys import derive_data_encryption_key
2020

21+
pytestmark = [pytest.mark.unit, pytest.mark.local]
22+
2123

2224
@pytest.yield_fixture
2325
def patch_default_backend(mocker):

test/unit/test_crypto_elliptic_curve.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
)
2929
from .test_crypto import VALUES
3030

31+
pytestmark = [pytest.mark.unit, pytest.mark.local]
32+
3133

3234
@pytest.yield_fixture
3335
def patch_default_backend(mocker):

0 commit comments

Comments
 (0)