コード例 #1
0
ファイル: test_forms.py プロジェクト: akatsoulas/oneanddone
    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
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 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)
コード例 #3
0
ファイル: test_forms.py プロジェクト: akatsoulas/oneanddone
    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_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)
コード例 #5
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 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)
コード例 #6
0
ファイル: test_models.py プロジェクト: adini121/oneanddone
 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)
コード例 #7
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)
コード例 #8
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:])
コード例 #9
0
ファイル: test_models.py プロジェクト: akatsoulas/oneanddone
 def test_has_bugzilla_bug_true(self):
     bug = BugzillaBugFactory.create()
     task = TaskFactory.create(imported_item=bug)
     ok_(task.has_bugzilla_bug)
コード例 #10
0
 def test_has_bugzilla_bug_true(self):
     bug = BugzillaBugFactory.create()
     task = TaskFactory.create(imported_item=bug)
     ok_(task.has_bugzilla_bug)