Пример #1
0
 def test_close_expired_task_attempts(self):
     """
     The close_expired_task_attempts routine should close all
     attempts for tasks that are no longer available,
     set them as requiring notification,
     and return the number that were closed.
     """
     task_no_expire = TaskFactory.create()
     task = TaskFactory.create(end_date=timezone.now() + timedelta(days=1))
     future_date = timezone.now() + timedelta(days=2)
     user1, user2, user3 = UserFactory.create_batch(3)
     TaskAttemptFactory.create(
         user=user1,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user2,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user3,
         state=TaskAttempt.STARTED,
         task=task_no_expire)
     eq_(task.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 2)
     eq_(task_no_expire.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = future_date
         eq_(TaskAttempt.close_expired_task_attempts(), 2)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
     eq_(TaskAttempt.objects.filter(task=task_no_expire,
                                    state=TaskAttempt.STARTED).count(), 1)
Пример #2
0
 def test_close_expired_task_attempts(self):
     """
     The close_expired_task_attempts routine should close all
     attempts for tasks that are no longer available,
     set them as requiring notification,
     and return the number that were closed.
     """
     task_no_expire = TaskFactory.create()
     task = TaskFactory.create(end_date=timezone.now() + timedelta(days=1))
     future_date = timezone.now() + timedelta(days=2)
     user1, user2, user3 = UserFactory.create_batch(3)
     TaskAttemptFactory.create(
         user=user1,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user2,
         state=TaskAttempt.STARTED,
         task=task)
     TaskAttemptFactory.create(
         user=user3,
         state=TaskAttempt.STARTED,
         task=task_no_expire)
     eq_(task.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 2)
     eq_(task_no_expire.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
     with patch('oneanddone.tasks.models.timezone.now') as now:
         now.return_value = future_date
         eq_(TaskAttempt.close_expired_task_attempts(), 2)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
     eq_(TaskAttempt.objects.filter(task=task_no_expire,
                                    state=TaskAttempt.STARTED).count(), 1)
Пример #3
0
 def test_close_expired_task_attempts(self):
     """
     The close_expired_task_attempts routine should close all
     attempts for tasks that are no longer available,
     set them as requiring notification,
     and return the number that were closed.
     """
     user1, user2, user3 = UserFactory.create_batch(3)
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.STARTED,
                               task=self.task_end_jan)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.STARTED,
                               task=self.task_end_jan)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.STARTED,
                               task=self.task_no_draft)
     eq_(
         self.task_end_jan.taskattempt_set.filter(
             state=TaskAttempt.STARTED).count(), 2)
     eq_(
         self.task_no_draft.taskattempt_set.filter(
             state=TaskAttempt.STARTED).count(), 1)
     eq_(TaskAttempt.close_expired_task_attempts(), 2)
     eq_(
         TaskAttempt.objects.filter(task=self.task_end_jan,
                                    state=TaskAttempt.STARTED).count(), 0)
     eq_(
         TaskAttempt.objects.filter(task=self.task_end_jan,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
     eq_(
         TaskAttempt.objects.filter(task=self.task_no_draft,
                                    state=TaskAttempt.STARTED).count(), 1)
Пример #4
0
 def handle(self, *args, **options):
     invalidated = Task.invalidate_tasks()
     self.stdout.write('%s: %s tasks were invalidated via bug data\n' %
                       (datetime.now().isoformat(), invalidated))
     closed = TaskAttempt.close_stale_onetime_attempts()
     self.stdout.write('%s: %s stale one-time attempts were closed\n' %
                       (datetime.now().isoformat(), closed))
     closed = TaskAttempt.close_expired_task_attempts()
     self.stdout.write('%s: %s attempts for expired tasks were closed\n' %
                       (datetime.now().isoformat(), closed))