Back to index

plone3  3.1.7
test_recent_portlet.py
Go to the documentation of this file.
00001 from zope.component import getUtility, getMultiAdapter
00002 from zope.app.component.hooks import setHooks, setSite
00003 
00004 from Products.GenericSetup.utils import _getDottedName
00005 
00006 from plone.portlets.interfaces import IPortletType
00007 from plone.portlets.interfaces import IPortletManager
00008 from plone.portlets.interfaces import IPortletAssignment
00009 from plone.portlets.interfaces import IPortletDataProvider
00010 from plone.portlets.interfaces import IPortletRenderer
00011 
00012 from plone.app.portlets.portlets import recent
00013 from plone.app.portlets.storage import PortletAssignmentMapping
00014 
00015 from plone.app.portlets.tests.base import PortletsTestCase
00016 
00017 class TestPortlet(PortletsTestCase):
00018 
00019     def afterSetUp(self):
00020         setHooks()
00021         setSite(self.portal)
00022         self.setRoles(('Manager',))
00023 
00024     def testPortletTypeRegistered(self):
00025         portlet = getUtility(IPortletType, name='portlets.Recent')
00026         self.assertEquals(portlet.addview, 'portlets.Recent')
00027 
00028     def testRegisteredInterfaces(self):
00029         portlet = getUtility(IPortletType, name='portlets.Recent')
00030         registered_interfaces = [_getDottedName(i) for i in portlet.for_] 
00031         registered_interfaces.sort() 
00032         self.assertEquals(['plone.app.portlets.interfaces.IColumn',
00033           'plone.app.portlets.interfaces.IDashboard'],
00034           registered_interfaces)
00035 
00036     def testInterfaces(self):
00037         portlet = recent.Assignment()
00038         self.failUnless(IPortletAssignment.providedBy(portlet))
00039         self.failUnless(IPortletDataProvider.providedBy(portlet.data))
00040 
00041     def testInvokeAddview(self):
00042         portlet = getUtility(IPortletType, name='portlets.Recent')
00043         mapping = self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
00044         for m in mapping.keys():
00045             del mapping[m]
00046         addview = mapping.restrictedTraverse('+/' + portlet.addview)
00047 
00048         addview.createAndAdd(data={})
00049 
00050         self.assertEquals(len(mapping), 1)
00051         self.failUnless(isinstance(mapping.values()[0], recent.Assignment))
00052 
00053     def testInvokeEditView(self):
00054         mapping = PortletAssignmentMapping()
00055         request = self.folder.REQUEST
00056 
00057         mapping['foo'] = recent.Assignment()
00058         editview = getMultiAdapter((mapping['foo'], request), name='edit')
00059         self.failUnless(isinstance(editview, recent.EditForm))
00060 
00061     def testRenderer(self):
00062         context = self.folder
00063         request = self.folder.REQUEST
00064         view = self.folder.restrictedTraverse('@@plone')
00065         manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00066         assignment = recent.Assignment()
00067 
00068         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00069         self.failUnless(isinstance(renderer, recent.Renderer))
00070 
00071 class TestRenderer(PortletsTestCase):
00072 
00073     def afterSetUp(self):
00074         setHooks()
00075         setSite(self.portal)
00076 
00077     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00078         context = context or self.folder
00079         request = request or self.folder.REQUEST
00080         view = view or self.folder.restrictedTraverse('@@plone')
00081         manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00082         assignment = assignment or recent.Assignment()
00083 
00084         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00085 
00086     def test_recent_items(self):
00087         r = self.renderer(assignment=recent.Assignment(count=5))
00088         self.assertEquals(5, len(r.recent_items()))
00089 
00090     def test_recently_modified_link(self):
00091         r = self.renderer(assignment=recent.Assignment(count=5))
00092         self.failUnless(r.recently_modified_link().endswith('/recently_modified'))
00093 
00094 def test_suite():
00095     from unittest import TestSuite, makeSuite
00096     suite = TestSuite()
00097     suite.addTest(makeSuite(TestPortlet))
00098     suite.addTest(makeSuite(TestRenderer))
00099     return suite