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
|
|
@ -1,5 +1,6 @@
|
|||
import boto
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
|
||||
from boto.exception import EC2ResponseError
|
||||
from moto import mock_ec2
|
||||
|
|
@ -11,6 +12,17 @@ def test_key_pairs_empty():
|
|||
assert len(conn.get_all_key_pairs()) == 0
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_key_pairs_invalid_id():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.get_all_key_pairs('foo')
|
||||
cm.exception.code.should.equal('InvalidKeyPair.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_key_pairs_create():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
|
|
@ -42,10 +54,12 @@ def test_key_pairs_create_exist():
|
|||
kp = conn.create_key_pair('foo')
|
||||
assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----')
|
||||
assert len(conn.get_all_key_pairs()) == 1
|
||||
conn.create_key_pair.when.called_with('foo').should.throw(
|
||||
EC2ResponseError,
|
||||
"The keypair 'foo' already exists."
|
||||
)
|
||||
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.create_key_pair('foo')
|
||||
cm.exception.code.should.equal('InvalidKeyPair.Duplicate')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue