def test_deletion_filtered_tags(): """ Test deletion methods """ # creating tests objects first_ami = AMI() first_ami.name = "test-ami1" first_ami.id = 'ami-28c2b348' first_ami.creation_date = "2017-11-04T01:35:31.000Z" second_ami = AMI() second_ami.name = "test-ami2" second_ami.id = 'ami-28c2b349' second_ami.creation_date = "2017-11-04T01:35:31.000Z" second_ami.tags = [ AWSTag.object_with_json(dict(Key="env", Value="prod")), AWSTag.object_with_json(dict(Key="role", Value="nginx")), ] third_ami = AMI() third_ami.name = "test-ami3" third_ami.id = 'ami-28c2b350' third_ami.creation_date = "2017-11-04T01:35:31.000Z" third_ami.tags = [ AWSTag.object_with_json(dict(Key="env", Value="dev")), AWSTag.object_with_json(dict(Key="role", Value="nginx")), ] # constructing dicts amis_dict = dict() amis_dict[first_ami.id] = first_ami amis_dict[second_ami.id] = second_ami amis_dict[third_ami.id] = third_ami parser = parse_args( [ '--keep-previous', '0', '--tag', 'role=nginx', ] ) app = App(parser) # testing filter candidates = app.fetch_candidates(amis_dict) candidates_tobedeleted = app.prepare_candidates(candidates) assert len(candidates) == 3 assert candidates_tobedeleted == [second_ami, third_ami] parser = parse_args( [ '--keep-previous', '0', '--tag', 'role=nginx', '--tag', 'env=dev', ] ) app = App(parser) candidates_tobedeleted2 = app.prepare_candidates(candidates) assert len(candidates) == 3 assert candidates_tobedeleted2 == [third_ami]
def test_deletion_ami_min_days(): """ Test deletion methods """ # creating tests objects first_ami = AMI() first_ami.name = "test-ami" first_ami.id = "ami-28c2b348" first_ami.creation_date = "2017-11-04T01:35:31.000Z" second_ami = AMI() second_ami.name = "test-ami" second_ami.id = "ami-28c2b349" second_ami.creation_date = "2017-11-04T01:35:31.000Z" # constructing dicts amis_dict = dict() amis_dict[first_ami.id] = first_ami amis_dict[second_ami.id] = second_ami parser = parse_args( [ "--keep-previous", "0", "--ami-min-days", "1", "--mapping-key", "name", "--mapping-values", "test-ami", ] ) app = App(parser) # testing filter candidates = app.fetch_candidates(amis_dict) candidates_tobedeleted = app.prepare_candidates(candidates) assert len(candidates) == 2 assert len(candidates_tobedeleted) == 2 parser = parse_args( [ "--keep-previous", "0", "--ami-min-days", "10000", "--mapping-key", "name", "--mapping-values", "test-ami", ] ) app = App(parser) candidates_tobedeleted2 = app.prepare_candidates(candidates) assert len(candidates) == 2 assert len(candidates_tobedeleted2) == 0
def test_deletion_filtered_name(): """ Test deletion methods """ # creating tests objects first_ami = AMI() first_ami.name = "test-ami-delete-1" first_ami.id = 'ami-28c2b348' first_ami.creation_date = "2017-11-04T01:35:31.000Z" second_ami = AMI() second_ami.name = "test-ami-keepme" second_ami.id = 'ami-28c2b349' second_ami.creation_date = "2017-11-04T01:35:31.000Z" third_ami = AMI() third_ami.name = "test-ami-delete-2" third_ami.id = 'ami-28c2b350' third_ami.creation_date = "2017-11-04T01:35:31.000Z" # constructing dicts amis_dict = dict() amis_dict[first_ami.id] = first_ami amis_dict[second_ami.id] = second_ami amis_dict[third_ami.id] = third_ami parser = parse_args( [ '--keep-previous', '0', '--mapping-key', 'name', '--mapping-values', 'test-ami-delete'] ) app = App(parser) # testing filter candidates = app.fetch_candidates(amis_dict) candidates_tobedeleted = app.prepare_candidates(candidates) assert len(candidates) == 3 assert candidates_tobedeleted == [first_ami, third_ami] parser = parse_args( [ '--keep-previous', '0', '--name', 'test-ami-delete-1', ] ) app = App(parser) candidates_tobedeleted2 = app.prepare_candidates(candidates) assert len(candidates) == 3 assert candidates_tobedeleted2 == [first_ami]
def test_deletion_ami_min_days(): """ Test deletion methods """ # creating tests objects first_ami = AMI() first_ami.name = "test-ami" first_ami.id = 'ami-28c2b348' first_ami.creation_date = "2017-11-04T01:35:31.000Z" second_ami = AMI() second_ami.name = "test-ami" second_ami.id = 'ami-28c2b349' second_ami.creation_date = "2017-11-04T01:35:31.000Z" # constructing dicts amis_dict = dict() amis_dict[first_ami.id] = first_ami amis_dict[second_ami.id] = second_ami parser = parse_args( [ '--keep-previous', '0', '--ami-min-days', '1', '--mapping-key', 'name', '--mapping-values', 'test-ami'] ) app = App(parser) # testing filter candidates = app.fetch_candidates(amis_dict) candidates_tobedeleted = app.prepare_candidates(candidates) assert len(candidates) == 2 assert len(candidates_tobedeleted) == 2 parser = parse_args( [ '--keep-previous', '0', '--ami-min-days', '10000', '--mapping-key', 'name', '--mapping-values', 'test-ami'] ) app = App(parser) candidates_tobedeleted2 = app.prepare_candidates(candidates) assert len(candidates) == 2 assert len(candidates_tobedeleted2) == 0
def test_deletion_ami_min_days(): """ Test deletion methods """ # creating tests objects first_ami = AMI() first_ami.name = "test-ami" first_ami.id = 'ami-28c2b348' first_ami.creation_date = "2017-11-04T01:35:31.000Z" second_ami = AMI() second_ami.name = "test-ami" second_ami.id = 'ami-28c2b349' second_ami.creation_date = "2017-11-04T01:35:31.000Z" # constructing dicts amis_dict = {first_ami.id: first_ami, second_ami.id: second_ami} parser = parse_args([ '--keep-previous', '0', '--ami-min-days', '1', '--mapping-key', 'name', '--mapping-values', 'test-ami' ]) app = App(parser) # testing filter candidates = app.fetch_candidates(amis_dict) candidates_tobedeleted = app.prepare_candidates(candidates) assert len(candidates) == 2 assert len(candidates_tobedeleted) == 2 parser = parse_args([ '--keep-previous', '0', '--ami-min-days', '10000', '--mapping-key', 'name', '--mapping-values', 'test-ami' ]) app = App(parser) candidates_tobedeleted2 = app.prepare_candidates(candidates) assert len(candidates) == 2 assert len(candidates_tobedeleted2) == 0