From 35507f33dfe161456f241f3096d9bf8278b5eb38 Mon Sep 17 00:00:00 2001 From: Don Kuntz Date: Wed, 28 Aug 2019 13:55:19 -0500 Subject: [PATCH 1/2] Don't error out on route53.list_tags_for_resource when resource has no tags Without the added `return {}`, calling route53.list_tags_for_resource when called with a ResourceId of a resource without any tags would result in the error: jinja2.exceptions.UndefinedError: 'None' has no attribute 'items' Because the LIST_TAGS_FOR_RESOURCE_RESPONSE was given None instead of empty dict. This now allows list_tags_for_resource to be called without issue on tag-less resources. --- moto/route53/models.py | 1 + tests/test_route53/test_route53.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/moto/route53/models.py b/moto/route53/models.py index 61a6609aa..77a0e59e6 100644 --- a/moto/route53/models.py +++ b/moto/route53/models.py @@ -305,6 +305,7 @@ class Route53Backend(BaseBackend): def list_tags_for_resource(self, resource_id): if resource_id in self.resource_tags: return self.resource_tags[resource_id] + return {} def get_all_hosted_zones(self): return self.zones.values() diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index de9465d6d..e70137156 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -404,6 +404,13 @@ def test_list_or_change_tags_for_resource_request(): ) healthcheck_id = health_check['HealthCheck']['Id'] + # confirm this works for resources with zero tags + response = conn.list_tags_for_resource( + ResourceType="healthcheck", ResourceId=healthcheck_id) + response["ResourceTagSet"]["Tags"].should.be.empty + + print(response) + tag1 = {"Key": "Deploy", "Value": "True"} tag2 = {"Key": "Name", "Value": "UnitTest"} From cae0b5bc45de692580a07fdee16c9a83628f52d1 Mon Sep 17 00:00:00 2001 From: Don Kuntz Date: Wed, 28 Aug 2019 13:59:49 -0500 Subject: [PATCH 2/2] Remove extraneous print statement from test --- tests/test_route53/test_route53.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_route53/test_route53.py b/tests/test_route53/test_route53.py index e70137156..babd54d26 100644 --- a/tests/test_route53/test_route53.py +++ b/tests/test_route53/test_route53.py @@ -409,8 +409,6 @@ def test_list_or_change_tags_for_resource_request(): ResourceType="healthcheck", ResourceId=healthcheck_id) response["ResourceTagSet"]["Tags"].should.be.empty - print(response) - tag1 = {"Key": "Deploy", "Value": "True"} tag2 = {"Key": "Name", "Value": "UnitTest"}