Skip to content

Migrate "test/unit/test_providers_kms_master_key_provider.py" from unittest to pytest #122

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
merged 6 commits into from
Dec 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions test/unit/test_providers_kms_master_key_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Unit test suite from aws_encryption_sdk.key_providers.kms.KMSMasterKeyProvider"""
import unittest

import botocore.client
import pytest
import six
from mock import ANY, MagicMock, call, patch, sentinel

from aws_encryption_sdk.exceptions import UnknownRegionError
Expand All @@ -32,8 +29,9 @@ def test_init_with_regionless_key_ids_and_region_names():
assert provider.master_key("alias/key_1").config.client.meta.region_name == region_names[0]


class TestKMSMasterKeyProvider(unittest.TestCase):
def setUp(self):
class TestKMSMasterKeyProvider(object):
@pytest.fixture(autouse=True)
def apply_fixtures(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #127 : need to run teardown actions.

self.mock_botocore_session_patcher = patch("aws_encryption_sdk.key_providers.kms.botocore.session.Session")
self.mock_botocore_session = self.mock_botocore_session_patcher.start()
self.mock_boto3_session_patcher = patch("aws_encryption_sdk.key_providers.kms.boto3.session.Session")
Expand All @@ -43,8 +41,8 @@ def setUp(self):
self.mock_boto3_client_instance = MagicMock()
self.mock_boto3_client_instance.__class__ = botocore.client.BaseClient
self.mock_boto3_session_instance.client.return_value = self.mock_boto3_client_instance

def tearDown(self):
yield
# Run tearDown
self.mock_botocore_session_patcher.stop()
self.mock_boto3_session_patcher.stop()

Expand Down Expand Up @@ -130,10 +128,9 @@ def test_client_no_region_name_with_default(self, mock_add_client):

def test_client_no_region_name_without_default(self):
test = KMSMasterKeyProvider()
with six.assertRaisesRegex(
self, UnknownRegionError, "No default region found and no region determinable from key id: *"
):
with pytest.raises(UnknownRegionError) as excinfo:
test._client("")
excinfo.match("No default region found and no region determinable from key id: *")

@patch("aws_encryption_sdk.key_providers.kms.KMSMasterKeyProvider._client")
def test_new_master_key(self, mock_client):
Expand Down