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

Tres Seaver tseaver at palladion.com
Mon Apr 9 15:39:52 EDT 2007


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

Changed:
  U   CMF/branches/2.0/CHANGES.txt
  U   CMF/branches/2.0/CMFCalendar/tests/test_Event.py
  U   CMF/branches/2.0/CMFCore/interfaces/_content.py
  U   CMF/branches/2.0/CMFDefault/DublinCore.py
  U   CMF/branches/2.0/CMFDefault/tests/test_DublinCore.py

-=-
Modified: CMF/branches/2.0/CHANGES.txt
===================================================================
--- CMF/branches/2.0/CHANGES.txt	2007-04-09 19:37:51 UTC (rev 74056)
+++ CMF/branches/2.0/CHANGES.txt	2007-04-09 19:39:51 UTC (rev 74057)
@@ -2,6 +2,11 @@
 
   Bug Fixes
 
+    - Fixed DST-driven test breakage in CMFCalendar by adding an optional
+      'zone' argument to the DublineCore methods which return string
+      rednitions of date metadata.
+     (http://www.zope.org/Collectors/CMF/476)
+
     - Fixed test failures due to changes in TALES expression parsing under
       Zope 2.10.
 

Modified: CMF/branches/2.0/CMFCalendar/tests/test_Event.py
===================================================================
--- CMF/branches/2.0/CMFCalendar/tests/test_Event.py	2007-04-09 19:37:51 UTC (rev 74056)
+++ CMF/branches/2.0/CMFCalendar/tests/test_Event.py	2007-04-09 19:39:51 UTC (rev 74057)
@@ -119,8 +119,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
@@ -153,8 +153,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, '' )
@@ -176,8 +176,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/branches/2.0/CMFCore/interfaces/_content.py
===================================================================
--- CMF/branches/2.0/CMFCore/interfaces/_content.py	2007-04-09 19:37:51 UTC (rev 74056)
+++ CMF/branches/2.0/CMFCore/interfaces/_content.py	2007-04-09 19:39:51 UTC (rev 74057)
@@ -271,45 +271,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/branches/2.0/CMFDefault/DublinCore.py
===================================================================
--- CMF/branches/2.0/CMFDefault/DublinCore.py	2007-04-09 19:37:51 UTC (rev 74056)
+++ CMF/branches/2.0/CMFDefault/DublinCore.py	2007-04-09 19:39:51 UTC (rev 74057)
@@ -189,44 +189,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/branches/2.0/CMFDefault/tests/test_DublinCore.py
===================================================================
--- CMF/branches/2.0/CMFDefault/tests/test_DublinCore.py	2007-04-09 19:37:51 UTC (rev 74056)
+++ CMF/branches/2.0/CMFDefault/tests/test_DublinCore.py	2007-04-09 19:39:51 UTC (rev 74057)
@@ -200,7 +200,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 TestSuite((
         makeSuite( DublinCoreTests ),



More information about the CMF-checkins mailing list