Port test suite from nose to pytest.

This just eliminates all errors on the tests collection. Elimination of
failures is left to the next commit.
This commit is contained in:
Matěj Cepl 2020-10-06 07:54:49 +02:00
commit 77dc60ea97
146 changed files with 1172 additions and 1277 deletions

View file

@ -0,0 +1 @@
# This file is intentionally left blank.

View file

@ -9,7 +9,7 @@ import six
import sure # noqa
from boto.exception import JSONResponseError
from boto.kms.exceptions import AlreadyExistsException, NotFoundException
from nose.tools import assert_raises
import pytest
from parameterized import parameterized
from moto.core.exceptions import JsonRESTError
from moto.kms.models import KmsBackend
@ -192,10 +192,10 @@ def test_generate_data_key():
response = conn.generate_data_key(key_id=key_id, number_of_bytes=32)
# CiphertextBlob must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(response["CiphertextBlob"], validate=True)
# Plaintext must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(response["Plaintext"], validate=True)
response["KeyId"].should.equal(key_arn)
@ -364,7 +364,7 @@ def test__create_alias__raises_if_reserved_alias():
]
for alias_name in reserved_aliases:
with assert_raises(JSONResponseError) as err:
with pytest.raises(JSONResponseError) as err:
kms.create_alias(alias_name, key_id)
ex = err.exception
@ -392,7 +392,7 @@ def test__create_alias__raises_if_wrong_prefix():
create_resp = kms.create_key()
key_id = create_resp["KeyMetadata"]["KeyId"]
with assert_raises(JSONResponseError) as err:
with pytest.raises(JSONResponseError) as err:
kms.create_alias("wrongprefix/my-alias", key_id)
ex = err.exception
@ -415,7 +415,7 @@ def test__create_alias__raises_if_duplicate():
kms.create_alias(alias, key_id)
with assert_raises(AlreadyExistsException) as err:
with pytest.raises(AlreadyExistsException) as err:
kms.create_alias(alias, key_id)
ex = err.exception
@ -450,7 +450,7 @@ def test__create_alias__raises_if_alias_has_restricted_characters():
]
for alias_name in alias_names_with_restricted_characters:
with assert_raises(JSONResponseError) as err:
with pytest.raises(JSONResponseError) as err:
kms.create_alias(alias_name, key_id)
ex = err.exception
ex.body["__type"].should.equal("ValidationException")
@ -480,7 +480,7 @@ def test__create_alias__raises_if_alias_has_colon_character():
alias_names_with_restricted_characters = ["alias/my:alias"]
for alias_name in alias_names_with_restricted_characters:
with assert_raises(JSONResponseError) as err:
with pytest.raises(JSONResponseError) as err:
kms.create_alias(alias_name, key_id)
ex = err.exception
ex.body["__type"].should.equal("ValidationException")
@ -514,7 +514,7 @@ def test__create_alias__raises_if_target_key_id_is_existing_alias():
kms.create_alias(alias, key_id)
with assert_raises(JSONResponseError) as err:
with pytest.raises(JSONResponseError) as err:
kms.create_alias(alias, alias)
ex = err.exception
@ -554,7 +554,7 @@ def test__delete_alias():
def test__delete_alias__raises_if_wrong_prefix():
kms = boto.connect_kms()
with assert_raises(JSONResponseError) as err:
with pytest.raises(JSONResponseError) as err:
kms.delete_alias("wrongprefix/my-alias")
ex = err.exception
@ -572,7 +572,7 @@ def test__delete_alias__raises_if_alias_is_not_found():
kms = boto.kms.connect_to_region(region)
alias_name = "alias/unexisting-alias"
with assert_raises(NotFoundException) as err:
with pytest.raises(NotFoundException) as err:
kms.delete_alias(alias_name)
expected_message_match = r"Alias arn:aws:kms:{region}:[0-9]{{12}}:{alias_name} is not found.".format(

View file

@ -10,7 +10,7 @@ import botocore.exceptions
import six
import sure # noqa
from freezegun import freeze_time
from nose.tools import assert_raises
import pytest
from parameterized import parameterized
from moto import mock_kms
@ -132,7 +132,7 @@ def test_describe_key_via_alias_invalid_alias(key_id):
client = boto3.client("kms", region_name="us-east-1")
client.create_key(Description="key")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.describe_key(KeyId=key_id)
@ -147,10 +147,10 @@ def test_generate_data_key():
response = kms.generate_data_key(KeyId=key_id, NumberOfBytes=32)
# CiphertextBlob must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(response["CiphertextBlob"], validate=True)
# Plaintext must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(response["Plaintext"], validate=True)
response["KeyId"].should.equal(key_arn)
@ -169,7 +169,7 @@ def test_encrypt(plaintext):
response["CiphertextBlob"].should_not.equal(plaintext)
# CiphertextBlob must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(response["CiphertextBlob"], validate=True)
response["KeyId"].should.equal(key_arn)
@ -188,13 +188,13 @@ def test_decrypt(plaintext):
client.create_key(Description="key")
# CiphertextBlob must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(encrypt_response["CiphertextBlob"], validate=True)
decrypt_response = client.decrypt(CiphertextBlob=encrypt_response["CiphertextBlob"])
# Plaintext must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(decrypt_response["Plaintext"], validate=True)
decrypt_response["Plaintext"].should.equal(_get_encoded_value(plaintext))
@ -216,7 +216,7 @@ def test_decrypt(plaintext):
def test_invalid_key_ids(key_id):
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.generate_data_key(KeyId=key_id, NumberOfBytes=5)
@ -403,7 +403,7 @@ def test_generate_data_key_invalid_size_params(kwargs):
client = boto3.client("kms", region_name="us-east-1")
key = client.create_key(Description="generate-data-key-size")
with assert_raises(
with pytest.raises(
(botocore.exceptions.ClientError, botocore.exceptions.ParamValidationError)
) as err:
client.generate_data_key(KeyId=key["KeyMetadata"]["KeyId"], **kwargs)
@ -423,7 +423,7 @@ def test_generate_data_key_invalid_size_params(kwargs):
def test_generate_data_key_invalid_key(key_id):
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.generate_data_key(KeyId=key_id, KeySpec="AES_256")
@ -485,7 +485,7 @@ def test_re_encrypt_decrypt(plaintext):
)
# CiphertextBlob must NOT be base64-encoded
with assert_raises(Exception):
with pytest.raises(Exception):
base64.b64decode(re_encrypt_response["CiphertextBlob"], validate=True)
re_encrypt_response["SourceKeyId"].should.equal(key_1_arn)
@ -517,7 +517,7 @@ def test_re_encrypt_to_invalid_destination():
encrypt_response = client.encrypt(KeyId=key_id, Plaintext=b"some plaintext")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.re_encrypt(
CiphertextBlob=encrypt_response["CiphertextBlob"],
DestinationKeyId="alias/DoesNotExist",
@ -548,7 +548,7 @@ def test_generate_random(number_of_bytes):
def test_generate_random_invalid_number_of_bytes(number_of_bytes, error_type):
client = boto3.client("kms", region_name="us-west-2")
with assert_raises(error_type):
with pytest.raises(error_type):
client.generate_random(NumberOfBytes=number_of_bytes)
@ -556,7 +556,7 @@ def test_generate_random_invalid_number_of_bytes(number_of_bytes, error_type):
def test_enable_key_rotation_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.enable_key_rotation(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -564,7 +564,7 @@ def test_enable_key_rotation_key_not_found():
def test_disable_key_rotation_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.disable_key_rotation(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -572,7 +572,7 @@ def test_disable_key_rotation_key_not_found():
def test_enable_key_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.enable_key(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -580,7 +580,7 @@ def test_enable_key_key_not_found():
def test_disable_key_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.disable_key(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -588,7 +588,7 @@ def test_disable_key_key_not_found():
def test_cancel_key_deletion_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.cancel_key_deletion(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -596,7 +596,7 @@ def test_cancel_key_deletion_key_not_found():
def test_schedule_key_deletion_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.schedule_key_deletion(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -604,7 +604,7 @@ def test_schedule_key_deletion_key_not_found():
def test_get_key_rotation_status_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.get_key_rotation_status(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -612,7 +612,7 @@ def test_get_key_rotation_status_key_not_found():
def test_get_key_policy_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.get_key_policy(
KeyId="12366f9b-1230-123d-123e-123e6ae60c02", PolicyName="default"
)
@ -622,7 +622,7 @@ def test_get_key_policy_key_not_found():
def test_list_key_policies_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.list_key_policies(KeyId="12366f9b-1230-123d-123e-123e6ae60c02")
@ -630,7 +630,7 @@ def test_list_key_policies_key_not_found():
def test_put_key_policy_key_not_found():
client = boto3.client("kms", region_name="us-east-1")
with assert_raises(client.exceptions.NotFoundException):
with pytest.raises(client.exceptions.NotFoundException):
client.put_key_policy(
KeyId="00000000-0000-0000-0000-000000000000",
PolicyName="default",

View file

@ -1,7 +1,7 @@
from __future__ import unicode_literals
import sure # noqa
from nose.tools import assert_raises
import pytest
from parameterized import parameterized
from moto.kms.exceptions import (
@ -123,7 +123,7 @@ def test_encrypt_decrypt_cycle(encryption_context):
def test_encrypt_unknown_key_id():
with assert_raises(NotFoundException):
with pytest.raises(NotFoundException):
encrypt(
master_keys={},
key_id="anything",
@ -136,7 +136,7 @@ def test_decrypt_invalid_ciphertext_format():
master_key = Key("nop", "nop", "nop", "nop", "nop")
master_key_map = {master_key.id: master_key}
with assert_raises(InvalidCiphertextException):
with pytest.raises(InvalidCiphertextException):
decrypt(master_keys=master_key_map, ciphertext_blob=b"", encryption_context={})
@ -148,7 +148,7 @@ def test_decrypt_unknwown_key_id():
b"some ciphertext"
)
with assert_raises(AccessDeniedException):
with pytest.raises(AccessDeniedException):
decrypt(master_keys={}, ciphertext_blob=ciphertext_blob, encryption_context={})
@ -161,7 +161,7 @@ def test_decrypt_invalid_ciphertext():
b"some ciphertext"
)
with assert_raises(InvalidCiphertextException):
with pytest.raises(InvalidCiphertextException):
decrypt(
master_keys=master_key_map,
ciphertext_blob=ciphertext_blob,
@ -181,7 +181,7 @@ def test_decrypt_invalid_encryption_context():
encryption_context={"some": "encryption", "context": "here"},
)
with assert_raises(InvalidCiphertextException):
with pytest.raises(InvalidCiphertextException):
decrypt(
master_keys=master_key_map,
ciphertext_blob=ciphertext_blob,