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
13
"""Test suite for aws_encryption_sdk.key_providers.base.MasterKey"""
14
- import unittest
15
-
16
14
import attr
17
15
import pytest
18
16
import six
@@ -63,8 +61,9 @@ class FakeMasterKey(MockMasterKey):
63
61
excinfo .match (r'MasterKey config classes must have a "provider_id" attribute defined.' )
64
62
65
63
66
- class TestMasterKey (unittest .TestCase ):
67
- def setUp (self ):
64
+ class TestMasterKey (object ):
65
+ @pytest .fixture (autouse = True )
66
+ def apply_fixture (self ):
68
67
self .mock_data_key_len_check_patcher = patch ("aws_encryption_sdk.internal.utils.source_data_key_length_check" )
69
68
self .mock_data_key_len_check = self .mock_data_key_len_check_patcher .start ()
70
69
@@ -85,8 +84,9 @@ def _encrypt_data_key(self, data_key, algorithm, encryption_context):
85
84
def _decrypt_data_key (self , encrypted_data_key , algorithm , encryption_context ):
86
85
pass
87
86
88
- with six . assertRaisesRegex ( self , TypeError , "Can't instantiate abstract class TestMasterKey *" ) :
87
+ with pytest . raises ( TypeError ) as excinfo :
89
88
TestMasterKey ()
89
+ excinfo .match ("Can't instantiate abstract class TestMasterKey *" )
90
90
91
91
def test_generate_data_key_enforcement (self ):
92
92
class TestMasterKey (MasterKey ):
@@ -98,8 +98,9 @@ def _encrypt_data_key(self, data_key, algorithm, encryption_context):
98
98
def _decrypt_data_key (self , encrypted_data_key , algorithm , encryption_context ):
99
99
pass
100
100
101
- with six . assertRaisesRegex ( self , TypeError , "Can't instantiate abstract class TestMasterKey *" ) :
101
+ with pytest . raises ( TypeError ) as excinfo :
102
102
TestMasterKey ()
103
+ excinfo .match ("Can't instantiate abstract class TestMasterKey *" )
103
104
104
105
def test_encrypt_data_key_enforcement (self ):
105
106
class TestMasterKey (MasterKey ):
@@ -111,8 +112,9 @@ def _generate_data_key(self, algorithm, encryption_context):
111
112
def _decrypt_data_key (self , encrypted_data_key , algorithm , encryption_context ):
112
113
pass
113
114
114
- with six . assertRaisesRegex ( self , TypeError , "Can't instantiate abstract class TestMasterKey *" ) :
115
+ with pytest . raises ( TypeError ) as excinfo :
115
116
TestMasterKey ()
117
+ excinfo .match ("Can't instantiate abstract class TestMasterKey *" )
116
118
117
119
def test_decrypt_data_key_enforcement (self ):
118
120
class TestMasterKey (MasterKey ):
@@ -124,8 +126,9 @@ def _generate_data_key(self, algorithm, encryption_context):
124
126
def _encrypt_data_key (self , data_key , algorithm , encryption_context ):
125
127
pass
126
128
127
- with six . assertRaisesRegex ( self , TypeError , "Can't instantiate abstract class TestMasterKey *" ) :
129
+ with pytest . raises ( TypeError ) as excinfo :
128
130
TestMasterKey ()
131
+ excinfo .match ("Can't instantiate abstract class TestMasterKey *" )
129
132
130
133
def test_new (self ):
131
134
mock_master_key = MockMasterKey (
@@ -142,10 +145,9 @@ def test_new_conf_mismatch(self):
142
145
mock_config = MagicMock ()
143
146
mock_config .__class__ = MockMasterKeyConfig
144
147
mock_config .provider_id = sentinel .mismatched_provider_id
145
- with six .assertRaisesRegex (
146
- self , ConfigMismatchError , "Config provider_id does not match MasterKey provider_id: *"
147
- ):
148
+ with pytest .raises (ConfigMismatchError ) as excinfo :
148
149
MockMasterKey (config = mock_config )
150
+ excinfo .match ("Config provider_id does not match MasterKey provider_id: *" )
149
151
150
152
def test_owns_data_key_owned (self ):
151
153
mock_master_key = MockMasterKey (
@@ -220,8 +222,9 @@ def test_new_master_key_invalid(self):
220
222
mock_encrypted_data_key = sentinel .encrypted_data_key ,
221
223
mock_decrypted_data_key = sentinel .decrypted_data_key ,
222
224
)
223
- with six . assertRaisesRegex ( self , InvalidKeyIdError , "MasterKeys can only provide themselves. *" ) :
225
+ with pytest . raises ( InvalidKeyIdError ) as excinfo :
224
226
mock_master_key ._new_master_key (sentinel .another_key_id )
227
+ excinfo .match ("MasterKeys can only provide themselves. *" )
225
228
226
229
def test_key_check_valid (self ):
227
230
mock_master_key = MockMasterKey (
@@ -243,8 +246,9 @@ def test_key_check_invalid(self):
243
246
)
244
247
mock_data_key = MagicMock ()
245
248
mock_data_key .key_provider = sentinel .another_key_provider
246
- with six . assertRaisesRegex ( self , IncorrectMasterKeyError , "Provided data key provider *" ) :
249
+ with pytest . raises ( IncorrectMasterKeyError ) as excinfo :
247
250
mock_master_key ._key_check (mock_data_key )
251
+ excinfo .match ("Provided data key provider *" )
248
252
249
253
def test_generate_data_key (self ):
250
254
mock_master_key = MockMasterKey (
0 commit comments