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/testing/layers.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/mailman/testing/layers.py') diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py index 353dd9edd..2e765ea3e 100644 --- a/src/mailman/testing/layers.py +++ b/src/mailman/testing/layers.py @@ -48,7 +48,6 @@ from mailman.core.logging import get_handler from mailman.interfaces.domain import IDomainManager from mailman.testing.helpers import TestableMaster, reset_the_world from mailman.testing.mta import ConnectionCountingController -from mailman.utilities.datetime import factory from mailman.utilities.string import expand @@ -60,17 +59,20 @@ NL = '\n' class MockAndMonkeyLayer: """Layer for mocking and monkey patching for testing.""" - @classmethod - def setUp(cls): - factory.testing_mode = True + # Set this to True to enable predictable datetimes, uids, etc. + testing_mode = False - @classmethod - def tearDown(cls): - factory.testing_mode = False + # A registration of all testing factories, for resetting between tests. + _resets = [] @classmethod def testTearDown(cls): - factory.reset() + for reset in cls._resets: + reset() + + @classmethod + def register_reset(cls, reset): + cls._resets.append(reset) -- cgit v1.2.3-70-g09d2