From 935e6bd95d66936e9ea6769f4f800c0bc2474dfe Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Mon, 25 Feb 2013 23:37:01 -0500 Subject: [PATCH] fix tag deletion --- moto/ec2/responses/tags.py | 3 ++- moto/ec2/utils.py | 7 ++++++- tests/test_ec2/test_tags.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/moto/ec2/responses/tags.py b/moto/ec2/responses/tags.py index f2241eeca..18478e9a5 100644 --- a/moto/ec2/responses/tags.py +++ b/moto/ec2/responses/tags.py @@ -15,7 +15,8 @@ class TagResponse(object): return CREATE_RESPONSE def delete_tags(self): - ec2_backend.delete_tag() + for resource_id, tag in self.resource_ids.iteritems(): + ec2_backend.delete_tag(resource_id, tag[0]) template = Template(DELETE_RESPONSE) return template.render(reservations=ec2_backend.all_reservations()) diff --git a/moto/ec2/utils.py b/moto/ec2/utils.py index d95ad3bbe..6a7667c95 100644 --- a/moto/ec2/utils.py +++ b/moto/ec2/utils.py @@ -48,7 +48,12 @@ def resource_ids_from_querystring(querystring_dict): if prefix in key: resource_index = key.replace(prefix + ".", "") tag_key = querystring_dict.get("Tag.{}.Key".format(resource_index))[0] - tag_value = querystring_dict.get("Tag.{}.Value".format(resource_index))[0] + + tag_value_key = "Tag.{}.Value".format(resource_index) + if tag_value_key in querystring_dict: + tag_value = querystring_dict.get(tag_value_key)[0] + else: + tag_value = None response_values[value[0]] = (tag_key, tag_value) return response_values diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 03365e578..e2eeba907 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -16,3 +16,6 @@ def test_instance_launch_and_terminate(): tag = tags[0] tag.name.should.equal("a key") tag.value.should.equal("some value") + + instance.remove_tag("a key") + conn.get_all_tags().should.have.length_of(0)