Back to index

plone3  3.1.7
testRecentView.py
Go to the documentation of this file.
00001 #
00002 # Test the RecentPortlet View
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 
00007 # BBB Plone 4.0
00008 import warnings
00009 showwarning = warnings.showwarning
00010 warnings.showwarning = lambda *a, **k: None
00011 # ignore deprecation warnings on import
00012 from Products.CMFPlone.browser.interfaces import IRecentPortlet
00013 from Products.CMFPlone.browser.portlets.recent import RecentPortlet
00014 # restore warning machinery
00015 warnings.showwarning = showwarning
00016 
00017 
00018 class TestRecentPortletView(PloneTestCase.PloneTestCase):
00019 
00020     def afterSetUp(self):
00021         self.url = self.portal.portal_url
00022         #self.recent = self.portal.recent
00023         self.workflow = self.portal.portal_workflow
00024         self.setupAuthenticator()
00025 
00026     def testImplementsIRecentPortlet(self):
00027         """RecentPortlet must implement IRecentPortlet"""
00028         self.failUnless(IRecentPortlet.implementedBy(RecentPortlet))
00029 
00030     def testRecentResults(self):
00031         """RecentPortlet.results() must return recently updated content"""
00032         self.portal.portal_catalog.manage_catalogClear()
00033         self.setRoles(['Manager'])
00034         self.folder.invokeFactory('Document', id='testpage', text='data', title='Foo')
00035         self.workflow.doActionFor(self.folder.testpage, 'publish')
00036         view = RecentPortlet(self.portal, self.app.REQUEST)
00037         result = view.results()
00038         self.failUnlessEqual(len(result), 1)
00039         self.failUnlessEqual(result[0].getId, 'testpage')
00040 
00041     def testNoRecent(self):
00042         """RecentPortlet.results() must return no content when no recent items"""
00043            # clear out the catalog to guarantee no results
00044         self.portal.portal_catalog.manage_catalogClear()
00045         view = RecentPortlet(self.portal, self.app.REQUEST)
00046         result = view.results()
00047         return result
00048         self.failUnlessEqual(len(result), 0)
00049 
00050     def testRecentResultsPrivate(self):
00051         """RecentPortlet.results() must return private items"""
00052         self.portal.portal_catalog.manage_catalogClear()
00053         self.setRoles(['Manager'])
00054         self.folder.invokeFactory('Document', id='testpage', text='data', title='Foo')
00055         self.workflow.doActionFor(self.folder.testpage, 'hide')
00056         view = RecentPortlet(self.portal, self.app.REQUEST)
00057         result = view.results()
00058         self.failUnlessEqual(len(result), 1)
00059         self.failUnlessEqual(result[0].getId, 'testpage')
00060 
00061     def testRecentResultsPublicDraft(self):
00062         """RecentPortlet.results() must return public draft items"""
00063         self.portal.portal_catalog.manage_catalogClear()
00064         self.setRoles(['Manager'])
00065         self.folder.invokeFactory('Document', id='testpage', text='data', title='Foo')
00066         view = RecentPortlet(self.portal, self.app.REQUEST)
00067         result = view.results()
00068         self.failUnlessEqual(len(result), 1)
00069         self.failUnlessEqual(result[0].getId, 'testpage')
00070 
00071 
00072 def test_suite():
00073     from unittest import TestSuite, makeSuite
00074     suite = TestSuite()
00075     suite.addTest(makeSuite(TestRecentPortletView))
00076     return suite
00077