Skip to content

Commit

Permalink
Fix AttributeError in @@render-portlet
Browse files Browse the repository at this point in the history
and add a test for that
  • Loading branch information
petschki committed Mar 21, 2019
1 parent 193524c commit 910a8dc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/124.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix loading portlets with `@@render-portlet` [petschki]
1 change: 0 additions & 1 deletion plone/app/portlets/browser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def render_portlet(self, portlethash, **kw):
manager, assignment.data),
IPortletRenderer
)
renderer = renderer.__of__(self.context)

renderer.update()
if IDeferredPortletRenderer.providedBy(renderer):
Expand Down
42 changes: 38 additions & 4 deletions plone/app/portlets/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# -*- coding: utf-8 -*-
from Products.CMFPlone.utils import safe_unicode

from plone.app.testing import TEST_USER_ID

from zope.component import getUtility, getMultiAdapter
from zope.component import getMultiAdapter
from zope.component import getUtility

from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletRenderer

from plone.portlets.constants import USER_CATEGORY, CONTEXT_CATEGORY
from plone.portlets.constants import CONTEXT_CATEGORY
from plone.portlets.constants import USER_CATEGORY
from plone.portlets.utils import hashPortletInfo

from plone.app.portlets.storage import PortletAssignmentMapping
from plone.app.portlets.browser.utils import PortletUtilities
from plone.app.portlets.portlets import classic
from plone.app.portlets.portlets import news
from plone.app.portlets.storage import PortletAssignmentMapping
from plone.app.portlets.tests.base import PortletsTestCase
from plone.app.portlets.utils import assignment_from_key

Expand Down Expand Up @@ -49,8 +57,34 @@ def testGetPortletFromUserCategory(self):
self.assertEqual(c, a)


class TestRendering(PortletsTestCase):

def afterSetUp(self):
self.portal.invokeFactory('News Item', 'testnews', title=u'Test News')

def testTraversalRendererWithHash(self):
context = self.folder
request = self.folder.REQUEST
manager = getUtility(
IPortletManager, name='plone.leftcolumn', context=self.folder)
assignment = news.Assignment(state=('private', ))
mapping = getMultiAdapter(
(context, manager), IPortletAssignmentMapping)
mapping['newsportlet'] = assignment
portlet_hash = hashPortletInfo(
dict(manager=manager.__name__, category=CONTEXT_CATEGORY,
key='/'.join(context.getPhysicalPath()),
name='newsportlet'))
render_portlet_view = PortletUtilities(context, request)
rendered_portlet = render_portlet_view.render_portlet(
safe_unicode(portlet_hash))
self.assertIn(u'portletNews', rendered_portlet)
self.assertIn(u'Test News', rendered_portlet)


def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
suite.addTest(makeSuite(TestAssignmentFromKey))
suite.addTest(makeSuite(TestRendering))
return suite

0 comments on commit 910a8dc

Please sign in to comment.