Exemple #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)
Exemple #2
0
    def test_num_fresh_bugs_with_small_stale_query(self):
        """
        Given a query that returns n < max_batch_size results, the
        number of fresh bugs in the form's cleaned data is equal to 0,
        if the query has been submitted before
        """
        max_batch_size = 20
        query_params = 'foo'
        bug1, bug2 = BugzillaBugFactory.create_batch(2)
        batch1 = TaskImportBatchFactory.create()
        TaskFactory.create_batch(1, batch=batch1, imported_item=bug1,
                                 is_invalid=False)
        TaskFactory.create_batch(1, batch=batch1, imported_item=bug2,
                                 is_invalid=False)
        with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs') as request_bugs:
            # two bugs previously imported in batch1
            request_bugs.return_value = [{u'id': bug1.bugzilla_id,
                                          u'summary': bug1.summary},
                                         {u'id': bug2.bugzilla_id,
                                          u'summary': bug2.summary}]
            bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query,
                                                       query_params,
                                                       len(request_bugs()),
                                                       max_batch_size)

            eq_(len(bugs), 0)
Exemple #3
0
 def setUp(self):
     user = UserFactory.create()
     self.task_not_repeatable_no_attempts = TaskFactory.create(repeatable=False)
     self.task_not_repeatable_abandoned_attempt = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.ABANDONED,
         task=self.task_not_repeatable_abandoned_attempt)
     self.task_not_repeatable_started_attempt = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.STARTED,
         task=self.task_not_repeatable_started_attempt)
     self.task_not_repeatable_finished_attempt = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.FINISHED,
         task=self.task_not_repeatable_finished_attempt)
     self.task_draft = TaskFactory.create(is_draft=True)
     self.task_invalid = TaskFactory.create(is_invalid=True)
     self.task_no_draft = TaskFactory.create(is_draft=False)
     self.task_start_jan = TaskFactory.create(
         is_draft=False, start_date=aware_datetime(2014, 1, 1))
     self.task_end_jan = TaskFactory.create(is_draft=False, end_date=aware_datetime(2014, 1, 1))
     self.task_range_jan_feb = TaskFactory.create(
         is_draft=False, start_date=aware_datetime(2014, 1, 1),
         end_date=aware_datetime(2014, 2, 1))
 def setUp(self):
     user = UserFactory.create()
     self.task_not_repeatable_no_attempts = TaskFactory.create(
         repeatable=False)
     self.task_not_repeatable_abandoned_attempt = TaskFactory.create(
         repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.ABANDONED,
         task=self.task_not_repeatable_abandoned_attempt)
     self.task_not_repeatable_started_attempt = TaskFactory.create(
         repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.STARTED,
         task=self.task_not_repeatable_started_attempt)
     self.task_not_repeatable_finished_attempt = TaskFactory.create(
         repeatable=False)
     TaskAttemptFactory.create(
         user=user,
         state=TaskAttempt.FINISHED,
         task=self.task_not_repeatable_finished_attempt)
     self.task_draft = TaskFactory.create(is_draft=True)
     self.task_invalid = TaskFactory.create(is_invalid=True)
     self.task_no_draft = TaskFactory.create(is_draft=False)
     self.task_start_jan = TaskFactory.create(is_draft=False,
                                              start_date=aware_datetime(
                                                  2014, 1, 1))
     self.task_end_jan = TaskFactory.create(is_draft=False,
                                            end_date=aware_datetime(
                                                2014, 1, 1))
     self.task_range_jan_feb = TaskFactory.create(
         is_draft=False,
         start_date=aware_datetime(2014, 1, 1),
         end_date=aware_datetime(2014, 2, 1))
Exemple #5
0
    def test_num_fresh_bugs_with_small_stale_query(self):
        """
        Given a query that returns n < max_batch_size results, the
        number of fresh bugs in the form's cleaned data is equal to 0,
        if the query has been submitted before
        """
        max_batch_size = 20
        query_params = 'foo'
        bug1, bug2 = BugzillaBugFactory.create_batch(2)
        batch1 = TaskImportBatchFactory.create()
        TaskFactory.create_batch(1,
                                 batch=batch1,
                                 imported_item=bug1,
                                 is_invalid=False)
        TaskFactory.create_batch(1,
                                 batch=batch1,
                                 imported_item=bug2,
                                 is_invalid=False)
        with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs'
                   ) as request_bugs:
            # two bugs previously imported in batch1
            request_bugs.return_value = [{
                u'id': bug1.bugzilla_id,
                u'summary': bug1.summary
            }, {
                u'id': bug2.bugzilla_id,
                u'summary': bug2.summary
            }]
            bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query,
                                                       query_params,
                                                       len(request_bugs()),
                                                       max_batch_size)

            eq_(len(bugs), 0)
