symposion_app/registrasion/tests/patch_datetime.py
Christopher Neugebauer 224878a10c Fixes flake8 errors
2016-01-22 17:21:29 +11:00

25 lines
690 B
Python

from django.utils import timezone
class SetTimeMixin(object):
''' Patches timezone.now() for the duration of a test case. Allows us to
test time-based conditions (ceilings etc) relatively easily. '''
def setUp(self):
super(SetTimeMixin, self).setUp()
self._old_timezone_now = timezone.now
self.now = timezone.now()
timezone.now = self.new_timezone_now
def tearDown(self):
timezone.now = self._old_timezone_now
super(SetTimeMixin, self).tearDown()
def set_time(self, time):
self.now = time
def add_timedelta(self, delta):
self.now += delta
def new_timezone_now(self):
return self.now