Back to index

plone3  3.1.7
test_Event.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 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 Event module.
00014 
00015 $Id: test_Event.py 77186 2007-06-28 19:06:19Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from DateTime import DateTime
00022 
00023 from Products.CMFCore.testing import ConformsToContent
00024 from Products.CMFCore.tests.base.testcase import RequestTest
00025 
00026 
00027 class TestEvent(ConformsToContent, unittest.TestCase):
00028 
00029     def _getTargetClass(self):
00030         from Products.CMFCalendar.Event import Event
00031 
00032         return Event
00033 
00034     def _makeOne(self, *args, **kw):
00035         return self._getTargetClass()(*args, **kw)
00036 
00037     def test_z3interfaces(self):
00038         from zope.interface.verify import verifyClass
00039         from Products.CMFCalendar.interfaces import IEvent
00040         from Products.CMFCalendar.interfaces import IMutableEvent
00041 
00042         verifyClass(IEvent, self._getTargetClass())
00043         verifyClass(IMutableEvent, self._getTargetClass())
00044 
00045     def test_new(self):
00046         event = self._makeOne('test')
00047 
00048         self.assertEqual( event.getId(), 'test' )
00049         self.failIf( event.Title() )
00050 
00051     def test_edit(self):
00052         # Year month and day were processed in the wrong order
00053         # Also see http://collector.zope.org/CMF/202
00054         event = self._makeOne('foo')
00055         event.edit( title='title'
00056                   , description='description'
00057                   , eventType=( 'eventType', )
00058                   , effectiveDay=1
00059                   , effectiveMo=5
00060                   , effectiveYear=1999
00061                   , expirationDay=31
00062                   , expirationMo=12
00063                   , expirationYear=1999
00064                   , start_time="00:00"
00065                   , startAMPM="AM"
00066                   , stop_time="11:59"
00067                   , stopAMPM="PM"
00068                   )
00069 
00070         self.assertEqual( event.Title(), 'title' )
00071         self.assertEqual( event.Description(), 'description' )
00072         self.assertEqual( event.Subject(), ( 'eventType', ), event.Subject() )
00073         self.assertEqual( event.effective_date, None )
00074         self.assertEqual( event.expiration_date, None )
00075         self.assertEqual( event.end(), DateTime('1999/12/31 23:59') )
00076         self.assertEqual( event.start(), DateTime('1999/05/01 00:00') )
00077         self.failIf( event.contact_name )
00078 
00079     def test_puke(self):
00080         event = self._makeOne('shouldPuke')
00081 
00082         self.assertRaises( DateTime.DateError
00083                          , event.edit
00084                          , effectiveDay=31
00085                          , effectiveMo=2
00086                          , effectiveYear=1999
00087                          , start_time="00:00"
00088                          , startAMPM="AM"
00089                          )
00090 
00091 EVENT_TXT = """\
00092 Title: Test Event
00093 Subject: Foosubject
00094 Contributors: Jim
00095 Effective_date: 2002-01-01T00:00:00Z
00096 Expiration_date: 2009-12-31T00:00:00Z
00097 StartDate: 2006/02/23 18:00
00098 EndDate: 2006/02/23 23:00
00099 Location: Spuds and Suds, River Street, Anytown
00100 Language: French
00101 Rights: Anytown Gazetteer
00102 ContactName: Jim
00103 ContactEmail: jim@example.com
00104 ContactPhone: (888) 555-1212
00105 EventURL: http://www.example.com
00106 Creator: Jim
00107 
00108 Fundraiser for disabled goldfish
00109 """
00110 
00111 class EventPUTTests(RequestTest):
00112 
00113     def _makeOne(self, id, *args, **kw):
00114         from Products.CMFCalendar.Event import Event
00115 
00116         # NullResource.PUT calls the PUT method on the bare object!
00117         return Event(id, *args, **kw)
00118 
00119     def test_PutWithoutMetadata(self):
00120         self.REQUEST['BODY'] = ''
00121         d = self._makeOne('foo')
00122         d.PUT(self.REQUEST, self.RESPONSE)
00123 
00124         self.assertEqual( d.Title(), '' )
00125         self.assertEqual( d.Format(), 'text/plain' )
00126         self.assertEqual( d.Description(), '' )
00127         self.assertEqual( d.Subject(), () )
00128         self.assertEqual( d.Contributors(), () )
00129         self.assertEqual( d.EffectiveDate('UTC'), 'None' )
00130         self.assertEqual( d.ExpirationDate('UTC'), 'None' )
00131         self.assertEqual( d.Language(), '' )
00132         self.assertEqual( d.Rights(), '' )
00133         self.assertEqual( d.location, '' )
00134         self.assertEqual( d.contact_name, '' )
00135         self.assertEqual( d.contact_email, '' )
00136         self.assertEqual( d.contact_phone, '' )
00137         self.assertEqual( d.event_url, '' )
00138 
00139     def test_PutWithMetadata(self):
00140         self.REQUEST['BODY'] = EVENT_TXT
00141         self.REQUEST.environ['CONTENT_TYPE'] = 'text/html'
00142         d = self._makeOne('foo')
00143         d.PUT(self.REQUEST, self.RESPONSE)
00144 
00145         self.assertEqual( d.Title(), 'Test Event' )
00146         self.assertEqual( d.Format(), 'text/html' )
00147         self.assertEqual( d.Description().strip()
00148                         , 'Fundraiser for disabled goldfish'
00149                         )
00150         self.assertEqual( d.Subject(), ('Foosubject',) )
00151         self.assertEqual( d.Contributors(), ('Jim',) )
00152         self.assertEqual( d.EffectiveDate('UTC'), '2002-01-01 00:00:00' )
00153         self.assertEqual( d.ExpirationDate('UTC'), '2009-12-31 00:00:00' )
00154         self.assertEqual( d.Language(), 'French' )
00155         self.assertEqual( d.Rights(), 'Anytown Gazetteer' )
00156         self.assertEqual( d.location, 'Spuds and Suds, River Street, Anytown' )
00157         self.assertEqual( d.contact_name, 'Jim' )
00158         self.assertEqual( d.contact_email, 'jim@example.com' )
00159         self.assertEqual( d.contact_phone, '(888) 555-1212' )
00160         self.assertEqual( d.event_url, 'http://www.example.com' )
00161         self.assertEqual( d.start(), DateTime('2006/02/23 18:00') )
00162         self.assertEqual( d.end(), DateTime('2006/02/23 23:00') )
00163 
00164 
00165 def test_suite():
00166     return unittest.TestSuite((
00167         unittest.makeSuite(TestEvent),
00168         unittest.makeSuite(EventPUTTests),
00169         ))
00170 
00171 if __name__ == '__main__':
00172     unittest.main(defaultTest='test_suite')