Пример #1
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:])
Пример #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)
Пример #3
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)
Пример #4
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)
Пример #5
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)
 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 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)
Пример #8
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)
 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)
Пример #10
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:])
Пример #11
0
 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)
Пример #12
0
 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)
Пример #13
0
 def test_get_next_task_url(self):
     task1, task2 = TaskFactory.create_batch(2)
     eq_(task1.get_next_task_url(), '')
     task2.next_task = task1
     task2.save()
     ok_(str(task1.id) in task2.get_next_task_url())
Пример #14
0
 def test_get_next_task_url(self):
     task1, task2 = TaskFactory.create_batch(2)
     eq_(task1.get_next_task_url(), '')
     task2.next_task = task1
     task2.save()
     ok_(str(task1.id) in task2.get_next_task_url())