Error handling: Model-level validations, proper error responses.
This commit is contained in:
parent
b94401247f
commit
071c03e216
25 changed files with 616 additions and 287 deletions
|
|
@ -4,6 +4,7 @@ import boto
|
|||
from boto.exception import EC2ResponseError
|
||||
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
|
||||
from moto import mock_ec2
|
||||
|
||||
|
|
@ -41,7 +42,12 @@ def test_igw_attach_bad_vpc():
|
|||
""" internet gateway fail to attach w/ bad vpc """
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
igw = conn.create_internet_gateway()
|
||||
conn.attach_internet_gateway.when.called_with(igw.id, BAD_VPC).should.throw(EC2ResponseError)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.attach_internet_gateway(igw.id, BAD_VPC)
|
||||
cm.exception.code.should.equal('InvalidVpcID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_attach_twice():
|
||||
|
|
@ -51,7 +57,12 @@ def test_igw_attach_twice():
|
|||
vpc1 = conn.create_vpc(VPC_CIDR)
|
||||
vpc2 = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc1.id)
|
||||
conn.attach_internet_gateway.when.called_with(igw.id, vpc2.id).should.throw(EC2ResponseError)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.attach_internet_gateway(igw.id, vpc2.id)
|
||||
cm.exception.code.should.equal('Resource.AlreadyAssociated')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_detach():
|
||||
|
|
@ -65,20 +76,46 @@ def test_igw_detach():
|
|||
igw.attachments.should.have.length_of(0)
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_detach_bad_vpc():
|
||||
""" internet gateway fail to detach w/ bad vpc """
|
||||
def test_igw_detach_wrong_vpc():
|
||||
""" internet gateway fail to detach w/ wrong vpc """
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
igw = conn.create_internet_gateway()
|
||||
vpc1 = conn.create_vpc(VPC_CIDR)
|
||||
vpc2 = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc1.id)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.detach_internet_gateway(igw.id, vpc2.id)
|
||||
cm.exception.code.should.equal('Gateway.NotAttached')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_detach_invalid_vpc():
|
||||
""" internet gateway fail to detach w/ invalid vpc """
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
igw = conn.create_internet_gateway()
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc.id)
|
||||
conn.detach_internet_gateway.when.called_with(igw.id, BAD_VPC).should.throw(EC2ResponseError)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.detach_internet_gateway(igw.id, BAD_VPC)
|
||||
cm.exception.code.should.equal('Gateway.NotAttached')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_detach_unattached():
|
||||
""" internet gateway fail to detach unattached """
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
igw = conn.create_internet_gateway()
|
||||
conn.detach_internet_gateway.when.called_with(igw.id, BAD_VPC).should.throw(EC2ResponseError)
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.detach_internet_gateway(igw.id, vpc.id)
|
||||
cm.exception.code.should.equal('Gateway.NotAttached')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_delete():
|
||||
|
|
@ -98,7 +135,12 @@ def test_igw_delete_attached():
|
|||
igw = conn.create_internet_gateway()
|
||||
vpc = conn.create_vpc(VPC_CIDR)
|
||||
conn.attach_internet_gateway(igw.id, vpc.id)
|
||||
conn.delete_internet_gateway.when.called_with(igw.id).should.throw(EC2ResponseError)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.delete_internet_gateway(igw.id)
|
||||
cm.exception.code.should.equal('DependencyViolation')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
@mock_ec2
|
||||
def test_igw_desribe():
|
||||
|
|
@ -112,4 +154,8 @@ def test_igw_desribe():
|
|||
def test_igw_desribe_bad_id():
|
||||
""" internet gateway fail to fetch by bad id """
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
conn.get_all_internet_gateways.when.called_with([BAD_IGW]).should.throw(EC2ResponseError)
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.get_all_internet_gateways([BAD_IGW])
|
||||
cm.exception.code.should.equal('InvalidInternetGatewayID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue