Fixed bug in attachment code

This commit is contained in:
Sybren A. Stüvel 2018-09-06 12:55:18 +02:00
parent 08bf63c2ee
commit e4fa32b8e4
2 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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'<img src="{link}" alt="cute_kitten.jpg"/></a>'
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'<img src="{link}" alt="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'<a href="{tag_link}" target="_blank">'
f'<img src="{link}" alt="cute_kitten.jpg"/></a>',
render('{attachment img link=%r}' % tag_link, context=node_props).strip()
render('{attachment img link=%r}' % tag_link, context=node_doc).strip()
)