Exemple #6
0
    def test_num_fresh_bugs_with_big_stale_query(self):
        """
        Given a query that returns max_batch_size + n results, where
        n < max_batch_size, the number of fresh bugs in the form's
        cleaned data is equal to n the second time the query is submitted
        (Next n bugs are accepted.)
        """
        max_batch_size = 3
        n = 2
        query_params = 'foo'
        db_bugs = BugzillaBugFactory.create_batch(max_batch_size)
        batch1 = TaskImportBatchFactory.create()
        for bug in db_bugs:
            TaskFactory.create_batch(1, batch=batch1, imported_item=bug,
                                     is_invalid=False)

        with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs') as request_bugs:
            stale_bugs = [{u'id': bug.bugzilla_id, u'summary': bug.summary}
                          for bug in db_bugs]
            new_bugs = [{u'id': 50 + i, u'summary': u'a'} for i in range(n)]
            all_bugs = stale_bugs + new_bugs

            def fake_request(request_params, fields=['id', 'summary'],
                             offset=0, limit=99):
                return all_bugs[offset:offset + limit]

            request_bugs.side_effect = fake_request
            bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query,
                                                       query_params,
                                                       len(all_bugs),
                                                       max_batch_size)
            eq_(bugs, all_bugs[max_batch_size:])
Exemple #7
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)
Exemple #8
0
 def setUp(self):
     self.task_draft = TaskFactory.create(is_draft=True)
     self.task_no_draft = TaskFactory.create(is_draft=False)
     self.task_start_jan = TaskFactory.create(
         is_draft=False, start_date=aware_datetime(2014, 1, 1))
     self.task_end_jan = TaskFactory.create(is_draft=False, end_date=aware_datetime(2014, 1, 1))
     self.task_range_jan_feb = TaskFactory.create(
         is_draft=False, start_date=aware_datetime(2014, 1, 1),
         end_date=aware_datetime(2014, 2, 1))
