moto/tests/test_ec2/test_amis.py

68 lines
2.0 KiB
Python

import boto
from boto.exception import EC2ResponseError
import sure # noqa
from moto import mock_ec2
@mock_ec2
def test_ami_create_and_delete():
conn = boto.connect_ec2('the_key', 'the_secret')
reservation = conn.run_instances('ami-1234abcd')
instance = reservation.instances[0]
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
success = conn.deregister_image.when.called_with(image).should.throw(EC2ResponseError)
@mock_ec2
def test_ami_tagging():
conn = boto.connect_vpc('the_key', 'the_secret')
reservation = conn.run_instances('ami-1234abcd')
instance = reservation.instances[0]
conn.create_image(instance.id, "test-ami", "this is a test ami")
image = conn.get_all_images()[0]
image.add_tag("a key", "some value")
tag = conn.get_all_tags()[0]
tag.name.should.equal("a key")
tag.value.should.equal("some value")
# Refresh the DHCP options
image = conn.get_all_images()[0]
image.tags.should.have.length_of(1)
image.tags["a key"].should.equal("some value")
@mock_ec2
def test_ami_create_from_missing_instance():
conn = boto.connect_ec2('the_key', 'the_secret')
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')
reservation = conn.run_instances('ami-1234abcd')
instance = reservation.instances[0]
instance.modify_attribute("kernel", "test-kernel")
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
image = conn.get_image(image_id)
image.kernel_id.should.equal('test-kernel')
@mock_ec2
def test_getting_missing_ami():
conn = boto.connect_ec2('the_key', 'the_secret')
conn.get_image.when.called_with('ami-missing').should.throw(EC2ResponseError)