Back to index

plone3  3.1.7
test_classic_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 classic
00013 
00014 from plone.app.portlets.storage import PortletAssignmentMapping
00015 
00016 from plone.app.portlets.tests.base import PortletsTestCase
00017 
00018 class TestPortlet(PortletsTestCase):
00019 
00020     def afterSetUp(self):
00021         setHooks()
00022         setSite(self.portal)
00023         self.setRoles(('Manager',))
00024 
00025     def testPortletTypeRegistered(self):
00026         portlet = getUtility(IPortletType, name='portlets.Classic')
00027         self.assertEquals(portlet.addview, 'portlets.Classic')
00028 
00029     def testRegisteredInterfaces(self):
00030         portlet = getUtility(IPortletType, name='portlets.Classic')
00031         registered_interfaces = [_getDottedName(i) for i in portlet.for_] 
00032         registered_interfaces.sort() 
00033         self.assertEquals(['plone.app.portlets.interfaces.IColumn',
00034           'plone.app.portlets.interfaces.IDashboard'],
00035           registered_interfaces)
00036 
00037     def testInterfaces(self):
00038         portlet = classic.Assignment(template='portlet_recent', macro='portlet')
00039         self.failUnless(IPortletAssignment.providedBy(portlet))
00040         self.failUnless(IPortletDataProvider.providedBy(portlet.data))
00041 
00042     def testInvokeAddview(self):
00043         portlet = getUtility(IPortletType, name='portlets.Classic')
00044         mapping = self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
00045         for m in mapping.keys():
00046             del mapping[m]
00047         addview = mapping.restrictedTraverse('+/' + portlet.addview)
00048 
00049         addview.createAndAdd(data={})
00050 
00051         self.assertEquals(len(mapping), 1)
00052         self.failUnless(isinstance(mapping.values()[0], classic.Assignment))
00053 
00054     def testInvokeEditView(self):
00055         mapping = PortletAssignmentMapping()
00056         request = self.folder.REQUEST
00057 
00058         mapping['foo'] = classic.Assignment(template='portlet_recent', macro='portlet')
00059         editview = getMultiAdapter((mapping['foo'], request), name='edit')
00060         self.failUnless(isinstance(editview, classic.EditForm))
00061 
00062     def testRenderer(self):
00063         context = self.folder
00064         request = self.folder.REQUEST
00065         view = self.folder.restrictedTraverse('@@plone')
00066         manager = getUtility(IPortletManager, name='plone.leftcolumn', context=self.portal)
00067         assignment = classic.Assignment(template='portlet_recent', macro='portlet')
00068 
00069         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00070         self.failUnless(isinstance(renderer, classic.Renderer))
00071 
00072 class TestRenderer(PortletsTestCase):
00073 
00074     def afterSetUp(self):
00075         setHooks()
00076         setSite(self.portal)
00077 
00078     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00079         context = context or self.folder
00080         request = request or self.folder.REQUEST
00081         view = view or self.folder.restrictedTraverse('@@plone')
00082         manager = manager or getUtility(IPortletManager, name='plone.leftcolumn', context=self.portal)
00083         assignment = assignment or classic.Assignment(template='portlet_recent', macro='portlet')
00084 
00085         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00086 
00087     def testUseMacro(self):
00088         r = self.renderer(assignment=classic.Assignment(template='portlet_recent', macro='portlet'))
00089         self.assertEquals(True, r.use_macro())
00090         r = self.renderer(assignment=classic.Assignment(template='portlet_recent', macro=None))
00091         self.assertEquals(False, r.use_macro())
00092 
00093     def testPathExpression(self):
00094         r = self.renderer(assignment=classic.Assignment(template='portlet_recent', macro='portlet'))
00095         self.assertEquals('context/portlet_recent/macros/portlet', r.path_expression())
00096         r = self.renderer(assignment=classic.Assignment(template='portlet_recent', macro=None))
00097         self.assertEquals('context/portlet_recent', r.path_expression())
00098 
00099 def test_suite():
00100     from unittest import TestSuite, makeSuite
00101     suite = TestSuite()
00102     suite.addTest(makeSuite(TestPortlet))
00103     suite.addTest(makeSuite(TestRenderer))
00104     return suite