Exemple #9
0
 def setUp(self):
     self.task_draft = TaskFactory.create(is_draft=True)
     self.task_no_draft = TaskFactory.create(is_draft=False)
     self.task_start_jan = TaskFactory.create(is_draft=False,
                                              start_date=aware_datetime(
                                                  2014, 1, 1))
     self.task_end_jan = TaskFactory.create(is_draft=False,
                                            end_date=aware_datetime(
                                                2014, 1, 1))
     self.task_range_jan_feb = TaskFactory.create(
         is_draft=False,
         start_date=aware_datetime(2014, 1, 1),
         end_date=aware_datetime(2014, 2, 1))
 def test_next_task(self):
     attempt = self.attempt
     task2 = TaskFactory.create()
     eq_(attempt.next_task, None)
     attempt.task.next_task = task2
     attempt.task.save()
     eq_(attempt.next_task, task2)
 def test_close_stale_onetime_attempts(self):
     """
     The close_stale_onetime_attempts routine should close all
     expired one-time attempts, set them as requiring notification,
     and return the number that were closed.
     """
     task = TaskFactory.create(repeatable=False)
     user = UserFactory.create()
     recent_attempt, expired_attempt_1, expired_attempt_2 = TaskAttemptFactory.create_batch(
         3, user=user, state=TaskAttempt.STARTED, task=task)
     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_(task.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_stale_onetime_attempts(), 2)
     eq_(
         TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.STARTED).count(), 1)
     eq_(
         TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
Exemple #12
0
 def test_next_task(self):
     attempt = self.attempt
     task2 = TaskFactory.create()
     eq_(attempt.next_task, None)
     attempt.task.next_task = task2
     attempt.task.save()
     eq_(attempt.next_task, task2)
 def test_invalidate_tasks_not_equals_criterion(self):
     """
     The invalidate_tasks routine should invalidate tasks which match the
     invalidation criteria.
     This tests a not equals criterion.
     """
     bug_to_become_invalid, bug_to_stay_valid = BugzillaBugFactory.create_batch(
         2)
     batch = TaskImportBatchFactory.create()
     criterion = TaskInvalidationCriterionFactory.create(
         field_name='name',
         relation=TaskInvalidationCriterion.NOT_EQUAL,
         field_value='value')
     criterion.batches.add(batch)
     criterion.save()
     task1, task2 = TaskFactory.create_batch(
         2,
         batch=batch,
         imported_item=bug_to_become_invalid,
         is_invalid=False)
     task2.imported_item = bug_to_stay_valid
     task2.save()
     with patch('oneanddone.tasks.models.BugzillaUtils.request_bug'
                ) as request_bug:
         request_bug.side_effect = lambda x: {
             bug_to_become_invalid.bugzilla_id: {
                 'name': 'value'
             },
             bug_to_stay_valid.bugzilla_id: {
                 'name': 'not value'
             }
         }[x]
         eq_(Task.invalidate_tasks(), 1)
     eq_(Task.objects.get(pk=task1.pk).is_invalid, False)
     eq_(Task.objects.get(pk=task2.pk).is_invalid, True)
 def test_invalidation_criteria_exists(self):
     batch = TaskImportBatchFactory.create()
     criterion = TaskInvalidationCriterionFactory.create()
     criterion.batches.add(batch)
     criterion.save()
     task = TaskFactory.create(batch=batch)
     eq_(criterion, task.invalidation_criteria[0])
Exemple #15
0
 def test_bugzilla_bug_exists(self):
     bug = BugzillaBugFactory.create()
     task = TaskFactory.create(imported_item=bug)
     with patch('oneanddone.tasks.models.BugzillaUtils.request_bug') as request_bug:
         request_bug.return_value = bug
         eq_(bug, task.bugzilla_bug)
         request_bug.assert_called_with(bug.bugzilla_id)
Exemple #16
0
 def test_users_with_valid_completed_attempt_counts(self):
     """
     users_with_valid_completed_attempt_counts should return counts of all attempts completed
     within the time threshold, sorted by highest number of attempts
     """
     task = TaskFactory.create()
     user1 = UserFactory.create()
     user2 = UserFactory.create()
     # Invalid attempt
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.FINISHED,
                               task=task)
     # Valid attempts
     ValidTaskAttemptFactory.create_batch(2,
                                          user=user1,
                                          state=TaskAttempt.FINISHED,
                                          task=task)
     ValidTaskAttemptFactory.create(user=user2,
                                    state=TaskAttempt.FINISHED,
                                    task=task)
     ValidTaskAttemptFactory.create(user=user1,
                                    state=TaskAttempt.STARTED,
                                    task=task)
     eq_(user1.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
     eq_(user1.taskattempt_set.filter(state=TaskAttempt.FINISHED).count(), 3)
     eq_(user2.taskattempt_set.filter(state=TaskAttempt.FINISHED).count(), 1)
     qs = User.users_with_valid_completed_attempt_counts()
     eq_(len(qs), 2)
     eq_(qs[0], user1)
     eq_(qs[0].valid_completed_attempts_count, 2)
     eq_(qs[1], user2)
     eq_(qs[1].valid_completed_attempts_count, 1)
Exemple #17
0
 def test_default_sort_order(self):
     """
     The sort order of tasks should default to `priority`, `difficulty`
     """
     Task.objects.all().delete()
     t3, t1, t4, t2, t6, t5 = TaskFactory.create_batch(6)
     t1.priority = 1
     t1.difficulty = 1
     t1.save()
     t2.priority = 1
     t2.difficulty = 2
     t2.save()
     t3.priority = 1
     t3.difficulty = 3
     t3.save()
     t4.priority = 2
     t4.difficulty = 1
     t4.save()
     t5.priority = 2
     t5.difficulty = 3
     t5.save()
     t6.priority = 3
     t6.difficulty = 1
     t6.save()
     tasks = Task.objects.all()
     eq_(tasks[0], t1)
     eq_(tasks[1], t2)
     eq_(tasks[2], t3)
     eq_(tasks[3], t4)
     eq_(tasks[4], t5)
     eq_(tasks[5], t6)
    def create_task(self, creator):
        team = TaskTeamFactory.create()
        project = TaskProjectFactory.create()
        type = TaskTypeFactory.create()

        return TaskFactory.create(team=team, project=project, type=type,
                                  creator=creator, owner=creator)
Exemple #19
0
 def test_close_stale_onetime_attempts(self):
     """
     The close_stale_onetime_attempts routine should close all
     expired one-time attempts, set them as requiring notification,
     and return the number that were closed.
     """
     task = TaskFactory.create(repeatable=False)
     user = UserFactory.create()
     recent_attempt, expired_attempt_1, expired_attempt_2 = TaskAttemptFactory.create_batch(
         3,
         user=user,
         state=TaskAttempt.STARTED,
         task=task)
     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_(task.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_stale_onetime_attempts(), 2)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.STARTED).count(), 1)
     eq_(TaskAttempt.objects.filter(task=task,
                                    state=TaskAttempt.CLOSED,
                                    requires_notification=True).count(), 2)
 def test_default_sort_order(self):
     """
     The sort order of tasks should default to `priority`, `difficulty`
     """
     Task.objects.all().delete()
     t3, t1, t4, t2, t6, t5 = TaskFactory.create_batch(6)
     t1.priority = 1
     t1.difficulty = 1
     t1.save()
     t2.priority = 1
     t2.difficulty = 2
     t2.save()
     t3.priority = 1
     t3.difficulty = 3
     t3.save()
     t4.priority = 2
     t4.difficulty = 1
     t4.save()
     t5.priority = 2
     t5.difficulty = 3
     t5.save()
     t6.priority = 3
     t6.difficulty = 1
     t6.save()
     tasks = Task.objects.all()
     eq_(tasks[0], t1)
     eq_(tasks[1], t2)
     eq_(tasks[2], t3)
     eq_(tasks[3], t4)
     eq_(tasks[4], t5)
     eq_(tasks[5], t6)
