Skip to content

Commit 852275c

Browse files
authored
Merge pull request #6 from mattsb42-aws/test-helpers
Test helpers
2 parents 2ee8800 + b7c4172 commit 852275c

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

test/functional/functional_test_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,7 @@ def diverse_item():
238238
_reserved_attributes = set([attr.value for attr in ReservedAttributes])
239239

240240

241-
def cycle_item_check(plaintext_item, crypto_config):
242-
"""Common logic for cycled item (plaintext->encrypted->decrypted) tests: used by many test suites."""
243-
ciphertext_item = encrypt_python_item(plaintext_item, crypto_config)
244-
241+
def check_encrypted_item(plaintext_item, ciphertext_item, attribute_actions):
245242
# Verify that all expected attributes are present
246243
ciphertext_attributes = set(ciphertext_item.keys())
247244
plaintext_attributes = set(plaintext_item.keys())
@@ -256,12 +253,19 @@ def cycle_item_check(plaintext_item, crypto_config):
256253
continue
257254

258255
# If the attribute should have been encrypted, verify that it is Binary and different from the original
259-
if crypto_config.attribute_actions.action(name) is ItemAction.ENCRYPT_AND_SIGN:
256+
if attribute_actions.action(name) is ItemAction.ENCRYPT_AND_SIGN:
260257
assert isinstance(value, Binary)
261258
assert value != plaintext_item[name]
262259
# Otherwise, verify that it is the same as the original
263260
else:
264261
assert value == plaintext_item[name]
265262

263+
264+
def cycle_item_check(plaintext_item, crypto_config):
265+
"""Common logic for cycled item (plaintext->encrypted->decrypted) tests: used by many test suites."""
266+
ciphertext_item = encrypt_python_item(plaintext_item, crypto_config)
267+
268+
check_encrypted_item(plaintext_item, ciphertext_item, crypto_config.attribute_actions)
269+
266270
cycled_item = decrypt_python_item(ciphertext_item, crypto_config)
267271
assert cycled_item == plaintext_item

test/functional/test_f_encrypted_item.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,61 +45,48 @@ def test_unsigned_item():
4545
exc_info.match(r'No signature attribute found in item')
4646

4747

48-
def test_ephemeral_item_cycle(some_cmps, parametrized_actions, parametrized_item):
49-
"""Test a small number of curated CMPs against a small number of curated items."""
48+
def _item_cycle_check(materials_provider, attribute_actions, item):
5049
crypto_config = CryptoConfig(
51-
materials_provider=some_cmps,
50+
materials_provider=materials_provider,
5251
encryption_context=EncryptionContext(),
53-
attribute_actions=parametrized_actions
52+
attribute_actions=attribute_actions
5453
)
55-
cycle_item_check(parametrized_item, crypto_config)
54+
cycle_item_check(item, crypto_config)
55+
56+
57+
def test_ephemeral_item_cycle(some_cmps, parametrized_actions, parametrized_item):
58+
"""Test a small number of curated CMPs against a small number of curated items."""
59+
_item_cycle_check(some_cmps, parametrized_actions, parametrized_item)
5660

5761

5862
@pytest.mark.slow
5963
def test_ephemeral_item_cycle_slow(all_the_cmps, parametrized_actions, parametrized_item):
6064
"""Test ALL THE CMPS against a small number of curated items."""
61-
crypto_config = CryptoConfig(
62-
materials_provider=all_the_cmps,
63-
encryption_context=EncryptionContext(),
64-
attribute_actions=parametrized_actions
65-
)
66-
cycle_item_check(parametrized_item, crypto_config)
65+
_item_cycle_check(all_the_cmps, parametrized_actions, parametrized_item)
6766

6867

6968
@pytest.mark.slow
69+
@pytest.mark.hypothesis
7070
@SLOW_SETTINGS
7171
@hypothesis.given(item=ddb_items)
7272
def test_ephemeral_item_cycle_hypothesis_slow(some_cmps, parametrized_actions, item):
7373
"""Test a small number of curated CMPs against a large number of items."""
74-
crypto_config = CryptoConfig(
75-
materials_provider=some_cmps,
76-
encryption_context=EncryptionContext(),
77-
attribute_actions=parametrized_actions
78-
)
79-
cycle_item_check(item, crypto_config)
74+
_item_cycle_check(some_cmps, parametrized_actions, item)
8075

8176

8277
@pytest.mark.veryslow
78+
@pytest.mark.hypothesis
8379
@VERY_SLOW_SETTINGS
8480
@hypothesis.given(item=ddb_items)
8581
def test_ephemeral_item_cycle_hypothesis_veryslow(some_cmps, parametrized_actions, item):
8682
"""Test a small number of curated CMPs against ALL THE ITEMS."""
87-
crypto_config = CryptoConfig(
88-
materials_provider=some_cmps,
89-
encryption_context=EncryptionContext(),
90-
attribute_actions=parametrized_actions
91-
)
92-
cycle_item_check(item, crypto_config)
83+
_item_cycle_check(some_cmps, parametrized_actions, item)
9384

9485

9586
@pytest.mark.nope
87+
@pytest.mark.hypothesis
9688
@VERY_SLOW_SETTINGS
9789
@hypothesis.given(item=ddb_items)
9890
def test_ephemeral_item_cycle_hypothesis_nope(all_the_cmps, parametrized_actions, item):
9991
"""Test ALL THE CMPs against ALL THE ITEMS."""
100-
crypto_config = CryptoConfig(
101-
materials_provider=all_the_cmps,
102-
encryption_context=EncryptionContext(),
103-
attribute_actions=parametrized_actions
104-
)
105-
cycle_item_check(item, crypto_config)
92+
_item_cycle_check(all_the_cmps, parametrized_actions, item)

0 commit comments

Comments
 (0)