Skip to content

Commit

Permalink
Add image_scales support for RealContentListingObject
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Apr 1, 2024
1 parent 2eaa880 commit 83595d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plone/app/contentlisting/realobject.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from Acquisition import aq_get
from plone.app.contentlisting.contentlisting import BaseContentListingObject
from plone.app.contentlisting.interfaces import IContentListingObject
from plone.base.interfaces import IImageScalesAdapter
from plone.base.utils import base_hasattr
from plone.base.utils import human_readable_size
from plone.rfc822.interfaces import IPrimaryFieldInfo
from plone.uuid.interfaces import IUUID
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from zope.interface import implementer


Expand Down Expand Up @@ -105,3 +107,7 @@ def Type(self):
def PortalType(self):
obj = self.getObject()
return obj.portal_type

def image_scales(self):
obj = self.getObject()
return getMultiAdapter((obj, self.request), IImageScalesAdapter)()
20 changes: 20 additions & 0 deletions plone/app/contentlisting/tests/test_integration_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.batching.interfaces import IBatch
from plone.namedfile.file import NamedBlobImage
from Products.CMFCore.utils import getToolByName
from zope.interface.verify import verifyObject

import base64
import unittest

TEST_IMAGE_DATA = base64.b64decode(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
)

class TestSetup(unittest.TestCase):
layer = CONTENTLISTING_FUNCTIONAL_TESTING
Expand Down Expand Up @@ -265,6 +270,21 @@ def test_item_get_none(self):
"result in an AttributeError."
)

def test_item_image_scales(self):
self.folder.invokeFactory(
"Image",
"myimage",
title="My Image",
)
myimage = self.folder.myimage
myimage.image = NamedBlobImage(
data=TEST_IMAGE_DATA,
filename="test.png",
)
item = IContentListingObject(myimage)
image_scales = item.image_scales()
self.assertIn("download", image_scales["image"][0])


class TestFolderContents(unittest.TestCase):
"""Testing that the folder contents browserview works and behaves
Expand Down

0 comments on commit 83595d5

Please sign in to comment.