def test_main_dry_run(self): """ Test that a correctly-tagged AMI is NOT deregistered """ self.args.append('--dry-run') mock_ec2 = MockEC2() with patch('boto3.resource', return_value=mock_ec2): main(self.args) mock_ec2.images.image.deregister.assert_not_called()
def test_main(self, mock_ec2): # lint-amnesty, pylint: disable=unused-argument """ Test output of main """ with LogCapture() as capture: main(self.args) capture.check(('aws.deregister_amis', 'INFO', 'Finding AMIs tagged with delete_or_keep: delete'), ('aws.deregister_amis', 'INFO', 'No images found matching criteria.'))
def test_main_dry_run(self): """ Test that a correctly-tagged AMI is NOT deregistered """ test_ami = self._get_test_image() test_ami.add_tag('delete_or_keep', 'delete') self.args.append('--dry-run') main(self.args) self.assertEqual(len(self.conn.get_all_images()), 1)
def test_main(self): """ Test output of main """ with LogCapture() as l: main(self.args) l.check(('aws.deregister_amis', 'INFO', 'Finding AMIs tagged with delete_or_keep: delete'), ('aws.deregister_amis', 'INFO', 'No images found matching criteria.'))
def test_main_deregister(self, mock_ec2): # lint-amnesty, pylint: disable=unused-argument """ Test that a correctly-tagged AMI is deregistered """ with LogCapture() as capture: main(self.args) capture.check( ('aws.deregister_amis', 'INFO', 'Finding AMIs tagged with delete_or_keep: delete'), ('aws.deregister_amis', 'INFO', 'Deregistering test_ami'))
def test_main_no_deregister(self, mock_ec2): """ Test that an AMI without proper tags is not de-registered """ with LogCapture() as capture: main(self.args) capture.check(('aws.deregister_amis', 'INFO', 'Finding AMIs tagged with delete_or_keep: delete'), ('aws.deregister_amis', 'INFO', 'No images found matching criteria.'))
def test_main_deregister(self): """ Test that a correctly-tagged AMI is deregistered """ test_ami = self._get_test_image() test_ami.add_tag('delete_or_keep', 'delete') with LogCapture() as l: main(self.args) l.check(('aws.deregister_amis', 'INFO', 'Finding AMIs tagged with delete_or_keep: delete'), ('aws.deregister_amis', 'INFO', 'Deregistering {image_id}'.format(image_id=test_ami))) self.assertEqual(len(self.conn.get_all_images()), 0)
def test_main_no_deregister(self): """ Test that an AMI without proper tags is not de-registered """ test_ami = self._get_test_image() # Flag AMI as 'keep' test_ami.add_tag('delete_or_keep', 'keep') with LogCapture() as l: main(self.args) l.check(('aws.deregister_amis', 'INFO', 'Finding AMIs tagged with delete_or_keep: delete'), ('aws.deregister_amis', 'INFO', 'No images found matching criteria.')) self.assertEqual(len(self.conn.get_all_images()), 1)