Finish porting from nose to pytest.

This commit is contained in:
Matěj Cepl 2020-10-06 08:04:09 +02:00
commit ea489bce6c
72 changed files with 1289 additions and 1280 deletions

View file

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import copy
import json
# Ensure 'assert_raises' context manager support for Python 2.6
# Ensure 'pytest.raises' context manager support for Python 2.6
import pytest
import boto3
@ -23,9 +23,9 @@ def test_create_and_describe_security_group():
security_group = conn.create_security_group(
"test security group", "this is a test security group", dry_run=True
)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the CreateSecurityGroup operation: Request would have succeeded, but DryRun flag is set"
)
@ -41,9 +41,9 @@ def test_create_and_describe_security_group():
conn.create_security_group(
"test security group", "this is a test security group"
)
cm.exception.code.should.equal("InvalidGroup.Duplicate")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidGroup.Duplicate")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
all_groups = conn.get_all_security_groups()
# The default group gets created automatically
@ -58,9 +58,9 @@ def test_create_security_group_without_description_raises_error():
with pytest.raises(EC2ResponseError) as cm:
conn.create_security_group("test security group", "")
cm.exception.code.should.equal("MissingParameter")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("MissingParameter")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
@ -90,9 +90,9 @@ def test_create_and_describe_vpc_security_group():
conn.create_security_group(
"test security group", "this is a test security group", vpc_id
)
cm.exception.code.should.equal("InvalidGroup.Duplicate")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidGroup.Duplicate")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
all_groups = conn.get_all_security_groups(filters={"vpc_id": [vpc_id]})
@ -147,16 +147,16 @@ def test_deleting_security_groups():
# Deleting a group that doesn't exist should throw an error
with pytest.raises(EC2ResponseError) as cm:
conn.delete_security_group("foobar")
cm.exception.code.should.equal("InvalidGroup.NotFound")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidGroup.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
# Delete by name
with pytest.raises(EC2ResponseError) as ex:
conn.delete_security_group("test2", dry_run=True)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the DeleteSecurityGroup operation: Request would have succeeded, but DryRun flag is set"
)
@ -191,9 +191,9 @@ def test_authorize_ip_range_and_revoke():
cidr_ip="123.123.123.123/32",
dry_run=True,
)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the GrantSecurityGroupIngress operation: Request would have succeeded, but DryRun flag is set"
)
@ -214,9 +214,9 @@ def test_authorize_ip_range_and_revoke():
to_port="2222",
cidr_ip="123.123.123.122/32",
)
cm.exception.code.should.equal("InvalidPermission.NotFound")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidPermission.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
# Actually revoke
with pytest.raises(EC2ResponseError) as ex:
@ -227,9 +227,9 @@ def test_authorize_ip_range_and_revoke():
cidr_ip="123.123.123.123/32",
dry_run=True,
)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the RevokeSecurityGroupIngress operation: Request would have succeeded, but DryRun flag is set"
)
@ -254,9 +254,9 @@ def test_authorize_ip_range_and_revoke():
cidr_ip="123.123.123.123/32",
dry_run=True,
)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the GrantSecurityGroupEgress operation: Request would have succeeded, but DryRun flag is set"
)
@ -293,9 +293,9 @@ def test_authorize_ip_range_and_revoke():
cidr_ip="123.123.123.123/32",
dry_run=True,
)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the RevokeSecurityGroupEgress operation: Request would have succeeded, but DryRun flag is set"
)
@ -338,9 +338,9 @@ def test_authorize_other_group_and_revoke():
security_group.revoke(
ip_protocol="tcp", from_port="22", to_port="2222", src_group=wrong_group
)
cm.exception.code.should.equal("InvalidPermission.NotFound")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidPermission.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
# Actually revoke
security_group.revoke(
@ -441,9 +441,9 @@ def test_get_all_security_groups():
with pytest.raises(EC2ResponseError) as cm:
conn.get_all_security_groups(groupnames=["does_not_exist"])
cm.exception.code.should.equal("InvalidGroup.NotFound")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidGroup.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
resp.should.have.length_of(1)
resp[0].id.should.equal(sg1.id)
@ -472,9 +472,9 @@ def test_authorize_bad_cidr_throws_invalid_parameter_value():
security_group.authorize(
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123"
)
cm.exception.code.should.equal("InvalidParameterValue")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidParameterValue")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2_deprecated
@ -486,9 +486,9 @@ def test_security_group_tagging():
with pytest.raises(EC2ResponseError) as ex:
sg.add_tag("Test", "Tag", dry_run=True)
ex.exception.error_code.should.equal("DryRunOperation")
ex.exception.status.should.equal(400)
ex.exception.message.should.equal(
ex.value.error_code.should.equal("DryRunOperation")
ex.value.status.should.equal(400)
ex.value.message.should.equal(
"An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set"
)
@ -539,7 +539,7 @@ def test_sec_group_rule_limit():
ip_protocol="-1",
cidr_ip=["{0}.0.0.0/0".format(i) for i in range(110)],
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
sg.rules.should.be.empty
# authorize a rule targeting a different sec group (because this count too)
@ -559,13 +559,13 @@ def test_sec_group_rule_limit():
ec2_conn.authorize_security_group(
group_id=sg.id, ip_protocol="-1", cidr_ip=["100.0.0.0/0"]
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
# verify that we cannot authorize past the limit for a different sec group
with pytest.raises(EC2ResponseError) as cm:
ec2_conn.authorize_security_group(
group_id=sg.id, ip_protocol="-1", src_security_group_group_id=other_sg.id
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
# EGRESS
# authorize a rule targeting a different sec group (because this count too)
@ -584,13 +584,13 @@ def test_sec_group_rule_limit():
ec2_conn.authorize_security_group_egress(
group_id=sg.id, ip_protocol="-1", cidr_ip="101.0.0.0/0"
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
# verify that we cannot authorize past the limit for a different sec group
with pytest.raises(EC2ResponseError) as cm:
ec2_conn.authorize_security_group_egress(
group_id=sg.id, ip_protocol="-1", src_group_id=other_sg.id
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
@mock_ec2_deprecated
@ -610,7 +610,7 @@ def test_sec_group_rule_limit_vpc():
ip_protocol="-1",
cidr_ip=["{0}.0.0.0/0".format(i) for i in range(110)],
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
sg.rules.should.be.empty
# authorize a rule targeting a different sec group (because this count too)
@ -630,13 +630,13 @@ def test_sec_group_rule_limit_vpc():
ec2_conn.authorize_security_group(
group_id=sg.id, ip_protocol="-1", cidr_ip=["100.0.0.0/0"]
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
# verify that we cannot authorize past the limit for a different sec group
with pytest.raises(EC2ResponseError) as cm:
ec2_conn.authorize_security_group(
group_id=sg.id, ip_protocol="-1", src_security_group_group_id=other_sg.id
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
# EGRESS
# authorize a rule targeting a different sec group (because this count too)
@ -655,13 +655,13 @@ def test_sec_group_rule_limit_vpc():
ec2_conn.authorize_security_group_egress(
group_id=sg.id, ip_protocol="-1", cidr_ip="50.0.0.0/0"
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
# verify that we cannot authorize past the limit for a different sec group
with pytest.raises(EC2ResponseError) as cm:
ec2_conn.authorize_security_group_egress(
group_id=sg.id, ip_protocol="-1", src_group_id=other_sg.id
)
cm.exception.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
cm.value.error_code.should.equal("RulesPerSecurityGroupLimitExceeded")
"""
@ -766,9 +766,9 @@ def test_security_group_tagging_boto3():
Tags=[{"Key": "Test", "Value": "Tag"}],
DryRun=True,
)
ex.exception.response["Error"]["Code"].should.equal("DryRunOperation")
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.exception.response["Error"]["Message"].should.equal(
ex.value.response["Error"]["Code"].should.equal("DryRunOperation")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["Error"]["Message"].should.equal(
"An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set"
)
@ -927,9 +927,9 @@ def test_get_all_security_groups_filter_with_same_vpc_id():
with pytest.raises(EC2ResponseError) as cm:
conn.get_all_security_groups(group_ids=["does_not_exist"])
cm.exception.code.should.equal("InvalidGroup.NotFound")
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
cm.value.code.should.equal("InvalidGroup.NotFound")
cm.value.status.should.equal(400)
cm.value.request_id.should_not.be.none
@mock_ec2