Exemple #21
0
 def test_initial_contains_empty_list_of_keywords_for_new_task(self):
     """
     Initial should contain an empty list of keywords for a new task.
     """
     task = TaskFactory.create()
     form = TaskForm(instance=task)
     eq_(form.initial['keywords'], '')
Exemple #22
0
    def test_save_processes_keywords_correctly(self):
        """
        Saving the form should update the keywords correctly.
        - Removed keywords should be removed
        - New keywords should be added
        - Remaining keywords should remain
        """
        user = UserFactory.create()
        task = TaskFactory.create()
        TaskKeywordFactory.create_batch(3, task=task)
        form = get_filled_taskform(task, keywords='test3, new_keyword')
        form.save(user)

        removed_keyword = TaskKeyword.objects.filter(task=task, name='test1')
        eq_(len(removed_keyword), 0)

        added_keyword = TaskKeyword.objects.filter(task=task,
                                                   name='new_keyword')
        eq_(len(added_keyword), 1)

        kept_keyword = TaskKeyword.objects.filter(task=task, name='test3')
        eq_(len(kept_keyword), 1)

        # double-check on the keywords_list property
        eq_(task.keywords_list, 'test3, new_keyword')
Exemple #23
0
 def test_initial_contains_empty_list_of_keywords_for_new_task(self):
     """
     Initial should contain an empty list of keywords for a new task.
     """
     task = TaskFactory.create()
     form = TaskForm(instance=task)
     eq_(form.initial['keywords'], '')
Exemple #24
0
    def test_save_processes_keywords_correctly(self):
        """
        Saving the form should update the keywords correctly.
        - Removed keywords should be removed
        - New keywords should be added
        - Remaining keywords should remain
        """
        user = UserFactory.create()
        task = TaskFactory.create()
        TaskKeywordFactory.create_batch(3, task=task)
        data = {
            'keywords': 'test3, new_keyword',
            'team': task.team.id,
        }
        for field in ('name', 'short_description', 'execution_time', 'difficulty',
                      'repeatable', 'instructions', 'is_draft'):
            data[field] = getattr(task, field)
        form = TaskForm(instance=task, data=data)
        form.save(user)

        removed_keyword = TaskKeyword.objects.filter(task=task, name='test1')
        eq_(len(removed_keyword), 0)

        added_keyword = TaskKeyword.objects.filter(task=task, name='new_keyword')
        eq_(len(added_keyword), 1)

        kept_keyword = TaskKeyword.objects.filter(task=task, name='test3')
        eq_(len(kept_keyword), 1)

        # double-check on the keywords_list property
        eq_(task.keywords_list, 'test3, new_keyword')
Exemple #25
0
 def test_has_completed_task_false(self):
     """
     has_completed_task should return false if the user has not completed the task.
     """
     user = UserFactory.create()
     task = TaskFactory.create()
     ok_(not user.has_completed_task(task))
