From 33ad44bc97f08df71f227f6f2a006e770a75c353 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 1 Apr 2011 18:51:29 -0400 Subject: * Re-organize the interface between buildout.cfg and the zope.testing layer initialization. buildout.cfg is now really simple; it calls one method. That method does all the relevant layer initializations. This better localizes what has to be set up before testing can even begin. * IUsers now have a created_on property which contains the datetime at which the user record was created. * Rework the date and uid factories so that they consult the MockAndMonkeyLayer for the current testing flag. Also, those factories register themselves with the layer so that they'll get automatically reset between tests, without the layer actually having to know about them. * Move the User model object initialization into User.__init__() from the user manager. The User now also adds itself to the store. * Add a 'uid factory' for unique id creation, which is test suite aware. --- src/mailman/utilities/datetime.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/mailman/utilities/datetime.py') diff --git a/src/mailman/utilities/datetime.py b/src/mailman/utilities/datetime.py index 7e727346d..9dcd21f1e 100644 --- a/src/mailman/utilities/datetime.py +++ b/src/mailman/utilities/datetime.py @@ -36,25 +36,27 @@ __all__ = [ import datetime +from mailman.testing.layers import MockAndMonkeyLayer + class DateFactory: """A factory for today() and now() that works with testing.""" - # Set to True to produce predictable dates and times. - testing_mode = False # The predictable time. predictable_now = None predictable_today = None def now(self, tz=None): + # We can't automatically fast-forward because some tests require us to + # stay on the same day for a while, e.g. autorespond.txt. return (self.predictable_now - if self.testing_mode + if MockAndMonkeyLayer.testing_mode else datetime.datetime.now(tz)) def today(self): return (self.predictable_today - if self.testing_mode + if MockAndMonkeyLayer.testing_mode else datetime.date.today()) @classmethod @@ -72,3 +74,4 @@ factory = DateFactory() factory.reset() today = factory.today now = factory.now +MockAndMonkeyLayer.register_reset(factory.reset) -- cgit v1.2.3-70-g09d2