def test_basic_lookup_no_matching_images_from_name(self, _mock_client): """Test basic lookup no matching images from name.""" image_id = "ami-fffccc111" self.stubber.add_response( "describe_images", { "Images": [ { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-13T01:17:44.000Z", "State": "available", "ImageId": image_id, "Name": "Fake Image 1", "VirtualizationType": "hvm", } ] }, ) with self.stubber: with self.assertRaises(ImageNotFound): AmiLookup.handle( value=r"owners:self name_regex:MyImage\s\d", provider=self.provider )
def test_basic_lookup_no_matching_images(self, _mock_client): """Test basic lookup no matching images.""" self.stubber.add_response("describe_images", {"Images": []}) with self.stubber: with self.assertRaises(ImageNotFound): AmiLookup.handle( value=r'owners:self name_regex:Fake\sImage\s\d', provider=self.provider)
def test_basic_lookup_no_matching_images( self, cfngin_context: MockCFNginContext) -> None: """Test basic lookup no matching images.""" stubber = cfngin_context.add_stubber("ec2") stubber.add_response("describe_images", {"Images": []}) with stubber, pytest.raises(ImageNotFound): AmiLookup.handle(value=r"owners:self name_regex:Fake\sImage\s\d", context=cfngin_context)
def test_basic_lookup_multiple_images(self, _mock_client): """Test basic lookup multiple images.""" image_id = "ami-fffccc111" self.stubber.add_response( "describe_images", { "Images": [ { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-13T01:17:44.000Z", "State": "available", "ImageId": "ami-fffccc110", "Name": "Fake Image 1", "VirtualizationType": "hvm", }, { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-14T01:17:44.000Z", "State": "available", "ImageId": image_id, "Name": "Fake Image 2", "VirtualizationType": "hvm", }, ] }) with self.stubber: value = AmiLookup.handle( value=r'owners:self name_regex:Fake\sImage\s\d', provider=self.provider) self.assertEqual(value, image_id)
def test_basic_lookup_with_region( self, cfngin_context: MockCFNginContext) -> None: """Test basic lookup with region.""" stubber = cfngin_context.add_stubber("ec2", region="us-west-1") image_id = "ami-fffccc111" stubber.add_response( "describe_images", { "Images": [{ "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-13T01:17:44.000Z", "State": "available", "ImageId": image_id, "Name": "Fake Image 1", "VirtualizationType": "hvm", }] }, ) with stubber: assert (AmiLookup.handle( value=r"us-west-1@owners:self name_regex:Fake\sImage\s\d", context=cfngin_context, ) == image_id)
def test_basic_lookup_no_matching_images_from_name( self, cfngin_context: MockCFNginContext) -> None: """Test basic lookup no matching images from name.""" stubber = cfngin_context.add_stubber("ec2") image_id = "ami-fffccc111" stubber.add_response( "describe_images", { "Images": [{ "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-13T01:17:44.000Z", "State": "available", "ImageId": image_id, "Name": "Fake Image 1", "VirtualizationType": "hvm", }] }, ) with stubber, pytest.raises(ImageNotFound): AmiLookup.handle(value=r"owners:self name_regex:MyImage\s\d", context=cfngin_context)
def test_basic_lookup_multiple_images( self, cfngin_context: MockCFNginContext) -> None: """Test basic lookup multiple images.""" stubber = cfngin_context.add_stubber("ec2") image_id = "ami-fffccc111" stubber.add_response( "describe_images", { "Images": [ { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-13T01:17:44.000Z", "State": "available", "ImageId": "ami-fffccc110", "Name": "Fake Image 1", "VirtualizationType": "hvm", }, { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-14T01:17:44.000Z", "State": "available", "ImageId": image_id, "Name": "Fake Image 2", "VirtualizationType": "hvm", }, # include an ARI in the response to ensure it can be handled # (these don't include a 'Name') { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-06-24T20:34:25.000Z", "State": "available", "ImageId": "ari-e6bc478f", "VirtualizationType": "paravirtual", }, ] }, ) with stubber: assert (AmiLookup.handle( value=r"owners:self name_regex:Fake\sImage\s\d", context=cfngin_context, ) == image_id)
def test_basic_lookup_multiple_images(self, _mock_client): """Test basic lookup multiple images.""" image_id = "ami-fffccc111" self.stubber.add_response( "describe_images", { "Images": [ { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-13T01:17:44.000Z", "State": "available", "ImageId": "ami-fffccc110", "Name": "Fake Image 1", "VirtualizationType": "hvm", }, { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-02-14T01:17:44.000Z", "State": "available", "ImageId": image_id, "Name": "Fake Image 2", "VirtualizationType": "hvm", }, # include an ARI in the response to ensure it can be handled # (these don't include a 'Name') { "OwnerId": "897883143566", "Architecture": "x86_64", "CreationDate": "2011-06-24T20:34:25.000Z", "State": "available", "ImageId": "ari-e6bc478f", "VirtualizationType": "paravirtual", }, ] }, ) with self.stubber: value = AmiLookup.handle( value=r"owners:self name_regex:Fake\sImage\s\d", provider=self.provider ) self.assertEqual(value, image_id)