Exemple #26
0
 def test_invalidation_criteria_exists(self):
     batch = TaskImportBatchFactory.create()
     criterion = TaskInvalidationCriterionFactory.create()
     criterion.batches.add(batch)
     criterion.save()
     task = TaskFactory.create(batch=batch)
     eq_(criterion, task.invalidation_criteria[0])
Exemple #27
0
 def test_invalidate_tasks_not_equals_criterion(self):
     """
     The invalidate_tasks routine should invalidate tasks which match the
     invalidation criteria.
     This tests a not equals criterion.
     """
     bug_to_become_invalid, bug_to_stay_valid = BugzillaBugFactory.create_batch(2)
     batch = TaskImportBatchFactory.create()
     criterion = TaskInvalidationCriterionFactory.create(
         field_name='name',
         relation=TaskInvalidationCriterion.NOT_EQUAL,
         field_value='value')
     criterion.batches.add(batch)
     criterion.save()
     task1, task2 = TaskFactory.create_batch(2,
                                             batch=batch,
                                             imported_item=bug_to_become_invalid,
                                             is_invalid=False)
     task2.imported_item = bug_to_stay_valid
     task2.save()
     with patch('oneanddone.tasks.models.BugzillaUtils.request_bug') as request_bug:
         request_bug.side_effect = lambda x: {
             bug_to_become_invalid.bugzilla_id: {'name': 'value'},
             bug_to_stay_valid.bugzilla_id: {'name': 'not value'}}[x]
         eq_(Task.invalidate_tasks(), 1)
     eq_(Task.objects.get(pk=task1.pk).is_invalid, False)
     eq_(Task.objects.get(pk=task2.pk).is_invalid, True)
Exemple #28
0
 def test_has_completed_task_false(self):
     """
     has_completed_task should return false if the user has not completed the task.
     """
     user = UserFactory.create()
     task = TaskFactory.create()
     ok_(not user.has_completed_task(task))
Exemple #29
0
 def test_bugzilla_bug_exists(self):
     bug = BugzillaBugFactory.create()
     task = TaskFactory.create(imported_item=bug)
     with patch('oneanddone.tasks.models.BugzillaUtils.request_bug') as request_bug:
         request_bug.return_value = bug
         eq_(bug, task.bugzilla_bug)
         request_bug.assert_called_with(bug.bugzilla_id)
 def test_first_previous_task(self):
     task1, task2, task3 = TaskFactory.create_batch(3)
     eq_(task2.first_previous_task, None)
     task1.next_task = task2
     task1.save()
     task3.next_task = task2
     task3.save()
     eq_(task1, task2.first_previous_task)
Exemple #31
0
 def test_first_previous_task(self):
     task1, task2, task3 = TaskFactory.create_batch(3)
     eq_(task2.first_previous_task, None)
     task1.next_task = task2
     task1.save()
     task3.next_task = task2
     task3.save()
     eq_(task1, task2.first_previous_task)
Exemple #32
0
 def test_initial_contains_list_of_keywords_for_existing_task(self):
     """
     Initial should contain the list of keywords from the task instance.
     """
     task = TaskFactory.create()
     TaskKeywordFactory.create_batch(3, task=task)
     form = TaskForm(instance=task)
     eq_(form.initial['keywords'], 'test1, test2, test3')
 def test_has_completed_task_false_task_started(self):
     """
     has_completed_task should return false if the user has just started the task.
     """
     user = UserFactory.create()
     task = TaskFactory.create()
     TaskAttemptFactory.create(user=user, task=task, state=TaskAttempt.STARTED)
     ok_(not user.has_completed_task(task))
 def test_has_completed_task_true(self):
     """
     has_completed_task should return true if the user has completed the task.
     """
     user = UserFactory.create()
     task = TaskFactory.create()
     TaskAttemptFactory.create(user=user, task=task, state=TaskAttempt.FINISHED)
     ok_(user.has_completed_task(task))
Exemple #35
0
 def test_initial_contains_list_of_keywords_for_existing_task(self):
     """
     Initial should contain the list of keywords from the task instance.
     """
     task = TaskFactory.create()
     TaskKeywordFactory.create_batch(3, task=task)
     form = TaskForm(instance=task)
     eq_(sorted(form.initial['keywords']), sorted('test1, test2, test3'))
