[CMF-checkins] SVN: CMF/trunk/CMF Issue #476: fix test breakage due to Zope timezone shift.

Tres Seaver tseaver at palladion.com
Mon Apr 9 15:58:21 EDT 2007


Log message for revision 74059:
  Issue #476: fix test breakage due to Zope timezone shift.

Changed:
  U   CMF/trunk/CMFCalendar/tests/test_Event.py
  U   CMF/trunk/CMFCore/interfaces/_content.py
  U   CMF/trunk/CMFDefault/DublinCore.py
  U   CMF/trunk/CMFDefault/tests/test_DublinCore.py

-=-
Modified: CMF/trunk/CMFCalendar/tests/test_Event.py
===================================================================
--- CMF/trunk/CMFCalendar/tests/test_Event.py	2007-04-09 19:40:38 UTC (rev 74058)
+++ CMF/trunk/CMFCalendar/tests/test_Event.py	2007-04-09 19:58:19 UTC (rev 74059)
@@ -92,8 +92,8 @@
 Title: Test Event
 Subject: Foosubject
 Contributors: Jim
-Effective_date: 2002/01/01
-Expiration_date: 2009/12/31
+Effective_date: 2002-01-01T00:00:00Z
+Expiration_date: 2009-12-31T00:00:00Z
 StartDate: 2006/02/23 18:00
 EndDate: 2006/02/23 23:00
 Location: Spuds and Suds, River Street, Anytown
@@ -126,8 +126,8 @@
         self.assertEqual( d.Description(), '' )
         self.assertEqual( d.Subject(), () )
         self.assertEqual( d.Contributors(), () )
-        self.assertEqual( d.EffectiveDate(), 'None' )
-        self.assertEqual( d.ExpirationDate(), 'None' )
+        self.assertEqual( d.EffectiveDate('UTC'), 'None' )
+        self.assertEqual( d.ExpirationDate('UTC'), 'None' )
         self.assertEqual( d.Language(), '' )
         self.assertEqual( d.Rights(), '' )
         self.assertEqual( d.location, '' )
@@ -149,8 +149,8 @@
                         )
         self.assertEqual( d.Subject(), ('Foosubject',) )
         self.assertEqual( d.Contributors(), ('Jim',) )
-        self.assertEqual( d.EffectiveDate(), '2002-01-01 00:00:00' )
-        self.assertEqual( d.ExpirationDate(), '2009-12-31 00:00:00' )
+        self.assertEqual( d.EffectiveDate('UTC'), '2002-01-01 00:00:00' )
+        self.assertEqual( d.ExpirationDate('UTC'), '2009-12-31 00:00:00' )
         self.assertEqual( d.Language(), 'French' )
         self.assertEqual( d.Rights(), 'Anytown Gazetteer' )
         self.assertEqual( d.location, 'Spuds and Suds, River Street, Anytown' )

Modified: CMF/trunk/CMFCore/interfaces/_content.py
===================================================================
--- CMF/trunk/CMFCore/interfaces/_content.py	2007-04-09 19:40:38 UTC (rev 74058)
+++ CMF/trunk/CMFCore/interfaces/_content.py	2007-04-09 19:58:19 UTC (rev 74059)
@@ -270,45 +270,60 @@
         o 'initial caps' names are reserved for strings.
         """
 
-    def Date():
+    def Date(zone=None):
         """ Return the DCMI Date element (default resource date).
 
         o Result is a string, formatted 'YYYY-MM-DD H24:MN:SS TZ'.
 
+        o If 'zone' is 'None', return the time in the system default
+          timezone.
+
         o Permission:  View
         """
 
-    def CreationDate():
+    def CreationDate(zone=None):
         """ Return the DCMI Date element (date resource created).
 
         o Result is a string, formatted 'YYYY-MM-DD H24:MN:SS TZ'.
 
+        o If 'zone' is 'None', return the time in the system default
+          timezone.
+
         o Permission:  View
         """
 
-    def EffectiveDate():
+    def EffectiveDate(zone=None):
         """ Return the DCMI Date element (date resource becomes effective).
 
         o Result is a string, formatted 'YYYY-MM-DD H24:MN:SS TZ', or
           None.
 
+        o If 'zone' is 'None', return the time in the system default
+          timezone.
+
         o Permission:  View
         """
 
-    def ExpirationDate():
+    def ExpirationDate(zone=None):
         """ Return the DCMI Date element (date resource expires).
 
         o Result is a string, formatted 'YYYY-MM-DD H24:MN:SS TZ', or
           None.
 
+        o If 'zone' is 'None', return the time in the system default
+          timezone.
+
         o Permission:  View
         """
 
-    def ModificationDate():
+    def ModificationDate(zone=None):
         """ DCMI Date element - date resource last modified.
 
         o Result is a string, formatted 'YYYY-MM-DD H24:MN:SS TZ'.
 
