From 866d8b4ea8131fb0b1bb36310495075ad7b0381e Mon Sep 17 00:00:00 2001 From: Joseph Lawson Date: Tue, 30 Sep 2014 16:12:23 -0400 Subject: [PATCH] allow get_filter_value to return state of ami and test * updated Ami.get_filter_value to return the state value of the AMI * updated test_ec2.test_amis.test_ami_filters to test for AMIs in the state of 'available' --- moto/ec2/models.py | 2 ++ tests/test_ec2/test_amis.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 20fe46b25..ccfa5d716 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -604,6 +604,8 @@ class Ami(TaggedEC2Instance): return getattr(self,filter_name) elif filter_name == 'image-id': return self.id + elif filter_name == 'state': + return self.state else: ec2_backend.raise_not_implemented_error("The filter '{0}' for DescribeImages".format(filter_name)) diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index 95fe9f920..1004cfb17 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -132,6 +132,9 @@ def test_ami_filters(): amis_by_id = conn.get_all_images(filters={'image-id': imageA.id}) set([ami.id for ami in amis_by_id]).should.equal(set([imageA.id])) + amis_by_id = conn.get_all_images(filters={'state': 'available'}) + set([ami.id for ami in amis_by_id]).should.equal(set([imageA.id])) + @mock_ec2 def test_getting_missing_ami():