Back to index

plone3  3.1.7
test_calendar_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 calendar
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.Calendar')
00026         self.assertEquals(portlet.addview, 'portlets.Calendar')
00027 
00028     def testRegisteredInterfaces(self):
00029         portlet = getUtility(IPortletType, name='portlets.Calendar')
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 = calendar.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.Calendar')
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         # This is a NullAddForm - calling it does the work
00049         addview()
00050 
00051         self.assertEquals(len(mapping), 1)
00052         self.failUnless(isinstance(mapping.values()[0], calendar.Assignment))
00053 
00054     def testRenderer(self):
00055         context = self.folder
00056         request = self.folder.REQUEST
00057         view = self.folder.restrictedTraverse('@@plone')
00058         manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00059         assignment = calendar.Assignment()
00060 
00061         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00062         self.failUnless(isinstance(renderer, calendar.Renderer))
00063 
00064 class TestRenderer(PortletsTestCase):
00065 
00066     def afterSetUp(self):
00067         setHooks()
00068         setSite(self.portal)
00069 
00070     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00071         context = context or self.folder
00072         request = request or self.folder.REQUEST
00073         view = view or self.folder.restrictedTraverse('@@plone')
00074         manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00075         assignment = assignment or calendar.Assignment()
00076 
00077         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00078 
00079     # XXX write tests
00080 
00081 def test_suite():
00082     from unittest import TestSuite, makeSuite
00083     suite = TestSuite()
00084     suite.addTest(makeSuite(TestPortlet))
00085     suite.addTest(makeSuite(TestRenderer))
00086     return suite