Back to index

plone3  3.1.7
test_rss_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 rss
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.rss')
00026         self.assertEquals(portlet.addview, 'portlets.rss')
00027 
00028     def testRegisteredInterfaces(self):
00029         portlet = getUtility(IPortletType, name='portlets.rss')
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 = rss.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.rss')
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], rss.Assignment))
00052 
00053     def testRenderer(self):
00054         context = self.folder
00055         request = self.folder.REQUEST
00056         view = self.folder.restrictedTraverse('@@plone')
00057         manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00058         assignment = rss.Assignment()
00059 
00060         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00061         self.failUnless(isinstance(renderer, rss.Renderer))
00062 
00063 class TestRenderer(PortletsTestCase):
00064 
00065     def afterSetUp(self):
00066         setHooks()
00067         setSite(self.portal)
00068 
00069     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00070         context = context or self.folder
00071         request = request or self.folder.REQUEST
00072         view = view or self.folder.restrictedTraverse('@@plone')
00073         manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00074         assignment = assignment or rss.Assignment()
00075 
00076         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00077 
00078     def test_rss_items(self):
00079         r = self.renderer(assignment=rss.Assignment())
00080         self.assertEquals(False, r.enabled)
00081 
00082 def test_suite():
00083     from unittest import TestSuite, makeSuite
00084     suite = TestSuite()
00085     suite.addTest(makeSuite(TestPortlet))
00086     suite.addTest(makeSuite(TestRenderer))
00087     return suite