Back to index

plone3  3.1.7
testNewsPortletView.py
Go to the documentation of this file.
00001 #
00002 # Tests the NewsPortlet 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 INewsPortlet
00013 from Products.CMFPlone.browser.portlets.news import NewsPortlet
00014 # restore warning machinery
00015 warnings.showwarning = showwarning
00016 
00017 
00018 class TestNewsPortletView(PloneTestCase.PloneTestCase):
00019 
00020     def afterSetUp(self):
00021         self.url = self.portal.portal_url
00022         self.news = self.portal.news
00023         self.workflow = self.portal.portal_workflow
00024         self.setupAuthenticator()
00025 
00026     def testImplementsINewsPortlet(self):
00027         """NewsPortlet must implement INewsPortlet"""
00028         self.failUnless(INewsPortlet.implementedBy(NewsPortlet))
00029 
00030     def testNewsItems(self):
00031         """NewsPortlet.published_news_items() must return published News Items"""
00032         self.setRoles(['Manager'])
00033         self.folder.invokeFactory('News Item', id='newsitem', text='data', title='Foo')
00034         self.workflow.doActionFor(self.folder.newsitem, 'publish')
00035         view = NewsPortlet(self.portal, self.app.REQUEST)
00036         result = view.published_news_items()
00037         self.failUnlessEqual(len(result), 1)
00038         self.failUnlessEqual(result[0].getId, 'newsitem')
00039 
00040     def testUnpublishedNewsItems(self):
00041         """NewsPortlet.published_news_items() must not return unpublished News Items"""
00042         self.folder.invokeFactory('News Item', id='newsitem', text='data', title='Foo')
00043         view = NewsPortlet(self.portal, self.app.REQUEST)
00044         result = view.published_news_items()
00045         self.failUnlessEqual(len(result), 0)
00046 
00047     def testNoNewsItems(self):
00048         """NewsPortlet.published_news_items() must return empty list if no News Items"""
00049         view = NewsPortlet(self.portal, self.app.REQUEST)
00050         result = view.published_news_items()
00051         self.failUnlessEqual(len(result), 0)
00052 
00053     def testAllNewsLink(self):
00054         """NewsPortlet.all_news_link() must return URL of 'news' folder if it exists"""
00055         view = NewsPortlet(self.portal, self.app.REQUEST)
00056         url = view.all_news_link()
00057         self.failUnlessEqual(url, self.portal.absolute_url()+'/news')
00058 
00059     def testAllNewsLinkNoNewsFolder(self):
00060         """
00061         NewsPortlet.all_news_link() must return URL of 'newslisting'
00062         template if 'news' does not exist
00063         """
00064         # We must have permission to delete objects
00065         self.setRoles(('Manager',))
00066         self.portal.manage_delObjects(['news'])
00067         view = NewsPortlet(self.portal, self.app.REQUEST)
00068         url = view.all_news_link()
00069         self.failUnlessEqual(url, self.portal.absolute_url()+'/news_listing')
00070 
00071 
00072 def test_suite():
00073     from unittest import TestSuite, makeSuite
00074     suite = TestSuite()
00075     suite.addTest(makeSuite(TestNewsPortletView))
00076     return suite