Back to index

plone3  3.1.7
test_review_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.CMFCore.utils import getToolByName
00005 from Products.GenericSetup.utils import _getDottedName
00006 
00007 from plone.portlets.interfaces import IPortletType
00008 from plone.portlets.interfaces import IPortletManager
00009 from plone.portlets.interfaces import IPortletAssignment
00010 from plone.portlets.interfaces import IPortletDataProvider
00011 from plone.portlets.interfaces import IPortletRenderer
00012 
00013 from plone.app.portlets.portlets import review
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.Review')
00027         self.assertEquals(portlet.addview, 'portlets.Review')
00028 
00029     def testRegisteredInterfaces(self):
00030         portlet = getUtility(IPortletType, name='portlets.Review')
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 = review.Assignment()
00039         self.failUnless(IPortletAssignment.providedBy(portlet))
00040         self.failUnless(IPortletDataProvider.providedBy(portlet.data))
00041 
00042     def testInvokeAddview(self):
00043         portlet = getUtility(IPortletType, name='portlets.Review')
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         # This is a NullAddForm - calling it does the work
00050         addview()
00051 
00052         self.assertEquals(len(mapping), 1)
00053         self.failUnless(isinstance(mapping.values()[0], review.Assignment))
00054 
00055     def testRenderer(self):
00056         context = self.folder
00057         request = self.folder.REQUEST
00058         view = self.folder.restrictedTraverse('@@plone')
00059         manager = getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00060         assignment = review.Assignment()
00061 
00062         renderer = getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00063         self.failUnless(isinstance(renderer, review.Renderer))
00064 
00065 class TestRenderer(PortletsTestCase):
00066 
00067     def afterSetUp(self):
00068         setHooks()
00069         setSite(self.portal)
00070         self.setRoles(['Manager'])
00071         self.portal.invokeFactory('Document', 'doc1')
00072         self.portal.invokeFactory('Document', 'doc2')
00073 
00074     def renderer(self, context=None, request=None, view=None, manager=None, assignment=None):
00075         context = context or self.folder
00076         request = request or self.folder.REQUEST
00077         view = view or self.folder.restrictedTraverse('@@plone')
00078         manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=self.portal)
00079         assignment = assignment or review.Assignment()
00080 
00081         return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)
00082 
00083     def test_review_items(self):
00084         r = self.renderer(assignment=review.Assignment())
00085         self.assertEquals(0, len(r.review_items()))
00086         wf = getToolByName(self.portal, 'portal_workflow')
00087         wf.doActionFor(self.portal.doc1, 'submit')
00088         r = self.renderer(assignment=review.Assignment())
00089         self.assertEquals(1, len(r.review_items()))
00090 
00091     def test_full_news_link(self):
00092         r = self.renderer(assignment=review.Assignment())
00093         self.failUnless(r.full_review_link().endswith('/full_review_list'))
00094 
00095 def test_suite():
00096     from unittest import TestSuite, makeSuite
00097     suite = TestSuite()
00098     suite.addTest(makeSuite(TestPortlet))
00099     suite.addTest(makeSuite(TestRenderer))
00100     return suite