Exemple #36
0
    def test_area_filter_empty_children(self):
        """
        If a TaskArea has available tasks but its children don't, the
        children should not be included in the area filter.
        """
        # root -> child1 -> grandchild1
        #     \-> child2
        root = TaskAreaFactory.create()
        child1, child2 = TaskAreaFactory.create_batch(2, parent=root)
        grandchild1 = TaskAreaFactory.create(parent=child1)

        # Only child1 has available tasks.
        TaskFactory.create(area=child1, is_draft=False)

        # Area should include child1, but not grandchild1.
        filter_set = AvailableTasksFilterSet()
        areas = filter_set.filters["area"].extra["queryset"]
        eq_(set(areas), set([root, child1]))
Exemple #37
0
 def test_is_available_to_user_user_attempt(self):
     """
     If there is an attempt by the current user,
     the task should be available.
     """
     user = UserFactory.create()
     task = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(user=user, state=TaskAttempt.STARTED, task=task)
     eq_(task.is_available_to_user(user), True)
Exemple #38
0
    def test_area_filter_only_with_available_tasks(self):
        """
        Only TaskAreas with available tasks and their parents should be
        included in the area filter.
        """
        # root -> child1 -> grandchild1
        #     \-> child2
        root = TaskAreaFactory.create()
        child1, child2 = TaskAreaFactory.create_batch(2, parent=root)
        grandchild1 = TaskAreaFactory.create(parent=child1)

        # Only grandchild1 has available tasks.
        TaskFactory.create(area=grandchild1, is_draft=False)

        # Area should include grandlchild1 and its parents.
        filter_set = AvailableTasksFilterSet()
        areas = filter_set.filters['area'].extra['queryset']
        eq_(set(areas), set([root, child1, grandchild1]))
Exemple #39
0
 def test_is_available_to_user_user_attempt(self):
     """
     If there is an attempt by the current user,
     the task should be available.
     """
     user = UserFactory.create()
     task = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(user=user, state=TaskAttempt.STARTED, task=task)
     eq_(task.is_available_to_user(user), True)
Exemple #40
0
    def test_area_filter_empty_children(self):
        """
        If a TaskArea has available tasks but its children don't, the
        children should not be included in the area filter.
        """
        # root -> child1 -> grandchild1
        #     \-> child2
        root = TaskAreaFactory.create()
        child1, child2 = TaskAreaFactory.create_batch(2, parent=root)
        grandchild1 = TaskAreaFactory.create(parent=child1)

        # Only child1 has available tasks.
        TaskFactory.create(area=child1, is_draft=False)

        # Area should include child1, but not grandchild1.
        filter_set = AvailableTasksFilterSet()
        areas = filter_set.filters['area'].extra['queryset']
        eq_(set(areas), set([root, child1]))
Exemple #41
0
    def test_area_filter_only_with_available_tasks(self):
        """
        Only TaskAreas with available tasks and their parents should be
        included in the area filter.
        """
        # root -> child1 -> grandchild1
        #     \-> child2
        root = TaskAreaFactory.create()
        child1, child2 = TaskAreaFactory.create_batch(2, parent=root)
        grandchild1 = TaskAreaFactory.create(parent=child1)

        # Only grandchild1 has available tasks.
        TaskFactory.create(area=grandchild1, is_draft=False)

        # Area should include grandlchild1 and its parents.
        filter_set = AvailableTasksFilterSet()
        areas = filter_set.filters["area"].extra["queryset"]
        eq_(set(areas), set([root, child1, grandchild1]))
    def test_validation_same_start_date_as_end_date(self):
        """
        The form is not valid if start date is same as end date.
        """
        form = get_filled_taskform(TaskFactory.create(),
                                   start_date='2013-08-15',
                                   end_date='2013-08-15')

        self.assertFalse(form.is_valid())
        eq_(form.non_field_errors(), ["'End date' must be after 'Start date'"])
Exemple #43
0
 def test_isnt_available_to_user_other_user_non_abandoned_attempt(self):
     """
     If there is a non-abandoned attempt by a different user,
     the task should not be available.
     """
     user = UserFactory.create()
     other_user = UserFactory.create()
     task = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(user=other_user, state=TaskAttempt.STARTED, task=task)
     eq_(task.is_available_to_user(user), False)
    def test_validation_start_date_before_end_date(self):
        """
        The form is valid if start date is before end date and all other
        field requirements are respected.
        """
        form = get_filled_taskform(TaskFactory.create(),
                                   start_date='2013-07-01',
                                   end_date='2013-08-15')

        self.assertTrue(form.is_valid())
