Skip to content

Commit

Permalink
add test for preview_image_link in image_scales
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Aug 12, 2022
1 parent 87993ca commit 8f7d5e7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/plone/volto/behaviors/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
provides=".preview.IPreview"
/>

<configure zcml:condition="have plone-6">
<configure zcml:condition="have plone-60">
<plone:behavior
name="volto.preview_image_link"
title="Preview Image Link"
Expand Down
10 changes: 10 additions & 0 deletions src/plone/volto/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
import plone.volto.coresandbox


try:
from Products.CMFPlone.factory import PLONE60MARKER

PLONE60MARKER # pyflakes
except ImportError:
PLONE_6 = False
else:
PLONE_6 = True


class PloneVoltoCoreLayer(PloneSandboxLayer):

defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)
Expand Down
11 changes: 1 addition & 10 deletions src/plone/volto/tests/test_migrate_to_volto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from plone.volto.content import FolderishDocument
from plone.volto.content import FolderishEvent
from plone.volto.content import FolderishNewsItem
from plone.volto.testing import PLONE_6
from plone.volto.testing import PLONE_VOLTO_MIGRATION_FUNCTIONAL_TESTING
from Products.CMFPlone.utils import get_installer

Expand All @@ -14,16 +15,6 @@
import unittest


try:
from Products.CMFPlone.factory import PLONE60MARKER

PLONE60MARKER # pyflakes
except ImportError:
PLONE_6 = False
else:
PLONE_6 = True


@unittest.skipIf(
not PLONE_6,
"This test is only intended to run for Plone 6",
Expand Down
50 changes: 50 additions & 0 deletions src/plone/volto/tests/test_preview_link_behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-

from plone.namedfile.file import NamedBlobImage
from plone.restapi.interfaces import ISerializeToJsonSummary
from plone.volto.testing import PLONE_6
from plone.volto.testing import PLONE_VOLTO_CORE_INTEGRATION_TESTING
from z3c.form.interfaces import IDataManager
from zope.component import getMultiAdapter

import unittest


TEST_GIF = (
b"GIF89a\x01\x00\x01\x00\x00\xff\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00;"
)


@unittest.skipIf(
not PLONE_6,
"This test is only intended to run for Plone 6",
)
class TestPreviewLinkBehavior(unittest.TestCase):
layer = PLONE_VOLTO_CORE_INTEGRATION_TESTING

def setUp(self):
from plone.volto.behaviors.preview_link import IPreviewLink

self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.request = self.layer["request"]
self.catalog = self.portal.portal_catalog

fti = self.portal.portal_types.Document
fti.behaviors += ("volto.preview_image_link",)

self.doc = self.portal[self.portal.invokeFactory("Document", id="doc1")]
self.image = self.portal[
self.portal.invokeFactory("Image", id="image-1", title="Target image")
]
self.image.image = NamedBlobImage(data=TEST_GIF, filename="test.gif")
dm = getMultiAdapter(
(self.doc, IPreviewLink["preview_image_link"]), IDataManager
)
dm.set(self.image)
self.doc.reindexObject()

def test_image_scales_includes_preview_image_link(self):
brain = self.catalog(UID=self.doc.UID())[0]
summary = getMultiAdapter((brain, self.request), ISerializeToJsonSummary)()
self.assertIn("preview_image_link", summary["image_scales"])

0 comments on commit 8f7d5e7

Please sign in to comment.