From e4fa32b8e4f248bb181f2395e8bbfbfac594797e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 6 Sep 2018 12:55:18 +0200 Subject: [PATCH] Fixed bug in attachment code --- pillar/shortcodes.py | 2 +- tests/test_shortcodes.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pillar/shortcodes.py b/pillar/shortcodes.py index 5a4a8c32..cdb93905 100644 --- a/pillar/shortcodes.py +++ b/pillar/shortcodes.py @@ -230,7 +230,7 @@ class Attachment: from pillar.web import system_util - attachments = node_properties.get('attachments', {}) + attachments = node_properties.get('properties', {}).get('attachments', {}) attachment = attachments.get(slug) if not attachment: raise self.NoSuchSlug(slug) diff --git a/tests/test_shortcodes.py b/tests/test_shortcodes.py index 5535f466..1201ed46 100644 --- a/tests/test_shortcodes.py +++ b/tests/test_shortcodes.py @@ -187,11 +187,11 @@ class AttachmentTest(AbstractPillarTest): ], 'filename': 'cute_kitten.jpg', }) - node_props = { + node_doc = {'properties': { 'attachments': { 'img': {'oid': oid}, } - } + }} # We have to get the file document again, because retrieving it via the # API (which is what the shortcode rendering is doing) will change its @@ -204,20 +204,20 @@ class AttachmentTest(AbstractPillarTest): f'cute_kitten.jpg' self.assertEqual( self_linked, - render('{attachment img link}', context=node_props).strip() + render('{attachment img link}', context=node_doc).strip() ) self.assertEqual( self_linked, - render('{attachment img link=self}', context=node_props).strip() + render('{attachment img link=self}', context=node_doc).strip() ) self.assertEqual( f'cute_kitten.jpg', - render('{attachment img}', context=node_props).strip() + render('{attachment img}', context=node_doc).strip() ) tag_link = 'https://i.imgur.com/FmbuPNe.jpg' self.assertEqual( f'' f'cute_kitten.jpg', - render('{attachment img link=%r}' % tag_link, context=node_props).strip() + render('{attachment img link=%r}' % tag_link, context=node_doc).strip() )