예제 #1
0
 def test_close_expired_onetime_attempts(self):
     """
     The close_expired_onetime_attempts routine should close all
     expired one-time attempts and return the number that were closed.
     """
     user = UserFactory.create()
     recent_attempt, expired_attempt_1, expired_attempt_2 = TaskAttemptFactory.create_batch(
         3,
         user=user,
         state=TaskAttempt.STARTED,
         task=self.task_not_repeatable_no_attempts)
     recent_attempt.created = aware_datetime(2014, 1, 29)
     recent_attempt.save()
     expired_attempt_1.created = aware_datetime(2014, 1, 1)
     expired_attempt_1.save()
     expired_attempt_2.created = aware_datetime(2014, 1, 1)
     expired_attempt_2.save()
     eq_(
         self.task_not_repeatable_no_attempts.taskattempt_set.filter(
             state=TaskAttempt.STARTED).count(), 3)
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = aware_datetime(2014, 1, 31)
         eq_(TaskAttempt.close_expired_onetime_attempts(), 2)
     eq_(
         TaskAttempt.objects.filter(
             task=self.task_not_repeatable_no_attempts,
             state=TaskAttempt.STARTED).count(), 1)
     eq_(
         TaskAttempt.objects.filter(
             task=self.task_not_repeatable_no_attempts,
             state=TaskAttempt.CLOSED).count(), 2)
예제 #2
0
 def handle(self, *args, **options):
     closed = TaskAttempt.close_expired_onetime_attempts()
     self.stdout.write('%s expired one-time attempts were closed\n' % closed)
예제 #3
0
 def handle(self, *args, **options):
     closed = TaskAttempt.close_expired_onetime_attempts()
     self.stdout.write('%s expired one-time attempts were closed\n' %
                       closed)