Renames patch_datetime to patches, adds e-mail patching bits

This commit is contained in:
Christopher Neugebauer 2016-08-21 16:39:57 +10:00
parent 1faa608425
commit 155f6d42d9
2 changed files with 27 additions and 3 deletions

View file

@ -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

View file

@ -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)