Make sure invalid or malformed AMIs raise an exception

Closes: https://github.com/spulec/moto/issues/1408
This commit is contained in:
Nuwan Goonasekera 2017-12-22 18:50:18 +05:30
commit c68cd650e7
2 changed files with 24 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import boto3
import boto.ec2
import boto3
from boto.exception import EC2ResponseError, EC2ResponseError
from botocore.exceptions import ClientError
import sure # noqa
@ -666,6 +667,19 @@ def test_ami_attribute_error_cases():
cm.exception.request_id.should_not.be.none
@mock_ec2
def test_ami_describe_non_existent():
ec2 = boto3.resource('ec2', region_name='us-west-1')
# Valid pattern but non-existent id
img = ec2.Image('ami-abcd1234')
with assert_raises(ClientError):
img.load()
# Invalid ami pattern
img = ec2.Image('not_an_ami_id')
with assert_raises(ClientError):
img.load()
@mock_ec2
def test_ami_filter_wildcard():
ec2 = boto3.resource('ec2', region_name='us-west-1')