-
Notifications
You must be signed in to change notification settings - Fork 86
Migrate "test/unit/test_providers_base_master_key.py" from unittest to pytest #119
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
mattsb42-aws
merged 4 commits into
aws:master
from
ansanper:unit/test_providers_base_master_key.py
Dec 17, 2018
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9eef35e
Migrate unit/test_defaults.py from unittest to pytest
32cdf5b
Migrate unit/test_providers_base_master_key.py from unittest to pytest
b5808b7
Removed one test from previous commit
88b1d82
Removed unused import and added yield and tearDown to apply_fixtures …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ | |
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
"""Test suite for aws_encryption_sdk.key_providers.base.MasterKey""" | ||
import unittest | ||
|
||
import attr | ||
import pytest | ||
import six | ||
|
@@ -63,8 +61,9 @@ class FakeMasterKey(MockMasterKey): | |
excinfo.match(r'MasterKey config classes must have a "provider_id" attribute defined.') | ||
|
||
|
||
class TestMasterKey(unittest.TestCase): | ||
def setUp(self): | ||
class TestMasterKey(object): | ||
@pytest.fixture(autouse=True) | ||
def apply_fixture(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #127 : need to run teardown actions. |
||
self.mock_data_key_len_check_patcher = patch("aws_encryption_sdk.internal.utils.source_data_key_length_check") | ||
self.mock_data_key_len_check = self.mock_data_key_len_check_patcher.start() | ||
|
||
|
@@ -85,8 +84,9 @@ def _encrypt_data_key(self, data_key, algorithm, encryption_context): | |
def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context): | ||
pass | ||
|
||
with six.assertRaisesRegex(self, TypeError, "Can't instantiate abstract class TestMasterKey *"): | ||
with pytest.raises(TypeError) as excinfo: | ||
TestMasterKey() | ||
excinfo.match("Can't instantiate abstract class TestMasterKey *") | ||
|
||
def test_generate_data_key_enforcement(self): | ||
class TestMasterKey(MasterKey): | ||
|
@@ -98,8 +98,9 @@ def _encrypt_data_key(self, data_key, algorithm, encryption_context): | |
def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context): | ||
pass | ||
|
||
with six.assertRaisesRegex(self, TypeError, "Can't instantiate abstract class TestMasterKey *"): | ||
with pytest.raises(TypeError) as excinfo: | ||
TestMasterKey() | ||
excinfo.match("Can't instantiate abstract class TestMasterKey *") | ||
|
||
def test_encrypt_data_key_enforcement(self): | ||
class TestMasterKey(MasterKey): | ||
|
@@ -111,8 +112,9 @@ def _generate_data_key(self, algorithm, encryption_context): | |
def _decrypt_data_key(self, encrypted_data_key, algorithm, encryption_context): | ||
pass | ||
|
||
with six.assertRaisesRegex(self, TypeError, "Can't instantiate abstract class TestMasterKey *"): | ||
with pytest.raises(TypeError) as excinfo: | ||
TestMasterKey() | ||
excinfo.match("Can't instantiate abstract class TestMasterKey *") | ||
|
||
def test_decrypt_data_key_enforcement(self): | ||
class TestMasterKey(MasterKey): | ||
|
@@ -124,8 +126,9 @@ def _generate_data_key(self, algorithm, encryption_context): | |
def _encrypt_data_key(self, data_key, algorithm, encryption_context): | ||
pass | ||
|
||
with six.assertRaisesRegex(self, TypeError, "Can't instantiate abstract class TestMasterKey *"): | ||
with pytest.raises(TypeError) as excinfo: | ||
TestMasterKey() | ||
excinfo.match("Can't instantiate abstract class TestMasterKey *") | ||
|
||
def test_new(self): | ||
mock_master_key = MockMasterKey( | ||
|
@@ -142,10 +145,9 @@ def test_new_conf_mismatch(self): | |
mock_config = MagicMock() | ||
mock_config.__class__ = MockMasterKeyConfig | ||
mock_config.provider_id = sentinel.mismatched_provider_id | ||
with six.assertRaisesRegex( | ||
self, ConfigMismatchError, "Config provider_id does not match MasterKey provider_id: *" | ||
): | ||
with pytest.raises(ConfigMismatchError) as excinfo: | ||
MockMasterKey(config=mock_config) | ||
excinfo.match("Config provider_id does not match MasterKey provider_id: *") | ||
|
||
def test_owns_data_key_owned(self): | ||
mock_master_key = MockMasterKey( | ||
|
@@ -220,8 +222,9 @@ def test_new_master_key_invalid(self): | |
mock_encrypted_data_key=sentinel.encrypted_data_key, | ||
mock_decrypted_data_key=sentinel.decrypted_data_key, | ||
) | ||
with six.assertRaisesRegex(self, InvalidKeyIdError, "MasterKeys can only provide themselves. *"): | ||
with pytest.raises(InvalidKeyIdError) as excinfo: | ||
mock_master_key._new_master_key(sentinel.another_key_id) | ||
excinfo.match("MasterKeys can only provide themselves. *") | ||
|
||
def test_key_check_valid(self): | ||
mock_master_key = MockMasterKey( | ||
|
@@ -243,8 +246,9 @@ def test_key_check_invalid(self): | |
) | ||
mock_data_key = MagicMock() | ||
mock_data_key.key_provider = sentinel.another_key_provider | ||
with six.assertRaisesRegex(self, IncorrectMasterKeyError, "Provided data key provider *"): | ||
with pytest.raises(IncorrectMasterKeyError) as excinfo: | ||
mock_master_key._key_check(mock_data_key) | ||
excinfo.match("Provided data key provider *") | ||
|
||
def test_generate_data_key(self): | ||
mock_master_key = MockMasterKey( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove the now-unused import