Exemple #45
0
 def test_isnt_available_to_user_other_user_non_abandoned_attempt(self):
     """
     If there is a non-abandoned attempt by a different user,
     the task should not be available.
     """
     user = UserFactory.create()
     other_user = UserFactory.create()
     task = TaskFactory.create(repeatable=False)
     TaskAttemptFactory.create(user=other_user, state=TaskAttempt.STARTED, task=task)
     eq_(task.is_available_to_user(user), False)
Exemple #46
0
    def test_validation_start_date_before_end_date(self):
        """
        The form is valid if start date is before end date and all other
        field requirements are respected.
        """
        form = get_filled_taskform(TaskFactory.create(),
                                   start_date='2013-07-01',
                                   end_date='2013-08-15')

        self.assertTrue(form.is_valid())
Exemple #47
0
    def test_validation_start_date_after_end_date(self):
        """
        The form is not valid if start date is after end date.
        """
        form = get_filled_taskform(TaskFactory.create(),
                                   start_date='2014-07-01',
                                   end_date='2013-08-15')

        self.assertFalse(form.is_valid())
        eq_(form.non_field_errors(), ["'End date' must be after 'Start date'"])
    def test_save_does_not_add_a_blank_keyword(self):
        """
        Saving the form should not add a blank keyword when
         keywords are empty.
        """
        user = UserFactory.create()
        task = TaskFactory.create()
        form = get_filled_taskform(task, keywords=' ')

        form.save(user)

        eq_(task.keyword_set.count(), 0)
Exemple #49
0
def assigned_task(base_url, is_local):
    if is_local:
        from oneanddone.tasks.tests import TaskFactory, TaskAttemptFactory
        from oneanddone.users.tests import UserFactory
        from oneanddone.tasks.models import TaskAttempt
        task = TaskFactory.create(repeatable=False)
        user = UserFactory.create()
        TaskAttemptFactory.create(
            user=user,
            state=TaskAttempt.STARTED,
            task=task)
        return task
Exemple #50
0
    def test_save_does_not_add_a_blank_keyword(self):
        """
        Saving the form should not add a blank keyword when
         keywords are empty.
        """
        user = UserFactory.create()
        task = TaskFactory.create()
        form = get_filled_taskform(task, keywords=' ')

        form.save(user)

        eq_(task.keyword_set.count(), 0)
Exemple #51
0
    def test_num_fresh_bugs_with_big_stale_query(self):
        """
        Given a query that returns max_batch_size + n results, where
        n < max_batch_size, the number of fresh bugs in the form's
        cleaned data is equal to n the second time the query is submitted
        (Next n bugs are accepted.)
        """
        max_batch_size = 3
        n = 2
        query_params = 'foo'
        db_bugs = BugzillaBugFactory.create_batch(max_batch_size)
        batch1 = TaskImportBatchFactory.create()
        for bug in db_bugs:
            TaskFactory.create_batch(1,
                                     batch=batch1,
                                     imported_item=bug,
                                     is_invalid=False)

        with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs'
                   ) as request_bugs:
            stale_bugs = [{
                u'id': bug.bugzilla_id,
                u'summary': bug.summary
            } for bug in db_bugs]
            new_bugs = [{u'id': 50 + i, u'summary': u'a'} for i in range(n)]
            all_bugs = stale_bugs + new_bugs

            def fake_request(request_params,
                             fields=['id', 'summary'],
                             offset=0,
                             limit=99):
                return all_bugs[offset:offset + limit]

            request_bugs.side_effect = fake_request
            bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query,
                                                       query_params,
                                                       len(all_bugs),
                                                       max_batch_size)
            eq_(bugs, all_bugs[max_batch_size:])
Exemple #52
0
    def test_save_does_not_add_a_blank_keyword(self):
        """
        Saving the form should not add a blank keyword when
         keywords are empty.
        """
        user = UserFactory.create()
        task = TaskFactory.create()
        data = {
            'keywords': ' ',
            'team': task.team.id,
        }
        for field in ('name', 'short_description', 'execution_time', 'difficulty',
                      'repeatable', 'instructions', 'is_draft'):
            data[field] = getattr(task, field)
        form = TaskForm(instance=task, data=data)
        form.save(user)

        eq_(task.keyword_set.count(), 0)