+        o If 'zone' is 'None', return the time in the system default
+          timezone.
+
         o Permission:  View
         """
 

Modified: CMF/trunk/CMFDefault/DublinCore.py
===================================================================
--- CMF/trunk/CMFDefault/DublinCore.py	2007-04-09 19:40:38 UTC (rev 74058)
+++ CMF/trunk/CMFDefault/DublinCore.py	2007-04-09 19:58:19 UTC (rev 74059)
@@ -183,44 +183,54 @@
         return self.listContributors()
 
     security.declareProtected(View, 'Date')
-    def Date( self ):
+    def Date( self, zone=None ):
         """ Dublin Core Date element - default date.
         """
+        if zone is None:
+            zone = _zone
         # Return effective_date if set, modification date otherwise
         date = getattr(self, 'effective_date', None )
         if date is None:
             date = self.modified()
-        return date.toZone(_zone).ISO()
+        return date.toZone(zone).ISO()
 
     security.declareProtected(View, 'CreationDate')
-    def CreationDate( self ):
+    def CreationDate( self, zone=None ):
         """ Dublin Core Date element - date resource created.
         """
+        if zone is None:
+            zone = _zone
         # return unknown if never set properly
         if self.creation_date:
-            return self.creation_date.toZone(_zone).ISO()
+            return self.creation_date.toZone(zone).ISO()
         else:
             return 'Unknown'
 
     security.declareProtected(View, 'EffectiveDate')
-    def EffectiveDate( self ):
+    def EffectiveDate( self, zone=None ):
         """ Dublin Core Date element - date resource becomes effective.
         """
+        if zone is None:
+            zone = _zone
         ed = getattr( self, 'effective_date', None )
-        return ed and ed.toZone(_zone).ISO() or 'None'
+        return ed and ed.toZone(zone).ISO() or 'None'
 
     security.declareProtected(View, 'ExpirationDate')
-    def ExpirationDate( self ):
+    def ExpirationDate( self, zone=None ):
         """ Dublin Core Date element - date resource expires.
         """
+        if zone is None:
+            zone = _zone
         ed = getattr( self, 'expiration_date', None )
-        return ed and ed.toZone(_zone).ISO() or 'None'
+        return ed and ed.toZone(zone).ISO() or 'None'
 
     security.declareProtected(View, 'ModificationDate')
-    def ModificationDate( self ):
+    def ModificationDate( self, zone=None ):
         """ Dublin Core Date element - date resource last modified.
         """
-        return self.modified().toZone(_zone).ISO()
+        if zone is None:
+            zone = _zone
+        return self.modified().toZone(zone).ISO()
 
     security.declareProtected(View, 'Type')
     def Type( self ):

Modified: CMF/trunk/CMFDefault/tests/test_DublinCore.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_DublinCore.py	2007-04-09 19:40:38 UTC (rev 74058)
+++ CMF/trunk/CMFDefault/tests/test_DublinCore.py	2007-04-09 19:58:19 UTC (rev 74059)
@@ -196,7 +196,36 @@
             new_DC = getattr(item, dc_methodname)()
             self.assertEqual(orig_DC, new_DC)
 
+    def test_Date_with_explicit_timezone(self):
+        item = self._makeDummyContent('item')
+        item.effective_date = DateTime('2007-01-01T12:00:00Z')
+        self.assertEqual(item.Date('US/Eastern'),
+                         '2007-01-01 07:00:00')
 
+    def test_CreationDate_with_explicit_timezone(self):
+        item = self._makeDummyContent('item')
+        item.creation_date = DateTime('2007-01-01T12:00:00Z')
+        self.assertEqual(item.CreationDate('US/Eastern'),
+                         '2007-01-01 07:00:00')
+
+    def test_ModificationDate_with_explicit_timezone(self):
+        item = self._makeDummyContent('item')
+        item.modification_date = DateTime('2007-01-01T12:00:00Z')
+        self.assertEqual(item.ModificationDate('US/Eastern'),
+                         '2007-01-01 07:00:00')
+
+    def test_EffectiveDate_with_explicit_timezone(self):
+        item = self._makeDummyContent('item')
+        item.effective_date = DateTime('2007-01-01T12:00:00Z')
+        self.assertEqual(item.EffectiveDate('US/Eastern'),
+                         '2007-01-01 07:00:00')
+
+    def test_ExpirationDate_with_explicit_timezone(self):
+        item = self._makeDummyContent('item')
+        item.expiration_date = DateTime('2007-01-01T12:00:00Z')
+        self.assertEqual(item.ExpirationDate('US/Eastern'),
+                         '2007-01-01 07:00:00')
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(DublinCoreTests),



More information about the CMF-checkins mailing list