diff --git a/registrasion/tests/patch_datetime.py b/registrasion/tests/patches.py similarity index 53% rename from registrasion/tests/patch_datetime.py rename to registrasion/tests/patches.py index 8b64b606..7d7cd66c 100644 --- a/registrasion/tests/patch_datetime.py +++ b/registrasion/tests/patches.py @@ -1,5 +1,6 @@ from django.utils import timezone +from registrasion.contrib import mail class SetTimeMixin(object): ''' Patches timezone.now() for the duration of a test case. Allows us to @@ -23,3 +24,26 @@ class SetTimeMixin(object): def new_timezone_now(self): return self.now + + +class SendEmailMixin(object): + + def setUp(self): + super(SendEmailMixin, self).setUp() + + self._old_sender = mail.__send_email__ + mail.__send_email__ = self._send_email + self.emails = [] + + def _send_email(self, template_prefix, to, kind, **kwargs): + args = {"to": to, "kind": kind} + args.update(kwargs) + self.emails.append(args) + + def tearDown(self): + mail.__send_email__ = self._old_sender + super(SendEmailMixin, self).tearDown() + + +class MixInPatches(SetTimeMixin, SendEmailMixin): + pass diff --git a/registrasion/tests/test_cart.py b/registrasion/tests/test_cart.py index 619b9074..bee94322 100644 --- a/registrasion/tests/test_cart.py +++ b/registrasion/tests/test_cart.py @@ -16,12 +16,12 @@ from registrasion.controllers.batch import BatchController from registrasion.controllers.product import ProductController from controller_helpers import TestingCartController -from patch_datetime import SetTimeMixin +from patches import MixInPatches UTC = pytz.timezone('UTC') -class RegistrationCartTestCase(SetTimeMixin, TestCase): +class RegistrationCartTestCase(MixInPatches, TestCase): def setUp(self): super(RegistrationCartTestCase, self).setUp() @@ -377,7 +377,7 @@ class BasicCartTests(RegistrationCartTestCase): # Memoise the cart same_cart = TestingCartController.for_user(self.USER_1) # Do nothing on exit - + rev_1 = self.reget(cart.cart).revision self.assertEqual(rev_0, rev_1)