Back to index

plone3  3.1.7
test_Calendar.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for CalendarTool module.
00014 
00015 $Id: test_Calendar.py 76729 2007-06-17 14:08:32Z yuppie $
00016 """
00017 
00018 import unittest
00019 from Testing import ZopeTestCase
00020 ZopeTestCase.utils.setupCoreSessions()
00021 
00022 import locale
00023 
00024 from AccessControl.SecurityManagement import newSecurityManager
00025 from AccessControl.User import UnrestrictedUser
00026 from DateTime import DateTime
00027 from zope.app.component.hooks import setSite
00028 
00029 from Products.CMFCalendar.testing import FunctionalLayer
00030 
00031 
00032 class CalendarTests(unittest.TestCase):
00033 
00034     def _getTargetClass(self):
00035         from Products.CMFCalendar.CalendarTool import CalendarTool
00036 
00037         return CalendarTool
00038 
00039     def _makeOne(self, *args, **kw):
00040         return self._getTargetClass()(*args, **kw)
00041 
00042     def test_z3interfaces(self):
00043         from zope.interface.verify import verifyClass
00044         from Products.CMFCalendar.interfaces import ICalendarTool
00045 
00046         verifyClass(ICalendarTool, self._getTargetClass())
00047 
00048     def test_new(self):
00049         ctool = self._makeOne()
00050         self.assertEqual( ctool.getId(), 'portal_calendar' )
00051 
00052     def test_types(self):
00053         ctool = self._makeOne()
00054         self.assertEqual(ctool.getCalendarTypes(), ('Event',))
00055 
00056         ctool.edit_configuration(show_types=['Event','Party'],
00057                                  show_states=[],
00058                                  use_session="")
00059         self.assertEqual( ctool.getCalendarTypes(), ('Event', 'Party') )
00060 
00061     def test_states(self):
00062         ctool = self._makeOne()
00063         self.assertEqual(ctool.getCalendarStates(), ('published',))
00064 
00065         ctool.edit_configuration(show_types=[],
00066                                  show_states=['pending', 'published'],
00067                                  use_session="")
00068         self.assertEqual( ctool.getCalendarStates(), ('pending', 'published') )
00069 
00070     def test_days(self):
00071         ctool = self._makeOne()
00072         old_locale = locale.getlocale(locale.LC_ALL)[0]
00073         locale.setlocale(locale.LC_ALL, 'C')
00074         try:
00075             self.assertEqual( ctool.getDays(),
00076                               ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] )
00077         finally:
00078             locale.setlocale(locale.LC_ALL, old_locale)
00079 
00080     def test_firstweekday(self):
00081         ctool = self._makeOne()
00082         ctool.firstweekday = 6
00083         self.assertEqual(ctool.getFirstWeekDay(), 6)
00084 
00085         # Try setting it to invalid values, the setting should not stick
00086         ctool.edit_configuration([], None, firstweekday='insane')
00087         self.assertEqual(ctool.getFirstWeekDay(), 6)
00088 
00089         ctool.edit_configuration([], None, firstweekday=42)
00090         self.assertEqual(ctool.getFirstWeekDay(), 6)
00091 
00092         # Set it to a sane value
00093         ctool.edit_configuration([], None, firstweekday=0)
00094         self.assertEqual(ctool.getFirstWeekDay(), 0)
00095 
00096         # Make sure the setting is being used...
00097         old_locale = locale.getlocale(locale.LC_ALL)[0]
00098         locale.setlocale(locale.LC_ALL, 'C')
00099         try:
00100             self.assertEqual( ctool.getDays(),
00101                               ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa','Su'] )
00102         finally:
00103             locale.setlocale(locale.LC_ALL, old_locale)
00104 
00105 
00106 class CalendarRequestTests(ZopeTestCase.FunctionalTestCase):
00107 
00108     layer = FunctionalLayer
00109 
00110     def afterSetUp(self):
00111         setSite(self.app.site)
00112         self.app.site.setupCurrentSkin(self.app.REQUEST)
00113         newSecurityManager(None, UnrestrictedUser('god', '', ['Manager'], ''))
00114 
00115         # sessioning setup
00116         sdm = self.app.session_data_manager
00117         self.app.REQUEST.set_lazy('SESSION', sdm.getSessionData)
00118 
00119     def _testURL(self, url, params=None):
00120         obj = self.app.site.restrictedTraverse(url)
00121         if params is None:
00122             params=(obj, self.app.site.REQUEST)
00123         obj(*params)
00124 
00125     def test_sessions_skinsview(self):
00126         caltool = self.app.site.portal_calendar
00127         caltool.edit_configuration(show_types=['Event'], use_session="True")
00128         self._testURL('/site/calendarBox', ())
00129 
00130         self.failUnless(self.app.REQUEST.SESSION.get('calendar_year',None))
00131 
00132     def test_sessions_fiveview(self):
00133         caltool = self.app.site.portal_calendar
00134         caltool.edit_configuration(show_types=['Event'], use_session="True")
00135         self._testURL('/site/@@calendar_widget', ())
00136 
00137         self.failUnless(self.app.REQUEST.SESSION.get('calendar_year',None))
00138 
00139     def test_noSessions_skinsview(self):
00140         caltool = self.app.site.portal_calendar
00141         caltool.edit_configuration(show_types=['Event'], use_session="")
00142         self._testURL('/site/calendarBox', ())
00143 
00144         self.failIf(self.app.REQUEST.SESSION.get('calendar_year',None))
00145 
00146     def test_noSessions_fiveview(self):
00147         caltool = self.app.site.portal_calendar
00148         caltool.edit_configuration(show_types=['Event'], use_session="")
00149         self._testURL('/site/@@calendar_widget', ())
00150 
00151         self.failIf(self.app.REQUEST.SESSION.get('calendar_year',None))
00152 
00153     def test_simpleCalendarRendering(self):
00154         caltool = self.app.site.portal_calendar
00155         data = [
00156                 [
00157                  {'day': 0, 'event': 0, 'eventslist':[]},
00158                  {'day': 0, 'event': 0, 'eventslist':[]},
00159                  {'day': 0, 'event': 0, 'eventslist':[]},
00160                  {'day': 1, 'event': 0, 'eventslist':[]},
00161                  {'day': 2, 'event': 0, 'eventslist':[]},
00162                  {'day': 3, 'event': 0, 'eventslist':[]},
00163                  {'day': 4, 'event': 0, 'eventslist':[]},
00164                  ],
00165                 [
00166                  {'day': 5, 'event': 0, 'eventslist':[]},
00167                  {'day': 6, 'event': 0, 'eventslist':[]},
00168                  {'day': 7, 'event': 0, 'eventslist':[]},
00169                  {'day': 8, 'event': 0, 'eventslist':[]},
00170                  {'day': 9, 'event': 0, 'eventslist':[]},
00171                  {'day':10, 'event': 0, 'eventslist':[]},
00172                  {'day':11, 'event': 0, 'eventslist':[]},
00173                  ],
00174                 [
00175                  {'day':12, 'event': 0, 'eventslist':[]},
00176                  {'day':13, 'event': 0, 'eventslist':[]},
00177                  {'day':14, 'event': 0, 'eventslist':[]},
00178                  {'day':15, 'event': 0, 'eventslist':[]},
00179                  {'day':16, 'event': 0, 'eventslist':[]},
00180                  {'day':17, 'event': 0, 'eventslist':[]},
00181                  {'day':18, 'event': 0, 'eventslist':[]},
00182                  ],
00183                 [
00184                  {'day':19, 'event': 0, 'eventslist':[]},
00185                  {'day':20, 'event': 0, 'eventslist':[]},
00186                  {'day':21, 'event': 0, 'eventslist':[]},
00187                  {'day':22, 'event': 0, 'eventslist':[]},
00188                  {'day':23, 'event': 0, 'eventslist':[]},
00189                  {'day':24, 'event': 0, 'eventslist':[]},
00190                  {'day':25, 'event': 0, 'eventslist':[]},
00191                  ],
00192                 [
00193                  {'day':26, 'event': 0, 'eventslist':[]},
00194                  {'day':27, 'event': 0, 'eventslist':[]},
00195                  {'day':28, 'event': 0, 'eventslist':[]},
00196                  {'day':29, 'event': 0, 'eventslist':[]},
00197                  {'day':30, 'event': 0, 'eventslist':[]},
00198                  {'day':31, 'event': 0, 'eventslist':[]},
00199                  {'day': 0, 'event': 0, 'eventslist':[]},
00200                  ]
00201                 ]
00202         result = caltool.getEventsForCalendar(month='5', year='2002')
00203         self.assertEqual(result, data)
00204 
00205     def test_singleEventCalendarRendering(self):
00206         site = self.app.site
00207         caltool = self.app.site.portal_calendar
00208         site.Members.invokeFactory(type_name="Event",id='Event1')
00209         event = self.app.restrictedTraverse('/site/Members/Event1')
00210         event.edit( title='title'
00211                     , description='description'
00212                     , eventType=( 'eventType', )
00213                     , effectiveDay=1
00214                     , effectiveMo=5
00215                     , effectiveYear=2002
00216                     , expirationDay=1
00217                     , expirationMo=5
00218                     , expirationYear=2002
00219                     , start_time="00:00"
00220                     , startAMPM="AM"
00221                     , stop_time="11:59"
00222                     , stopAMPM="PM"
00223                     )
00224         site.portal_workflow.doActionFor(event, 'publish', comment='testing')
00225 
00226         data = [
00227                 [
00228                  {'day': 0, 'event': 0, 'eventslist':[]},
00229                  {'day': 0, 'event': 0, 'eventslist':[]},
00230                  {'day': 0, 'event': 0, 'eventslist':[]},
00231                  {'day': 1, 'event': 1, 'eventslist':[{'title': 'title',
00232                                                        'end': '23:59:00',
00233                                                        'start': '00:00:00'}]},
00234                  {'day': 2, 'event': 0, 'eventslist':[]},
00235                  {'day': 3, 'event': 0, 'eventslist':[]},
00236                  {'day': 4, 'event': 0, 'eventslist':[]},
00237                  ],
00238                 [
00239                  {'day': 5, 'event': 0, 'eventslist':[]},
00240                  {'day': 6, 'event': 0, 'eventslist':[]},
00241                  {'day': 7, 'event': 0, 'eventslist':[]},
00242                  {'day': 8, 'event': 0, 'eventslist':[]},
00243                  {'day': 9, 'event': 0, 'eventslist':[]},
00244                  {'day':10, 'event': 0, 'eventslist':[]},
00245                  {'day':11, 'event': 0, 'eventslist':[]},
00246                  ],
00247                 [
00248                  {'day':12, 'event': 0, 'eventslist':[]},
00249                  {'day':13, 'event': 0, 'eventslist':[]},
00250                  {'day':14, 'event': 0, 'eventslist':[]},
00251                  {'day':15, 'event': 0, 'eventslist':[]},
00252                  {'day':16, 'event': 0, 'eventslist':[]},
00253                  {'day':17, 'event': 0, 'eventslist':[]},
00254                  {'day':18, 'event': 0, 'eventslist':[]},
00255                  ],
00256                 [
00257                  {'day':19, 'event': 0, 'eventslist':[]},
00258                  {'day':20, 'event': 0, 'eventslist':[]},
00259                  {'day':21, 'event': 0, 'eventslist':[]},
00260                  {'day':22, 'event': 0, 'eventslist':[]},
00261                  {'day':23, 'event': 0, 'eventslist':[]},
00262                  {'day':24, 'event': 0, 'eventslist':[]},
00263                  {'day':25, 'event': 0, 'eventslist':[]},
00264                  ],
00265                 [
00266                  {'day':26, 'event': 0, 'eventslist':[]},
00267                  {'day':27, 'event': 0, 'eventslist':[]},
00268                  {'day':28, 'event': 0, 'eventslist':[]},
00269                  {'day':29, 'event': 0, 'eventslist':[]},
00270                  {'day':30, 'event': 0, 'eventslist':[]},
00271                  {'day':31, 'event': 0, 'eventslist':[]},
00272                  {'day': 0, 'event': 0, 'eventslist':[]},
00273                  ]
00274                 ]
00275         result = caltool.getEventsForCalendar(month='5', year='2002')
00276         self.assertEqual(result, data)
00277 
00278     def test_eventCalendarRenderingIssue411(self):
00279         #  http://www.zope.org/Collectors/CMF/411
00280         site = self.app.site
00281         site.Members.invokeFactory(type_name="Event",id='Event1')
00282         event = self.app.restrictedTraverse('/site/Members/Event1')
00283         event.edit( title='title'
00284                     , description='description'
00285                     , eventType=( 'eventType', )
00286                     , effectiveDay=31
00287                     , effectiveMo=3
00288                     , effectiveYear=2006
00289                     , expirationDay=1
00290                     , expirationMo=4
00291                     , expirationYear=2006
00292                     , start_time="00:00"
00293                     , startAMPM="AM"
00294                     , stop_time="00:00"
00295                     , stopAMPM="AM"
00296                     )
00297         site.portal_workflow.doActionFor(event, 'publish', comment='testing')
00298 
00299         site.Members.invokeFactory(type_name="Event",id='Event2')
00300         event = self.app.restrictedTraverse('/site/Members/Event2')
00301         event.edit( title='title'
00302                     , description='description'
00303                     , eventType=( 'eventType', )
00304                     , effectiveDay=29
00305                     , effectiveMo=3
00306                     , effectiveYear=2006
00307                     , expirationDay=30
00308                     , expirationMo=3
00309                     , expirationYear=2006
00310                     , start_time="00:00"
00311                     , startAMPM="AM"
00312                     , stop_time="00:00"
00313                     , stopAMPM="AM"
00314                     )
00315         site.portal_workflow.doActionFor(event, 'publish', comment='testing')
00316 
00317         # With the bug unfixed, this raises a TypeError
00318         ignored = site.portal_calendar.catalog_getevents(2006, 3)
00319 
00320     def test_spanningEventCalendarRendering(self):
00321         site = self.app.site
00322         caltool = self.app.site.portal_calendar
00323         site.Members.invokeFactory(type_name="Event",id='Event1')
00324         event = self.app.restrictedTraverse('/site/Members/Event1')
00325         event.edit( title='title'
00326                     , description='description'
00327                     , eventType=( 'eventType', )
00328                     , effectiveDay=1
00329                     , effectiveMo=5
00330                     , effectiveYear=2002
00331                     , expirationDay=31
00332                     , expirationMo=5
00333                     , expirationYear=2002
00334                     , start_time="00:00"
00335                     , startAMPM="AM"
00336                     , stop_time="11:59"
00337                     , stopAMPM="PM"
00338                     )
00339         site.portal_workflow.doActionFor(event, 'publish', comment='testing')
00340 
00341         data = [
00342                 [
00343                  {'day': 0, 'event': 0, 'eventslist':[]},
00344                  {'day': 0, 'event': 0, 'eventslist':[]},
00345                  {'day': 0, 'event': 0, 'eventslist':[]},
00346                  {'day': 1, 'event': 1, 'eventslist':[{'title': 'title',
00347                                                        'end': None,
00348                                                        'start': '00:00:00'}]},
00349                  {'day': 2, 'event': 1, 'eventslist':[{'title': 'title',
00350                                                        'end': None,
00351                                                        'start': None}]},
00352                  {'day': 3, 'event': 1, 'eventslist':[{'title': 'title',
00353                                                        'end': None,
00354                                                        'start': None}]},
00355                  {'day': 4, 'event': 1, 'eventslist':[{'title': 'title',
00356                                                        'end': None,
00357                                                        'start': None}]},
00358                 ],
00359                 [
00360                  {'day': 5, 'event': 1, 'eventslist':[{'title': 'title',
00361                                                        'end': None,
00362                                                        'start': None}]},
00363                  {'day': 6, 'event': 1, 'eventslist':[{'title': 'title',
00364                                                        'end': None,
00365                                                        'start': None}]},
00366                  {'day': 7, 'event': 1, 'eventslist':[{'title': 'title',
00367                                                        'end': None,
00368                                                        'start': None}]},
00369                  {'day': 8, 'event': 1, 'eventslist':[{'title': 'title',
00370                                                        'end': None,
00371                                                        'start': None}]},
00372                  {'day': 9, 'event': 1, 'eventslist':[{'title': 'title',
00373                                                        'end': None,
00374                                                        'start': None}]},
00375                  {'day':10, 'event': 1, 'eventslist':[{'title': 'title',
00376                                                        'end': None,
00377                                                        'start': None}]},
00378                  {'day':11, 'event': 1, 'eventslist':[{'title': 'title',
00379                                                        'end': None,
00380                                                        'start': None}]},
00381                 ],
00382                 [
00383                  {'day':12, 'event': 1, 'eventslist':[{'title': 'title',
00384                                                        'end': None,
00385                                                        'start': None}]},
00386                  {'day':13, 'event': 1, 'eventslist':[{'title': 'title',
00387                                                        'end': None,
00388                                                        'start': None}]},
00389                  {'day':14, 'event': 1, 'eventslist':[{'title': 'title',
00390                                                        'end': None,
00391                                                        'start': None}]},
00392                  {'day':15, 'event': 1, 'eventslist':[{'title': 'title',
00393                                                        'end': None,
00394                                                        'start': None}]},
00395                  {'day':16, 'event': 1, 'eventslist':[{'title': 'title',
00396                                                        'end': None,
00397                                                        'start': None}]},
00398                  {'day':17, 'event': 1, 'eventslist':[{'title': 'title',
00399                                                        'end': None,
00400                                                        'start': None}]},
00401                  {'day':18, 'event': 1, 'eventslist':[{'title': 'title',
00402                                                        'end': None,
00403                                                        'start': None}]},
00404                 ],
00405                 [
00406                  {'day':19, 'event': 1, 'eventslist':[{'title': 'title',
00407                                                        'end': None,
00408                                                        'start': None}]},
00409                  {'day':20, 'event': 1, 'eventslist':[{'title': 'title',
00410                                                        'end': None,
00411                                                        'start': None}]},
00412                  {'day':21, 'event': 1, 'eventslist':[{'title': 'title',
00413                                                        'end': None,
00414                                                        'start': None}]},
00415                  {'day':22, 'event': 1, 'eventslist':[{'title': 'title',
00416                                                        'end': None,
00417                                                        'start': None}]},
00418                  {'day':23, 'event': 1, 'eventslist':[{'title': 'title',
00419                                                        'end': None,
00420                                                        'start': None}]},
00421                  {'day':24, 'event': 1, 'eventslist':[{'title': 'title',
00422                                                        'end': None,
00423                                                        'start': None}]},
00424                  {'day':25, 'event': 1, 'eventslist':[{'title': 'title',
00425                                                        'end': None,
00426                                                        'start': None}]},
00427                  ],
00428                 [
00429                  {'day':26, 'event': 1, 'eventslist':[{'title': 'title',
00430                                                        'end': None,
00431                                                        'start': None}]},
00432                  {'day':27, 'event': 1, 'eventslist':[{'title': 'title',
00433                                                        'end': None,
00434                                                        'start': None}]},
00435                  {'day':28, 'event': 1, 'eventslist':[{'title': 'title',
00436                                                        'end': None,
00437                                                        'start': None}]},
00438                  {'day':29, 'event': 1, 'eventslist':[{'title': 'title',
00439                                                        'end': None,
00440                                                        'start': None}]},
00441                  {'day':30, 'event': 1, 'eventslist':[{'title': 'title',
00442                                                        'end': None,
00443                                                        'start': None}]},
00444                  {'day':31, 'event': 1, 'eventslist':[{'title': 'title',
00445                                                        'end': '23:59:00',
00446                                                        'start': None}]},
00447                  {'day': 0, 'event': 0, 'eventslist':[]},
00448                 ]
00449                ]
00450         result = caltool.getEventsForCalendar(month='5', year='2002')
00451         self.assertEqual(result, data)
00452 
00453     def test_getPreviousMonth(self):
00454         caltool = self.app.site.portal_calendar
00455 
00456         self.assertEqual( caltool.getPreviousMonth(2,2002),
00457                           DateTime('2002/1/1') )
00458         self.assertEqual( caltool.getPreviousMonth(1,2002),
00459                           DateTime('2001/12/1') )
00460 
00461     def test_getNextMonth(self):
00462         caltool = self.app.site.portal_calendar
00463 
00464         self.assertEqual( caltool.getNextMonth(12,2001),
00465                           DateTime('2002/1/1') )
00466         self.assertEqual( caltool.getNextMonth(1,2002),
00467                           DateTime('2002/2/1') )
00468 
00469     def test_getBeginAndEndTimes(self):
00470         caltool = self.app.site.portal_calendar
00471 
00472         self.assertEqual( caltool.getBeginAndEndTimes(1,12,2001),
00473                           ( DateTime('2001/12/1 12:00:00AM'),
00474                             DateTime('2001/12/1 11:59:59PM') ) )
00475 
00476     def test_singleDayRendering(self):
00477         site = self.app.site
00478         caltool = self.app.site.portal_calendar
00479         wftool = self.app.site.portal_workflow
00480 
00481         site.Members.invokeFactory(type_name="Event",id='Event1')
00482         event = site.Members.Event1
00483         event.edit( title='title'
00484                     , description='description'
00485                     , eventType=( 'eventType', )
00486                     , effectiveDay=1
00487                     , effectiveMo=5
00488                     , effectiveYear=2002
00489                     , expirationDay=31
00490                     , expirationMo=5
00491                     , expirationYear=2002
00492                     , start_time="00:00"
00493                     , startAMPM="AM"
00494                     , stop_time="11:59"
00495                     , stopAMPM="PM"
00496                     )
00497         wftool.doActionFor(event, 'publish', comment='testing')
00498         events = caltool.getEventsForThisDay(thisDay=DateTime('2002/5/1'))
00499         self.assertEqual( len(events), 1 )
00500 
00501         site.Members.invokeFactory(type_name="Event",id='Event2')
00502         event = site.Members.Event2
00503         event.edit( title='title'
00504                     , description='description'
00505                     , eventType=( 'eventType', )
00506                     , effectiveDay=1
00507                     , effectiveMo=5
00508                     , effectiveYear=2002
00509                     , expirationDay=1
00510                     , expirationMo=5
00511                     , expirationYear=2002
00512                     , start_time="00:00"
00513                     , startAMPM="AM"
00514                     , stop_time="11:59"
00515                     , stopAMPM="PM"
00516                     )
00517         wftool.doActionFor(event, 'publish', comment='testing')
00518         events = caltool.getEventsForThisDay(thisDay=DateTime('2002/5/1'))
00519         self.assertEqual( len(events), 2 )
00520 
00521         site.Members.invokeFactory(type_name="Event",id='Event3')
00522         event = site.Members.Event3
00523         event.edit( title='title'
00524                     , description='description'
00525                     , eventType=( 'eventType', )
00526                     , effectiveDay=12
00527                     , effectiveMo=12
00528                     , effectiveYear=2001
00529                     , expirationDay=1
00530                     , expirationMo=5
00531                     , expirationYear=2002
00532                     , start_time="00:00"
00533                     , startAMPM="AM"
00534                     , stop_time="11:59"
00535                     , stopAMPM="PM"
00536                     )
00537         wftool.doActionFor(event, 'publish', comment='testing')
00538         events = caltool.getEventsForThisDay(thisDay=DateTime('2002/5/1'))
00539         self.assertEqual( len(events), 3 )
00540 
00541         site.Members.invokeFactory(type_name="Event",id='Event4')
00542         event = site.Members.Event4
00543         event.edit( title='title'
00544                     , description='description'
00545                     , eventType=( 'eventType', )
00546                     , effectiveDay=12
00547                     , effectiveMo=12
00548                     , effectiveYear=2001
00549                     , expirationDay=31
00550                     , expirationMo=5
00551                     , expirationYear=2002
00552                     , start_time="00:00"
00553                     , startAMPM="AM"
00554                     , stop_time="11:59"
00555                     , stopAMPM="PM"
00556                     )
00557         wftool.doActionFor(event, 'publish', comment='testing')
00558         events = caltool.getEventsForThisDay(thisDay=DateTime('2002/5/1'))
00559         self.assertEqual( len(events), 4 )
00560 
00561         site.Members.invokeFactory(type_name="Event",id='Event5')
00562         event = site.Members.Event5
00563         event.edit( title='title'
00564                     , description='description'
00565                     , eventType=( 'eventType', )
00566                     , effectiveDay=31
00567                     , effectiveMo=5
00568                     , effectiveYear=2002
00569                     , expirationDay=31
00570                     , expirationMo=5
00571                     , expirationYear=2002
00572                     , start_time="00:00"
00573                     , startAMPM="AM"
00574                     , stop_time="11:59"
00575                     , stopAMPM="PM"
00576                     )
00577         wftool.doActionFor(event, 'publish', comment='testing')
00578         events = caltool.getEventsForThisDay(thisDay=DateTime('2002/5/1'))
00579         self.assertEqual( len(events), 4 )
00580         events = caltool.getEventsForThisDay(thisDay=DateTime('2002/5/31'))
00581         self.assertEqual( len(events), 3 )
00582 
00583     def test_lastDayRendering(self):
00584         # Bug in catalog_getevents included events starting at 00:00:00
00585         # on the next day
00586         site = self.app.site
00587         site.invokeFactory('Event', id='today', title='today',
00588                            start_date='2002/05/31 23:50:00',
00589                            end_date='2002/05/31 23:59:59')
00590 
00591         site.invokeFactory('Event', id='tomorrow', title='tomorrow',
00592                            start_date='2002/06/01 00:00:00',
00593                            end_date='2002/06/01 00:10:00')
00594 
00595         site.portal_workflow.doActionFor(site.today, 'publish')
00596         site.portal_workflow.doActionFor(site.tomorrow, 'publish')
00597 
00598         # Last week of May 2002
00599         data = [
00600                {'day': 25, 'event': 0, 'eventslist':[]},
00601                {'day': 26, 'event': 0, 'eventslist':[]},
00602                {'day': 27, 'event': 0, 'eventslist':[]},
00603                {'day': 28, 'event': 0, 'eventslist':[]},
00604                {'day': 29, 'event': 0, 'eventslist':[]},
00605                {'day': 30, 'event': 0, 'eventslist':[]},
00606                {'day': 31, 'event': 1, 'eventslist':[{'start': '23:50:00',
00607                                                       'end': '23:59:59',
00608                                                       'title': 'today'}]},
00609                ]
00610 
00611         events = site.portal_calendar.catalog_getevents(2002, 5)
00612         self.assertEqual([events[e] for e in range(25, 32)], data)
00613 
00614     def test_firstDayRendering(self):
00615         # Double check it works on the other boundary as well
00616         site = self.app.site
00617         site.invokeFactory('Event', id='yesterday', title='yesterday',
00618                            start_date='2002/05/31 23:50:00',
00619                            end_date='2002/05/31 23:59:59')
00620 
00621         site.invokeFactory('Event', id='today', title='today',
00622                            start_date='2002/06/01 00:00:00',
00623                            end_date='2002/06/01 00:10:00')
00624 
00625         site.portal_workflow.doActionFor(site.yesterday, 'publish')
00626         site.portal_workflow.doActionFor(site.today, 'publish')
00627 
00628         # First week of June 2002
00629         data = [
00630                {'day': 1, 'event': 1, 'eventslist':[{'start': '00:00:00',
00631                                                      'end': '00:10:00',
00632                                                      'title': 'today'}]},
00633                {'day': 2, 'event': 0, 'eventslist':[]},
00634                {'day': 3, 'event': 0, 'eventslist':[]},
00635                {'day': 4, 'event': 0, 'eventslist':[]},
00636                {'day': 5, 'event': 0, 'eventslist':[]},
00637                {'day': 6, 'event': 0, 'eventslist':[]},
00638                {'day': 7, 'event': 0, 'eventslist':[]},
00639                ]
00640 
00641         events = site.portal_calendar.catalog_getevents(2002, 6)
00642         self.assertEqual([events[e] for e in range(1, 8)], data)
00643 
00644     def test_workflowStateRendering(self):
00645         # Calendar should return events in all of the selected workflow states
00646         site = self.app.site
00647         caltool = self.app.site.portal_calendar
00648         site.invokeFactory('Event', id='meeting',
00649                            start_date='2002/05/01 11:00:00',
00650                            end_date='2002/05/01 13:30:00')
00651 
00652         site.invokeFactory('Event', id='dinner',
00653                            start_date='2002/05/01 20:00:00',
00654                            end_date='2002/05/01 22:00:00')
00655 
00656         self.assertEqual(len(site.portal_catalog(portal_type='Event')), 2)
00657 
00658         # No published events
00659         self.assertEqual(
00660             len(caltool.getEventsForThisDay(DateTime('2002/05/01'))), 0)
00661 
00662         # One published event
00663         site.portal_workflow.doActionFor(site.meeting, 'publish')
00664         self.assertEqual(len(site.portal_catalog(review_state='published')), 1)
00665 
00666         self.assertEqual(
00667             len(caltool.getEventsForThisDay(DateTime('2002/05/01'))), 1)
00668 
00669         # One pending event
00670         site.portal_workflow.doActionFor(site.dinner, 'submit')
00671         self.assertEqual(len(site.portal_catalog(review_state='pending')), 1)
00672 
00673         self.assertEqual(
00674             len(caltool.getEventsForThisDay(DateTime('2002/05/01'))), 1)
00675 
00676         # Make calendar return pending events
00677         caltool.edit_configuration(show_types=('Event',),
00678                                    show_states=('pending', 'published'),
00679                                    use_session='')
00680 
00681         self.assertEqual(
00682             len(caltool.getEventsForThisDay(DateTime('2002/05/01'))), 2)
00683 
00684     def test_EventEndingMidnight(self):
00685         # Events ending exactly at midnight should not be shown for the day
00686         # after (see http://www.zope.org/Collectors/CMF/246)
00687         site = self.app.site
00688         caltool = self.app.site.portal_calendar
00689         the_day = DateTime('2002/05/01')
00690         day_after = DateTime('2002/05/02')
00691 
00692         site.invokeFactory('Event', id='party',
00693                            start_date=the_day,
00694                            end_date=day_after)
00695         site.portal_workflow.doActionFor(site.party, 'publish')
00696 
00697         # One entry should be present for the day of the event
00698         self.assertEqual(len(caltool.getEventsForThisDay(the_day)), 1)
00699 
00700         # No entry should be present for the day after
00701         self.assertEqual(len(caltool.getEventsForThisDay(day_after)), 0)
00702 
00703         # First week of May 2002
00704         data = [
00705                {'day': 1, 'event': 1, 'eventslist':[{'start': '00:00:00',
00706                                                      'end': '23:59:59',
00707                                                      'title': 'party'}]},
00708                {'day': 2, 'event': 0, 'eventslist':[]},
00709                {'day': 3, 'event': 0, 'eventslist':[]},
00710                {'day': 4, 'event': 0, 'eventslist':[]},
00711                {'day': 5, 'event': 0, 'eventslist':[]},
00712                {'day': 6, 'event': 0, 'eventslist':[]},
00713                {'day': 7, 'event': 0, 'eventslist':[]},
00714                ]
00715 
00716         events = caltool.catalog_getevents(2002, 5)
00717         self.assertEqual([events[e] for e in range(1, 8)], data)
00718 
00719 
00720 def test_suite():
00721     return unittest.TestSuite((
00722         unittest.makeSuite(CalendarTests),
00723         unittest.makeSuite(CalendarRequestTests),
00724         ))
00725 
00726 if __name__ == '__main__':
00727     from Products.CMFCore.testing import run
00728     run(test_suite())