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)
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)
def setUp(self): self.user1, self.user2 = UserFactory.create_batch(2) self.task1, self.task2 = TaskFactory.create_batch(2) TaskAttemptFactory.create_batch(2, user=self.user1, task=self.task1, state=TaskAttempt.FINISHED) ValidTaskAttemptFactory.create_batch(2, user=self.user1, task=self.task1, state=TaskAttempt.FINISHED) ValidTaskAttemptFactory.create(user=self.user1, task=self.task2, state=TaskAttempt.FINISHED) ValidTaskAttemptFactory.create(user=self.user2, task=self.task1, state=TaskAttempt.FINISHED) ValidTaskAttemptFactory.create_batch(2, user=self.user1, task=self.task1, state=TaskAttempt.ABANDONED) ValidTaskAttemptFactory.create(user=self.user2, task=self.task1, state=TaskAttempt.ABANDONED) ValidTaskAttemptFactory.create(user=self.user1, task=self.task2, state=TaskAttempt.ABANDONED) ValidTaskAttemptFactory.create_batch(2, user=self.user1, task=self.task1, state=TaskAttempt.CLOSED) ValidTaskAttemptFactory.create(user=self.user2, task=self.task1, state=TaskAttempt.CLOSED) ValidTaskAttemptFactory.create(user=self.user1, task=self.task2, state=TaskAttempt.CLOSED)