delete tags when their resource is deleted

This commit is contained in:
Brady 2020-02-05 11:58:52 -05:00
parent 414f8086b0
commit c95254a284
3 changed files with 21 additions and 1 deletions

View File

@ -143,6 +143,8 @@ class EventsBackend(BaseBackend):
def delete_rule(self, name):
self.rules_order.pop(self.rules_order.index(name))
arn = self.rules.get(name).arn
self.tagger.delete_all_tags_for_resource(arn)
return self.rules.pop(name) is not None
def describe_rule(self, name):

View File

@ -12,6 +12,9 @@ class TaggingService:
result.append({self.keyName: k, self.valueName: v})
return {self.tagName: result}
def delete_all_tags_for_resource(self, arn):
del self.tags[arn]
def tag_resource(self, arn, tags):
if arn not in self.tags:
self.tags[arn] = {}

View File

@ -19,6 +19,7 @@ def test_create_tag():
expected.should.be.equal(actual)
def test_create_tag_without_value():
svc = TaggingService()
tags = [{"Key": "key_key"}]
@ -28,6 +29,7 @@ def test_create_tag_without_value():
expected.should.be.equal(actual)
def test_delete_tag_using_names():
svc = TaggingService()
tags = [{"Key": "key_key", "Value": "value_value"}]
@ -37,6 +39,19 @@ def test_delete_tag_using_names():
{"Tags": []}.should.be.equal(result)
def test_delete_all_tags_for_resource():
svc = TaggingService()
tags = [{"Key": "key_key", "Value": "value_value"}]
tags2 = [{"Key": "key_key2", "Value": "value_value2"}]
svc.tag_resource("arn", tags)
svc.tag_resource("arn", tags2)
svc.delete_all_tags_for_resource("arn")
result = svc.list_tags_for_resource("arn")
{"Tags": []}.should.be.equal(result)
def test_list_empty_delete():
svc = TaggingService()
svc.untag_resource_using_names("arn", ["key_key"])
@ -44,6 +59,7 @@ def test_list_empty_delete():
{"Tags": []}.should.be.equal(result)
def test_delete_tag_using_tags():
svc = TaggingService()
tags = [{"Key": "key_key", "Value": "value_value"}]
@ -61,4 +77,3 @@ def test_extract_tag_names():
expected = ["key1", "key2"]
expected.should.be.equal(actual)