Files
@ 9ca25e5986ba
Branch filter:
Location: symposion_app/registrasion/tests/patch_datetime.py - annotation
9ca25e5986ba
690 B
text/x-python
Makes sure that the cache is not disturbed by calling end_batch
d9e433659d01 d9e433659d01 224878a10ce3 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 d9e433659d01 | 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
|