[CMF-checkins] SVN: CMF/branches/2.1/CMFTopic/ Remove race
conditions when testing date-based criteria.
Tres Seaver
tseaver at palladion.com
Tue May 8 11:56:27 EDT 2007
Log message for revision 75625:
Remove race conditions when testing date-based criteria.
Changed:
U CMF/branches/2.1/CMFTopic/DateCriteria.py
U CMF/branches/2.1/CMFTopic/tests/test_DateC.py
-=-
Modified: CMF/branches/2.1/CMFTopic/DateCriteria.py
===================================================================
--- CMF/branches/2.1/CMFTopic/DateCriteria.py 2007-05-08 13:43:23 UTC (rev 75624)
+++ CMF/branches/2.1/CMFTopic/DateCriteria.py 2007-05-08 15:56:26 UTC (rev 75625)
@@ -27,6 +27,7 @@
from permissions import View
from Topic import Topic
+_as_of = DateTime # Allow for controlled value when testing
class FriendlyDateCriterion( AbstractCriterion ):
@@ -131,7 +132,8 @@
elif operation == 'min':
operation = 'max'
- date = DateTime() + value
+ now = _as_of()
+ date = now + value
if operation == 'within_day':
# When items within a day are requested, the range is between
@@ -142,7 +144,7 @@
elif operation == 'min':
if value != 0:
if self.daterange == 'old':
- date_range = (date, DateTime())
+ date_range = (date, now)
return ( ( field, { 'query': date_range
, 'range': 'min:max'
} ), )
@@ -159,7 +161,7 @@
if self.daterange == 'old':
return ((field, {'query': date, 'range': operation}),)
else:
- date_range = (DateTime(), date.latestTime())
+ date_range = (now, date.latestTime())
return ( ( field, { 'query': date_range
, 'range': 'min:max'
} ), )
Modified: CMF/branches/2.1/CMFTopic/tests/test_DateC.py
===================================================================
--- CMF/branches/2.1/CMFTopic/tests/test_DateC.py 2007-05-08 13:43:23 UTC (rev 75624)
+++ CMF/branches/2.1/CMFTopic/tests/test_DateC.py 2007-05-08 15:56:26 UTC (rev 75625)
@@ -27,7 +27,13 @@
from common import CriterionTestCase
+def _replace_DC__as_of(new_callable):
+ from Products.CMFTopic import DateCriteria
+ old_value = DateCriteria._as_of
+ DateCriteria._as_of = new_callable
+ return old_value
+
class FriendlyDateCriterionTests(CriterionTestCase):
lessThanFiveDaysOld = { 'value': 5
@@ -44,6 +50,13 @@
, 'daterange': 'ahead'
}
+ def setUp(self):
+ self._now = DateTime()
+ self._old_as_of = _replace_DC__as_of(lambda: self._now)
+
+ def tearDown(self):
+ _replace_DC__as_of(self._old_as_of)
+
def _getTargetClass(self):
from Products.CMFTopic.DateCriteria import FriendlyDateCriterion
@@ -171,6 +184,7 @@
type_crit.edit(value='Dummy Content')
self.criterion = self.topic.getCriterion('modified')
self.now = DateTime()
+ self._old_as_of = _replace_DC__as_of(lambda: self.now)
for i in self.day_diffs:
dummy_id = 'dummy%i' % i
@@ -181,6 +195,9 @@
dummy_ob.modified_date = self.now + i
dummy_ob.reindexObject()
+ def beforeTearDown(self):
+ _replace_DC__as_of(self._old_as_of)
+
def test_Harness(self):
# Make sure the test harness is set up OK
ob_values = self.site.objectValues(['Dummy'])
More information about the CMF-checkins
mailing list