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:
parent
47dbad291e
commit
77dc60ea97
146 changed files with 1172 additions and 1277 deletions
|
|
@ -4,8 +4,7 @@ import copy
|
|||
import json
|
||||
|
||||
# Ensure 'assert_raises' context manager support for Python 2.6
|
||||
import tests.backport_assert_raises # noqa
|
||||
from nose.tools import assert_raises
|
||||
import pytest
|
||||
|
||||
import boto3
|
||||
import boto
|
||||
|
|
@ -20,7 +19,7 @@ from moto import mock_ec2, mock_ec2_deprecated
|
|||
def test_create_and_describe_security_group():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
security_group = conn.create_security_group(
|
||||
"test security group", "this is a test security group", dry_run=True
|
||||
)
|
||||
|
|
@ -38,7 +37,7 @@ def test_create_and_describe_security_group():
|
|||
security_group.description.should.equal("this is a test security group")
|
||||
|
||||
# Trying to create another group with the same name should throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_security_group(
|
||||
"test security group", "this is a test security group"
|
||||
)
|
||||
|
|
@ -57,7 +56,7 @@ def test_create_and_describe_security_group():
|
|||
def test_create_security_group_without_description_raises_error():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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)
|
||||
|
|
@ -87,7 +86,7 @@ def test_create_and_describe_vpc_security_group():
|
|||
|
||||
# Trying to create another group with the same name in the same VPC should
|
||||
# throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
conn.create_security_group(
|
||||
"test security group", "this is a test security group", vpc_id
|
||||
)
|
||||
|
|
@ -146,14 +145,14 @@ def test_deleting_security_groups():
|
|||
conn.get_all_security_groups().should.have.length_of(4)
|
||||
|
||||
# Deleting a group that doesn't exist should throw an error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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
|
||||
|
||||
# Delete by name
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
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)
|
||||
|
|
@ -184,7 +183,7 @@ def test_authorize_ip_range_and_revoke():
|
|||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
security_group = conn.create_security_group("test", "test")
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
success = security_group.authorize(
|
||||
ip_protocol="tcp",
|
||||
from_port="22",
|
||||
|
|
@ -208,7 +207,7 @@ def test_authorize_ip_range_and_revoke():
|
|||
security_group.rules[0].grants[0].cidr_ip.should.equal("123.123.123.123/32")
|
||||
|
||||
# Wrong Cidr should throw error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
security_group.revoke(
|
||||
ip_protocol="tcp",
|
||||
from_port="22",
|
||||
|
|
@ -220,7 +219,7 @@ def test_authorize_ip_range_and_revoke():
|
|||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
# Actually revoke
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
security_group.revoke(
|
||||
ip_protocol="tcp",
|
||||
from_port="22",
|
||||
|
|
@ -246,7 +245,7 @@ def test_authorize_ip_range_and_revoke():
|
|||
"testegress", "testegress", vpc_id="vpc-3432589"
|
||||
)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
success = conn.authorize_security_group_egress(
|
||||
egress_security_group.id,
|
||||
"tcp",
|
||||
|
|
@ -285,7 +284,7 @@ def test_authorize_ip_range_and_revoke():
|
|||
).should.throw(EC2ResponseError)
|
||||
|
||||
# Actually revoke
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
with pytest.raises(EC2ResponseError) as ex:
|
||||
conn.revoke_security_group_egress(
|
||||
egress_security_group.id,
|
||||
"tcp",
|
||||
|
|
@ -335,7 +334,7 @@ def test_authorize_other_group_and_revoke():
|
|||
security_group.rules[0].grants[0].group_id.should.equal(other_security_group.id)
|
||||
|
||||
# Wrong source group should throw error
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
security_group.revoke(
|
||||
ip_protocol="tcp", from_port="22", to_port="2222", src_group=wrong_group
|
||||
)
|
||||
|
|
@ -440,7 +439,7 @@ def test_get_all_security_groups():
|
|||
resp.should.have.length_of(1)
|
||||
resp[0].id.should.equal(sg1.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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)
|
||||
|
|
@ -469,7 +468,7 @@ def test_get_all_security_groups():
|
|||
def test_authorize_bad_cidr_throws_invalid_parameter_value():
|
||||
conn = boto.connect_ec2("the_key", "the_secret")
|
||||
security_group = conn.create_security_group("test", "test")
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
security_group.authorize(
|
||||
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123"
|
||||
)
|
||||
|
|
@ -485,7 +484,7 @@ def test_security_group_tagging():
|
|||
|
||||
sg = conn.create_security_group("test-sg", "Test SG", vpc.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as ex:
|
||||
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)
|
||||
|
|
@ -534,7 +533,7 @@ def test_sec_group_rule_limit():
|
|||
other_sg = ec2_conn.create_security_group("test_2", "test_other")
|
||||
|
||||
# INGRESS
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id,
|
||||
ip_protocol="-1",
|
||||
|
|
@ -556,13 +555,13 @@ def test_sec_group_rule_limit():
|
|||
)
|
||||
success.should.be.true
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
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")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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
|
||||
)
|
||||
|
|
@ -581,13 +580,13 @@ def test_sec_group_rule_limit():
|
|||
group_id=sg.id, ip_protocol="-1", cidr_ip="{0}.0.0.0/0".format(i)
|
||||
)
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
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")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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
|
||||
)
|
||||
|
|
@ -605,7 +604,7 @@ def test_sec_group_rule_limit_vpc():
|
|||
other_sg = ec2_conn.create_security_group("test_2", "test", vpc_id=vpc.id)
|
||||
|
||||
# INGRESS
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
ec2_conn.authorize_security_group(
|
||||
group_id=sg.id,
|
||||
ip_protocol="-1",
|
||||
|
|
@ -627,13 +626,13 @@ def test_sec_group_rule_limit_vpc():
|
|||
)
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
success.should.be.true
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
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")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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
|
||||
)
|
||||
|
|
@ -652,13 +651,13 @@ def test_sec_group_rule_limit_vpc():
|
|||
group_id=sg.id, ip_protocol="-1", cidr_ip="{0}.0.0.0/0".format(i)
|
||||
)
|
||||
# verify that we cannot authorize past the limit for a CIDR IP
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
with pytest.raises(EC2ResponseError) as cm:
|
||||
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")
|
||||
# verify that we cannot authorize past the limit for a different sec group
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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
|
||||
)
|
||||
|
|
@ -689,7 +688,7 @@ def test_add_same_rule_twice_throws_error():
|
|||
]
|
||||
sg.authorize_ingress(IpPermissions=ip_permissions)
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
sg.authorize_ingress(IpPermissions=ip_permissions)
|
||||
|
||||
|
||||
|
|
@ -761,7 +760,7 @@ def test_security_group_tagging_boto3():
|
|||
|
||||
sg = conn.create_security_group(GroupName="test-sg", Description="Test SG")
|
||||
|
||||
with assert_raises(ClientError) as ex:
|
||||
with pytest.raises(ClientError) as ex:
|
||||
conn.create_tags(
|
||||
Resources=[sg["GroupId"]],
|
||||
Tags=[{"Key": "Test", "Value": "Tag"}],
|
||||
|
|
@ -926,7 +925,7 @@ def test_get_all_security_groups_filter_with_same_vpc_id():
|
|||
)
|
||||
security_groups.should.have.length_of(1)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue