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))
Пример #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 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))
Пример #4
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)
Пример #5
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))
Пример #6
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))
Пример #7
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'], '')
Пример #8
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')
Пример #9
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)
Пример #10
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))
Пример #11
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))
Пример #12
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])
Пример #13
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')
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
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)
Пример #19
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'], '')
Пример #20
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])
Пример #21
0
    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)
Пример #22
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)
Пример #23
0
 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))
Пример #24
0
 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))
Пример #25
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'))
Пример #26
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')
Пример #27
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]))
Пример #28
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)
Пример #29
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]))
Пример #30
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]))
Пример #31
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)
Пример #32
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]))
Пример #33
0
    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'"])
Пример #34
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'"])
Пример #35
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)
Пример #36
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)
Пример #37
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())
Пример #38
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())
Пример #39
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)
Пример #40
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)
Пример #41
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
Пример #42
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)
Пример #43
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)
Пример #44
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)
Пример #45
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)
Пример #46
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')
Пример #47
0
 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)
Пример #48
0
 def test_has_bugzilla_bug_true(self):
     bug = BugzillaBugFactory.create()
     task = TaskFactory.create(imported_item=bug)
     ok_(task.has_bugzilla_bug)
Пример #49
0
 def save_task(user, **kwargs):
     return TaskFactory.create(creator=user)
Пример #50
0
 def test_bugzilla_bug_not_exists(self):
     task = TaskFactory.create()
     eq_(None, task.bugzilla_bug)
Пример #51
0
 def test_invalidation_criteria_does_not_exist(self):
     task = TaskFactory.create()
     eq_(None, task.invalidation_criteria)
Пример #52
0
 def test_bugzilla_bug_not_exists(self):
     task = TaskFactory.create()
     eq_(None, task.bugzilla_bug)
Пример #53
0
 def setUp(self):
     self.user = UserProfileFactory.create(user__is_staff=True, name='Foo bar').user
     self.task = TaskFactory.create(owner=self.user)
Пример #54
0
 def setUp(self):
     self.view = views.StartTaskView()
     self.task = TaskFactory.create()
     self.view.get_object = Mock(return_value=self.task)
Пример #55
0
 def setUp(self):
     TaskAttempt.objects.all().delete()
     user = UserFactory.create()
     task = TaskFactory.create()
     self.attempt = TaskAttemptFactory.create(user=user, task=task)
Пример #56
0
 def setUp(self):
     TaskAttempt.objects.all().delete()
     user = UserFactory.create()
     task = TaskFactory.create()
     self.attempt = TaskAttemptFactory.create(user=user, task=task)