Exemple #53
0
 def test_get_form_kwargs_populates_form_with_data_to_be_cloned(self):
     """
     When accessed via the tasks.clone url, the view displays a form
     whose initial data is that of the task being cloned, except for
     the 'name' field, which should be prefixed with 'Copy of '
     """
     user = UserFactory.create()
     original_task = TaskFactory.create()
     TaskKeywordFactory.create_batch(3, task=original_task)
     original_data = get_filled_taskform(original_task).data
     self.view.kwargs = {'clone': original_task.pk}
     self.view.request = Mock(user=user)
     with patch('oneanddone.tasks.views.generic.CreateView.get_form_kwargs') as get_form_kwargs:
         get_form_kwargs.return_value = {'initial': {}}
         initial = self.view.get_form_kwargs()['initial']
     eq_(initial['keywords'], original_task.keywords_list)
     eq_(initial['name'], ' '.join(['Copy of', original_task.name]))
     del original_data['name']
     assert_dict_contains_subset(original_data, initial)
Exemple #54
0
 def test_get_form_kwargs_populates_form_with_data_to_be_cloned(self):
     """
     When accessed via the tasks.clone url, the view displays a form
     whose initial data is that of the task being cloned, except for
     the 'name' field, which should be prefixed with 'Copy of '
     """
     user = UserFactory.create()
     original_task = TaskFactory.create()
     TaskKeywordFactory.create_batch(3, task=original_task)
     original_data = get_filled_taskform(original_task).data
     self.view.kwargs = {'clone': original_task.pk}
     self.view.request = Mock(user=user)
     with patch('oneanddone.tasks.views.generic.CreateView.get_form_kwargs'
                ) as get_form_kwargs:
         get_form_kwargs.return_value = {'initial': {}}
         initial = self.view.get_form_kwargs()['initial']
     eq_(initial['keywords'], original_task.keywords_list)
     eq_(initial['name'], ' '.join(['Copy of', original_task.name]))
     del original_data['name']
     assert_dict_contains_subset(original_data, initial)
 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)
 def test_recent_users(self):
     """
     recent_users should return users sorted by most recent task activity
     """
     task = TaskFactory.create()
     user1 = UserProfileFactory.create().user
     user2 = UserProfileFactory.create().user
     user3 = UserProfileFactory.create().user
     user4 = UserFactory.create()
     TaskAttemptFactory.create(user=user4,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user2,
                               state=TaskAttempt.FINISHED,
                               task=task)
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.STARTED,
                               task=task)
     TaskAttemptFactory.create(user=user3,
                               state=TaskAttempt.ABANDONED,
                               task=task)
     eq_(user1.taskattempt_set.all().count(), 1)
     eq_(user2.taskattempt_set.all().count(), 2)
     eq_(user3.taskattempt_set.all().count(), 2)
     eq_(user4.taskattempt_set.all().count(), 1)
     qs = User.recent_users()
     eq_(len(qs), 3)
     eq_(qs[0], user1)
     eq_(qs[1], user2)
     eq_(qs[2], user3)
Exemple #57
0
 def test_users_with_valid_completed_attempt_counts(self):
     """
     users_with_valid_completed_attempt_counts should return counts of all attempts completed
     within the time threshold, sorted by highest number of attempts
     """
     task = TaskFactory.create()
     user1 = UserFactory.create()
     user2 = UserFactory.create()
     # Invalid attempt
     TaskAttemptFactory.create(user=user1,
                               state=TaskAttempt.FINISHED,
                               task=task)
     # Valid attempts
     ValidTaskAttemptFactory.create_batch(2,
                                          user=user1,
                                          state=TaskAttempt.FINISHED,
                                          task=task)
     ValidTaskAttemptFactory.create(user=user2,
                                    state=TaskAttempt.FINISHED,
                                    task=task)
     ValidTaskAttemptFactory.create(user=user1,
                                    state=TaskAttempt.STARTED,
                                    task=task)
     eq_(user1.taskattempt_set.filter(state=TaskAttempt.STARTED).count(), 1)
     eq_(
         user1.taskattempt_set.filter(state=TaskAttempt.FINISHED).count(),
         3)
     eq_(
         user2.taskattempt_set.filter(state=TaskAttempt.FINISHED).count(),
         1)
     qs = User.users_with_valid_completed_attempt_counts()
     eq_(len(qs), 2)
     eq_(qs[0], user1)
     eq_(qs[0].valid_completed_attempts_count, 2)
     eq_(qs[1], user2)
     eq_(qs[1].valid_completed_attempts_count, 1)