10
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
11
# ANY KIND, either express or implied. See the License for the specific
12
12
# language governing permissions and limitations under the License.
13
+ """Helper tools for use in tests."""
13
14
from __future__ import division
14
- import copy
15
+
15
16
from collections import defaultdict
17
+ import copy
16
18
from decimal import Decimal
17
19
import itertools
18
20
28
30
from dynamodb_encryption_sdk .material_providers .static import StaticCryptographicMaterialsProvider
29
31
from dynamodb_encryption_sdk .material_providers .wrapped import WrappedCryptographicMaterialsProvider
30
32
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
32
34
33
35
_DELEGATED_KEY_CACHE = defaultdict (lambda : defaultdict (dict ))
34
36
TEST_TABLE_NAME = 'my_table'
39
41
},
40
42
'sort_attribute' : {
41
43
'type' : 'N' ,
42
- 'value' : Decimal ('99.233' )
44
+ 'value' : Decimal ('99.233' )
43
45
}
44
46
}
45
47
TEST_KEY = {name : value ['value' ] for name , value in TEST_INDEX .items ()}
51
53
},
52
54
'sort_attribute' : {
53
55
'type' : 'N' ,
54
- 'value' : Decimal ('99.233' )
56
+ 'value' : Decimal ('99.233' )
55
57
}
56
58
},
57
59
{
61
63
},
62
64
'sort_attribute' : {
63
65
'type' : 'N' ,
64
- 'value' : Decimal ('92986745' )
66
+ 'value' : Decimal ('92986745' )
65
67
}
66
68
},
67
69
{
71
73
},
72
74
'sort_attribute' : {
73
75
'type' : 'N' ,
74
- 'value' : Decimal ('2231.0001' )
76
+ 'value' : Decimal ('2231.0001' )
75
77
}
76
78
},
77
79
{
81
83
},
82
84
'sort_attribute' : {
83
85
'type' : 'N' ,
84
- 'value' : Decimal ('732342' )
86
+ 'value' : Decimal ('732342' )
85
87
}
86
88
}
87
89
]
@@ -301,7 +303,7 @@ def set_parametrized_cmp(metafunc):
301
303
302
304
303
305
def set_parametrized_actions (metafunc ):
304
- """Set parametrized values for attribute actions"""
306
+ """Set parametrized values for attribute actions. """
305
307
for name , actions in _ACTIONS .items ():
306
308
if name in metafunc .fixturenames :
307
309
metafunc .parametrize (name , actions )
@@ -360,13 +362,13 @@ def check_encrypted_item(plaintext_item, ciphertext_item, attribute_actions):
360
362
361
363
362
364
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 ]
370
372
371
373
372
374
def _nop_transformer (item ):
@@ -401,7 +403,7 @@ def cycle_batch_item_check(
401
403
write_transformer = _nop_transformer ,
402
404
read_transformer = _nop_transformer
403
405
):
404
- """Common logic for cycling batch items ."""
406
+ """Check that cycling (plaintext->encrypted->decrypted) item batch has the expected results ."""
405
407
check_attribute_actions = initial_actions .copy ()
406
408
check_attribute_actions .set_index_keys (* list (TEST_KEY .keys ()))
407
409
items = []
@@ -410,7 +412,7 @@ def cycle_batch_item_check(
410
412
_item .update (key )
411
413
items .append (write_transformer (_item ))
412
414
413
- _put_result = encrypted .batch_write_item (
415
+ _put_result = encrypted .batch_write_item ( # noqa
414
416
RequestItems = {
415
417
TEST_TABLE_NAME : [
416
418
{'PutRequest' : {'Item' : _item }}
@@ -447,7 +449,7 @@ def cycle_batch_item_check(
447
449
transformer = read_transformer
448
450
)
449
451
450
- _delete_result = encrypted .batch_write_item (
452
+ _delete_result = encrypted .batch_write_item ( # noqa
451
453
RequestItems = {
452
454
TEST_TABLE_NAME : [
453
455
{'DeleteRequest' : {'Key' : _key }}
@@ -461,7 +463,7 @@ def cycle_batch_item_check(
461
463
462
464
463
465
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 ."""
465
467
ciphertext_item = encrypt_python_item (plaintext_item , crypto_config )
466
468
467
469
check_encrypted_item (plaintext_item , ciphertext_item , crypto_config .attribute_actions )
0 commit comments