Back to index

plone3  3.1.7
testCalendarView.py
Go to the documentation of this file.
00001 # Tests the CalendarPortlet View
00002 #
00003 
00004 from Products.CMFPlone.tests import PloneTestCase
00005 
00006 from Products.CMFPlone.tests.PloneTestCase import default_user
00007 from Products.CMFPlone.tests.PloneTestCase import default_password
00008 
00009 from DateTime import DateTime
00010 
00011 from Products.ATContentTypes.tests.utils import FakeRequestSession
00012 
00013 # BBB Plone 4.0
00014 import warnings
00015 showwarning = warnings.showwarning
00016 warnings.showwarning = lambda *a, **k: None
00017 # ignore deprecation warnings on import
00018 from Products.CMFPlone.browser.interfaces import ICalendarPortlet
00019 from Products.CMFPlone.browser.portlets.calendar import CalendarPortlet
00020 # restore warning machinery
00021 warnings.showwarning = showwarning
00022 
00023 
00024 class TestCalendarPortletView(PloneTestCase.PloneTestCase):
00025 
00026     def afterSetUp(self):
00027         self.url = self.portal.portal_url
00028         self.calendar = self.portal.portal_calendar
00029         self.now = DateTime()
00030 
00031     def testImplementsICalendarPortlet(self):
00032         """CalendarPortlet must implement ICalendarPortlet"""
00033         self.failUnless(ICalendarPortlet.implementedBy(CalendarPortlet))
00034 
00035     def testGetYearAndMonthToDisplay(self):
00036         """CalendarPortlet.getYearAndMonthToDisplay() must return the current
00037            year and month.
00038         """
00039         view = CalendarPortlet(self.portal, self.app.REQUEST)
00040         result = view.getYearAndMonthToDisplay()
00041         self.failUnlessEqual(result, (self.now.year(), self.now.month()))
00042         
00043     def testGetYearAndMonthToDisplayRequest(self):
00044         """CalendarPortlet.getYearAndMonthToDisplay() must return the year and
00045            month found in REQUEST variables.
00046         """
00047         self.app.REQUEST['year'] = 2005
00048         self.app.REQUEST['month'] = 7
00049         view = CalendarPortlet(self.portal, self.app.REQUEST)
00050         result = view.getYearAndMonthToDisplay()
00051         self.failUnlessEqual(result, (2005, 7))
00052 
00053     def testGetYearAndMonthToDisplaySession(self):
00054         """CalendarPortlet.getYearAndMonthToDisplay() must return the year and
00055            month found in SESSION variables if this is enables in the calendar
00056            tool.
00057         """
00058         usesession = self.calendar.getUseSession()
00059         self.app.REQUEST['SESSION'] = FakeRequestSession()
00060         self.app.REQUEST['SESSION']['calendar_year'] = 2004
00061         self.app.REQUEST['SESSION']['calendar_month'] = 6
00062         
00063         # Ignore the session variables and use the current date
00064         self.calendar.use_session = False
00065         view = CalendarPortlet(self.portal, self.app.REQUEST)
00066         result = view.getYearAndMonthToDisplay()
00067         self.failUnlessEqual(result, (self.now.year(), self.now.month()))
00068         
00069         # Use the session variables
00070         self.calendar.use_session = True
00071         view = CalendarPortlet(self.portal, self.app.REQUEST)
00072         result = view.getYearAndMonthToDisplay()
00073         self.failUnlessEqual(result, (2004, 6))
00074         
00075         # Restore the orginal value
00076         self.calendar.use_session = usesession
00077 
00078     def testGetPreviousMonth(self):
00079         view = CalendarPortlet(self.portal, self.app.REQUEST)
00080         result = view.getPreviousMonth(12, 2006)
00081         self.failUnlessEqual(result, DateTime(2006, 11, 1))
00082         
00083         result = view.getPreviousMonth(1, 2006)
00084         self.failUnlessEqual(result, DateTime(2005, 12, 1))
00085 
00086     def testGetNextMonth(self):
00087         view = CalendarPortlet(self.portal, self.app.REQUEST)
00088         result = view.getNextMonth(12, 2006)
00089         self.failUnlessEqual(result, DateTime(2007, 1, 1))
00090         
00091         result = view.getNextMonth(1, 2006)
00092         self.failUnlessEqual(result, DateTime(2006, 2, 1))
00093 
00094     def testIsToday(self):
00095         view = CalendarPortlet(self.portal, self.app.REQUEST)
00096         self.failUnless(view.isToday(self.now.day()))
00097 
00098 
00099 def test_suite():
00100     from unittest import TestSuite, makeSuite
00101     suite = TestSuite()
00102     suite.addTest(makeSuite(TestCalendarPortletView))
00103     return suite