def test_map_with_tag_exclusions(): # tags stack_tag = AWSTag() stack_tag.key = "stack" stack_tag.value = "web-server" env_tag = AWSTag() env_tag.key = "env" env_tag.value = "prod" # creating tests objects # prod and web-server first_ami = AMI() first_ami.id = 'ami-28c2b348' first_ami.name = "ubuntu-20160102" first_ami.tags.append(stack_tag) first_ami.tags.append(env_tag) first_ami.creation_date = datetime.now() # just prod second_ami = AMI() second_ami.id = 'ami-28c2b349' second_ami.name = "ubuntu-20160103" second_ami.tags.append(env_tag) second_ami.creation_date = datetime.now() # just web-server third_ami = AMI() third_ami.id = 'ami-28c2b350' third_ami.name = "debian-20160104" third_ami.tags.append(stack_tag) third_ami.creation_date = datetime.now() # creating amis to drop dict candidates = [first_ami, second_ami, third_ami] # grouping strategy grouping_strategy = { "key": "tags", "values": ["stack", "env"], "excluded": ["prod"] } grouped_amis = AMICleaner().map_candidates(candidates, grouping_strategy) assert grouped_amis is not None assert grouped_amis.get("prod") is None assert grouped_amis.get("prod.web-server") is None assert len(grouped_amis.get("web-server")) == 1
def test_tags_values_to_string_without_filters(): first_tag = AWSTag() first_tag.key = "Key1" first_tag.value = "Value1" second_tag = AWSTag() second_tag.key = "Key2" second_tag.value = "Value2" third_tag = AWSTag() third_tag.key = "Key3" third_tag.value = "Value3" tags = [first_tag, third_tag, second_tag] filters = [] tags_values_string = AMICleaner.tags_values_to_string(tags, filters) assert tags_values_string is not None assert tags_values_string == "Value1.Value2.Value3"
def test_tags_values_to_string(): first_tag = AWSTag() first_tag.key = "Key1" first_tag.value = "Value1" second_tag = AWSTag() second_tag.key = "Key2" second_tag.value = "Value2" third_tag = AWSTag() third_tag.key = "Key3" third_tag.value = "Value3" fourth_tag = AWSTag() fourth_tag.key = "Key4" fourth_tag.value = "Value4" tags = [first_tag, third_tag, second_tag, fourth_tag] filters = ["Key2", "Key3"] tags_values_string = AMICleaner.tags_values_to_string(tags, filters) assert tags_values_string is not None assert tags_values_string == "Value2.Value3"
def test_get_awstag_from_none(): aws_tag = AWSTag.object_with_json(None) assert aws_tag is None
def test_models_to_tring(): assert str(AMI()) is not None assert str(AWSBlockDevice()) is not None assert str(AWSEC2Instance()) is not None assert str(AWSTag()) is not None
def test_get_awstag_from_json(): json_to_parse = {"Key": "Name", "Value": "Test"} aws_tag = AWSTag.object_with_json(json_to_parse) assert aws_tag.value == "Test" assert aws_tag.key == "Name"