moto/tests/test_ec2/test_amis.py

40 lines
1.2 KiB
Python
Raw Normal View History

2013-02-22 04:13:01 +00:00
import boto
from boto.exception import EC2ResponseError
2013-03-05 13:35:18 +00:00
import sure # flake8: noqa
2013-02-22 04:13:01 +00:00
from moto import mock_ec2
@mock_ec2
def test_ami_create_and_delete():
conn = boto.connect_ec2('the_key', 'the_secret')
2013-03-05 13:14:43 +00:00
reservation = conn.run_instances('ami-1234abcd')
instance = reservation.instances[0]
2013-02-28 05:08:35 +00:00
image = conn.create_image(instance.id, "test-ami", "this is a test ami")
all_images = conn.get_all_images()
all_images[0].id.should.equal(image)
success = conn.deregister_image(image)
success.should.be.true
@mock_ec2
def test_ami_create_from_missing_instance():
conn = boto.connect_ec2('the_key', 'the_secret')
2013-03-05 13:14:43 +00:00
args = ["i-abcdefg", "test-ami", "this is a test ami"]
conn.create_image.when.called_with(*args).should.throw(EC2ResponseError)
@mock_ec2
def test_ami_pulls_attributes_from_instance():
conn = boto.connect_ec2('the_key', 'the_secret')
2013-03-05 13:14:43 +00:00
reservation = conn.run_instances('ami-1234abcd')
instance = reservation.instances[0]
instance.modify_attribute("kernel", "test-kernel")
2013-02-28 05:08:35 +00:00
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
image = conn.get_image(image_id)
2013-03-05 13:35:18 +00:00
image.kernel_id.should.equal('test-kernel')