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

@ -5,8 +5,8 @@ from datetime import datetime, timedelta
import boto3
from botocore.exceptions import ClientError
from nose import SkipTest
from nose.tools import assert_raises
from unittest import SkipTest
import pytest
from moto import mock_s3
from moto.config import mock_config
@ -20,7 +20,7 @@ def test_put_configuration_recorder():
client = boto3.client("config", region_name="us-west-2")
# Try without a name supplied:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_recorder(ConfigurationRecorder={"roleARN": "somearn"})
assert (
ce.exception.response["Error"]["Code"]
@ -29,7 +29,7 @@ def test_put_configuration_recorder():
assert "is not valid, blank string." in ce.exception.response["Error"]["Message"]
# Try with a really long name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_recorder(
ConfigurationRecorder={"name": "a" * 257, "roleARN": "somearn"}
)
@ -68,7 +68,7 @@ def test_put_configuration_recorder():
]
for bg in bad_groups:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_recorder(
ConfigurationRecorder={
"name": "default",
@ -85,7 +85,7 @@ def test_put_configuration_recorder():
)
# With an invalid Resource Type:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_recorder(
ConfigurationRecorder={
"name": "default",
@ -166,7 +166,7 @@ def test_put_configuration_recorder():
assert not result[0]["recordingGroup"].get("resourceTypes")
# Can currently only have exactly 1 Config Recorder in an account/region:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_recorder(
ConfigurationRecorder={
"name": "someotherrecorder",
@ -192,7 +192,7 @@ def test_put_configuration_aggregator():
client = boto3.client("config", region_name="us-west-2")
# With too many aggregation sources:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -213,7 +213,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# With an invalid region config (no regions defined):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -229,7 +229,7 @@ def test_put_configuration_aggregator():
)
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
OrganizationAggregationSource={
@ -243,7 +243,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
# With both region flags defined:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -260,7 +260,7 @@ def test_put_configuration_aggregator():
)
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
OrganizationAggregationSource={
@ -276,7 +276,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
# Name too long:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="a" * 257,
AccountAggregationSources=[
@ -287,7 +287,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Too many tags (>50):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -304,7 +304,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Tag key is too big (>128 chars):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -319,7 +319,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Tag value is too big (>256 chars):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -334,7 +334,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Duplicate Tags:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -346,7 +346,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "InvalidInput"
# Invalid characters in the tag key:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -361,7 +361,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# If it contains both the AccountAggregationSources and the OrganizationAggregationSource
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(
ConfigurationAggregatorName="testing",
AccountAggregationSources=[
@ -379,7 +379,7 @@ def test_put_configuration_aggregator():
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
# If it contains neither:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_configuration_aggregator(ConfigurationAggregatorName="testing")
assert (
"AccountAggregationSource or the OrganizationAggregationSource"
@ -466,7 +466,7 @@ def test_describe_configuration_aggregators():
)
# Describe with an incorrect name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_configuration_aggregators(
ConfigurationAggregatorNames=["DoesNotExist"]
)
@ -480,7 +480,7 @@ def test_describe_configuration_aggregators():
)
# Error describe with more than 1 item in the list:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_configuration_aggregators(
ConfigurationAggregatorNames=["testing0", "DoesNotExist"]
)
@ -551,7 +551,7 @@ def test_describe_configuration_aggregators():
)
# Test with an invalid filter:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_configuration_aggregators(NextToken="WRONG")
assert (
"The nextToken provided is invalid" == ce.exception.response["Error"]["Message"]
@ -564,7 +564,7 @@ def test_put_aggregation_authorization():
client = boto3.client("config", region_name="us-west-2")
# Too many tags (>50):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_aggregation_authorization(
AuthorizedAccountId="012345678910",
AuthorizedAwsRegion="us-west-2",
@ -579,7 +579,7 @@ def test_put_aggregation_authorization():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Tag key is too big (>128 chars):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_aggregation_authorization(
AuthorizedAccountId="012345678910",
AuthorizedAwsRegion="us-west-2",
@ -592,7 +592,7 @@ def test_put_aggregation_authorization():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Tag value is too big (>256 chars):
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_aggregation_authorization(
AuthorizedAccountId="012345678910",
AuthorizedAwsRegion="us-west-2",
@ -605,7 +605,7 @@ def test_put_aggregation_authorization():
assert ce.exception.response["Error"]["Code"] == "ValidationException"
# Duplicate Tags:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_aggregation_authorization(
AuthorizedAccountId="012345678910",
AuthorizedAwsRegion="us-west-2",
@ -615,7 +615,7 @@ def test_put_aggregation_authorization():
assert ce.exception.response["Error"]["Code"] == "InvalidInput"
# Invalid characters in the tag key:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_aggregation_authorization(
AuthorizedAccountId="012345678910",
AuthorizedAwsRegion="us-west-2",
@ -708,7 +708,7 @@ def test_describe_aggregation_authorizations():
] == ["{}".format(str(x) * 12) for x in range(8, 10)]
# Test with an invalid filter:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_aggregation_authorizations(NextToken="WRONG")
assert (
"The nextToken provided is invalid" == ce.exception.response["Error"]["Message"]
@ -751,7 +751,7 @@ def test_delete_configuration_aggregator():
client.delete_configuration_aggregator(ConfigurationAggregatorName="testing")
# And again to confirm that it's deleted:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.delete_configuration_aggregator(ConfigurationAggregatorName="testing")
assert (
"The configuration aggregator does not exist."
@ -796,7 +796,7 @@ def test_describe_configurations():
)
# Specify an incorrect name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_configuration_recorders(ConfigurationRecorderNames=["wrong"])
assert (
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
@ -804,7 +804,7 @@ def test_describe_configurations():
assert "wrong" in ce.exception.response["Error"]["Message"]
# And with both a good and wrong name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_configuration_recorders(
ConfigurationRecorderNames=["testrecorder", "wrong"]
)
@ -819,7 +819,7 @@ def test_delivery_channels():
client = boto3.client("config", region_name="us-west-2")
# Try without a config recorder:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(DeliveryChannel={})
assert (
ce.exception.response["Error"]["Code"]
@ -845,7 +845,7 @@ def test_delivery_channels():
)
# Try without a name supplied:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(DeliveryChannel={})
assert (
ce.exception.response["Error"]["Code"] == "InvalidDeliveryChannelNameException"
@ -853,7 +853,7 @@ def test_delivery_channels():
assert "is not valid, blank string." in ce.exception.response["Error"]["Message"]
# Try with a really long name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(DeliveryChannel={"name": "a" * 257})
assert ce.exception.response["Error"]["Code"] == "ValidationException"
assert (
@ -862,7 +862,7 @@ def test_delivery_channels():
)
# Without specifying a bucket name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(DeliveryChannel={"name": "testchannel"})
assert ce.exception.response["Error"]["Code"] == "NoSuchBucketException"
assert (
@ -870,7 +870,7 @@ def test_delivery_channels():
== "Cannot find a S3 bucket with an empty bucket name."
)
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(
DeliveryChannel={"name": "testchannel", "s3BucketName": ""}
)
@ -881,7 +881,7 @@ def test_delivery_channels():
)
# With an empty string for the S3 key prefix:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(
DeliveryChannel={
"name": "testchannel",
@ -893,7 +893,7 @@ def test_delivery_channels():
assert "empty s3 key prefix." in ce.exception.response["Error"]["Message"]
# With an empty string for the SNS ARN:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(
DeliveryChannel={
"name": "testchannel",
@ -905,7 +905,7 @@ def test_delivery_channels():
assert "The sns topic arn" in ce.exception.response["Error"]["Message"]
# With an invalid delivery frequency:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(
DeliveryChannel={
"name": "testchannel",
@ -950,7 +950,7 @@ def test_delivery_channels():
)
# Can only have 1:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_delivery_channel(
DeliveryChannel={"name": "testchannel2", "s3BucketName": "somebucket"}
)
@ -1015,13 +1015,13 @@ def test_describe_delivery_channels():
)
# Specify an incorrect name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_delivery_channels(DeliveryChannelNames=["wrong"])
assert ce.exception.response["Error"]["Code"] == "NoSuchDeliveryChannelException"
assert "wrong" in ce.exception.response["Error"]["Message"]
# And with both a good and wrong name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_delivery_channels(DeliveryChannelNames=["testchannel", "wrong"])
assert ce.exception.response["Error"]["Code"] == "NoSuchDeliveryChannelException"
assert "wrong" in ce.exception.response["Error"]["Message"]
@ -1032,7 +1032,7 @@ def test_start_configuration_recorder():
client = boto3.client("config", region_name="us-west-2")
# Without a config recorder:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.start_configuration_recorder(ConfigurationRecorderName="testrecorder")
assert (
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
@ -1052,7 +1052,7 @@ def test_start_configuration_recorder():
)
# Without a delivery channel:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.start_configuration_recorder(ConfigurationRecorderName="testrecorder")
assert (
ce.exception.response["Error"]["Code"] == "NoAvailableDeliveryChannelException"
@ -1090,7 +1090,7 @@ def test_stop_configuration_recorder():
client = boto3.client("config", region_name="us-west-2")
# Without a config recorder:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.stop_configuration_recorder(ConfigurationRecorderName="testrecorder")
assert (
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
@ -1180,7 +1180,7 @@ def test_describe_configuration_recorder_status():
assert not result[0]["recording"]
# Invalid name:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.describe_configuration_recorder_status(
ConfigurationRecorderNames=["testrecorder", "wrong"]
)
@ -1211,7 +1211,7 @@ def test_delete_configuration_recorder():
client.delete_configuration_recorder(ConfigurationRecorderName="testrecorder")
# Try again -- it should be deleted:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.delete_configuration_recorder(ConfigurationRecorderName="testrecorder")
assert (
ce.exception.response["Error"]["Code"] == "NoSuchConfigurationRecorderException"
@ -1240,7 +1240,7 @@ def test_delete_delivery_channel():
client.start_configuration_recorder(ConfigurationRecorderName="testrecorder")
# With the recorder enabled:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.delete_delivery_channel(DeliveryChannelName="testchannel")
assert (
ce.exception.response["Error"]["Code"]
@ -1258,7 +1258,7 @@ def test_delete_delivery_channel():
client.delete_delivery_channel(DeliveryChannelName="testchannel")
# Verify:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.delete_delivery_channel(DeliveryChannelName="testchannel")
assert ce.exception.response["Error"]["Code"] == "NoSuchDeliveryChannelException"
@ -1341,12 +1341,12 @@ def test_list_discovered_resource():
)["resourceIdentifiers"]
# Test with an invalid page num > 100:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.list_discovered_resources(resourceType="AWS::S3::Bucket", limit=101)
assert "101" in ce.exception.response["Error"]["Message"]
# Test by supplying both resourceName and also resourceIds:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.list_discovered_resources(
resourceType="AWS::S3::Bucket",
resourceName="whats",
@ -1359,7 +1359,7 @@ def test_list_discovered_resource():
# More than 20 resourceIds:
resource_ids = ["{}".format(x) for x in range(0, 21)]
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.list_discovered_resources(
resourceType="AWS::S3::Bucket", resourceIds=resource_ids
)
@ -1378,7 +1378,7 @@ def test_list_aggregate_discovered_resource():
client = boto3.client("config", region_name="us-west-2")
# Without an aggregator:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.list_aggregate_discovered_resources(
ConfigurationAggregatorName="lolno", ResourceType="AWS::S3::Bucket"
)
@ -1504,7 +1504,7 @@ def test_list_aggregate_discovered_resource():
)["ResourceIdentifiers"]
# Test with an invalid page num > 100:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.list_aggregate_discovered_resources(
ConfigurationAggregatorName="testing",
ResourceType="AWS::S3::Bucket",
@ -1522,7 +1522,7 @@ def test_get_resource_config_history():
client = boto3.client("config", region_name="us-west-2")
# With an invalid resource type:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.get_resource_config_history(
resourceType="NOT::A::RESOURCE", resourceId="notcreatedyet"
)
@ -1533,7 +1533,7 @@ def test_get_resource_config_history():
}
# With nothing created yet:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.get_resource_config_history(
resourceType="AWS::S3::Bucket", resourceId="notcreatedyet"
)
@ -1565,7 +1565,7 @@ def test_get_resource_config_history():
Bucket="eu-bucket",
CreateBucketConfiguration={"LocationConstraint": "eu-west-1"},
)
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.get_resource_config_history(
resourceType="AWS::S3::Bucket", resourceId="eu-bucket"
)
@ -1581,7 +1581,7 @@ def test_batch_get_resource_config():
client = boto3.client("config", region_name="us-west-2")
# With more than 100 resourceKeys:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.batch_get_resource_config(
resourceKeys=[
{"resourceType": "AWS::S3::Bucket", "resourceId": "someBucket"}
@ -1653,7 +1653,7 @@ def test_batch_get_aggregate_resource_config():
"ResourceType": "NOT::A::RESOURCE",
"ResourceId": "nope",
}
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.batch_get_aggregate_resource_config(
ConfigurationAggregatorName="lolno", ResourceIdentifiers=[bad_ri]
)
@ -1673,7 +1673,7 @@ def test_batch_get_aggregate_resource_config():
)
# With more than 100 items:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.batch_get_aggregate_resource_config(
ConfigurationAggregatorName="testing", ResourceIdentifiers=[bad_ri] * 101
)
@ -1814,7 +1814,7 @@ def test_put_evaluations():
client = boto3.client("config", region_name="us-west-2")
# Try without Evaluations supplied:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_evaluations(Evaluations=[], ResultToken="test", TestMode=True)
assert ce.exception.response["Error"]["Code"] == "InvalidParameterValueException"
assert (
@ -1823,7 +1823,7 @@ def test_put_evaluations():
)
# Try without a ResultToken supplied:
with assert_raises(ClientError) as ce:
with pytest.raises(ClientError) as ce:
client.put_evaluations(
Evaluations=[
{
@ -1842,7 +1842,7 @@ def test_put_evaluations():
raise SkipTest("Does not work in server mode due to error in Workzeug")
else:
# Try without TestMode supplied:
with assert_raises(NotImplementedError):
with pytest.raises(NotImplementedError):
client.put_evaluations(
Evaluations=[
{
@ -1913,7 +1913,7 @@ def test_put_organization_conformance_pack_errors():
client = boto3.client("config", region_name="us-east-1")
# when
with assert_raises(ClientError) as e:
with pytest.raises(ClientError) as e:
client.put_organization_conformance_pack(
DeliveryS3Bucket="awsconfigconforms-test-bucket",
OrganizationConformancePackName="test-pack",
@ -1927,7 +1927,7 @@ def test_put_organization_conformance_pack_errors():
ex.response["Error"]["Message"].should.equal("Template body is invalid")
# when
with assert_raises(ClientError) as e:
with pytest.raises(ClientError) as e:
client.put_organization_conformance_pack(
DeliveryS3Bucket="awsconfigconforms-test-bucket",
OrganizationConformancePackName="test-pack",
@ -1979,7 +1979,7 @@ def test_describe_organization_conformance_packs_errors():
client = boto3.client("config", region_name="us-east-1")
# when
with assert_raises(ClientError) as e:
with pytest.raises(ClientError) as e:
client.describe_organization_conformance_packs(
OrganizationConformancePackNames=["not-existing"]
)
@ -2055,7 +2055,7 @@ def test_describe_organization_conformance_pack_statuses_errors():
client = boto3.client("config", region_name="us-east-1")
# when
with assert_raises(ClientError) as e:
with pytest.raises(ClientError) as e:
client.describe_organization_conformance_pack_statuses(
OrganizationConformancePackNames=["not-existing"]
)
@ -2127,7 +2127,7 @@ def test_get_organization_conformance_pack_detailed_status_errors():
client = boto3.client("config", region_name="us-east-1")
# when
with assert_raises(ClientError) as e:
with pytest.raises(ClientError) as e:
client.get_organization_conformance_pack_detailed_status(
OrganizationConformancePackName="not-existing"
)
@ -2171,7 +2171,7 @@ def test_delete_organization_conformance_pack_errors():
client = boto3.client("config", region_name="us-east-1")
# when
with assert_raises(ClientError) as e:
with pytest.raises(ClientError) as e:
client.delete_organization_conformance_pack(
OrganizationConformancePackName="not-existing"
)