moto/tests/test_ec2/test_key_pairs.py

31 lines
852 B
Python
Raw Normal View History

2013-02-22 04:13:01 +00:00
import boto
2013-08-03 21:21:25 +00:00
import sure # noqa
2013-02-22 04:13:01 +00:00
from boto.exception import EC2ResponseError
2013-02-22 04:13:01 +00:00
from moto import mock_ec2
@mock_ec2
def test_key_pairs_empty():
conn = boto.connect_ec2('the_key', 'the_secret')
assert len(conn.get_all_key_pairs()) == 0
2014-02-24 10:24:46 +00:00
@mock_ec2
def test_key_pairs_create():
conn = boto.connect_ec2('the_key', 'the_secret')
kp = conn.create_key_pair('foo')
2014-02-24 11:03:26 +00:00
assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----')
@mock_ec2
def test_key_pairs_create_exist():
conn = boto.connect_ec2('the_key', 'the_secret')
kp = conn.create_key_pair('foo')
assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----')
# Call get_all_instances with a bad id should raise an error
conn.create_key_pair.when.called_with('foo').should.throw(
EC2ResponseError,
"The keypair 'foo' already exists."
)