Ejemplo n.º 1
0
def classified_failures(request, jm, eleven_jobs_stored, initial_data, failure_lines):
    from treeherder.model.models import ClassifiedFailure, FailureMatch, Matcher
    from treeherder.autoclassify import detectors

    job_1 = jm.get_job(1)[0]

    class TreeherderUnitTestDetector(detectors.Detector):
        def __call__(self, failure_lines):
            pass

    test_matcher = Matcher.objects.register_detector(TreeherderUnitTestDetector)

    def finalize():
        Matcher._detector_funcs = {}
        Matcher._matcher_funcs = {}
    request.addfinalizer(finalize)

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == job_1["job_guid"]:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            match = FailureMatch(failure_line=failure_line,
                                 classified_failure=classified_failure,
                                 matcher=test_matcher.db_object,
                                 score=1.0,
                                 is_best=True)
            match.save()
            classified_failures.append(classified_failure)

    return classified_failures
Ejemplo n.º 2
0
def test_put_multiple_duplicate(webapp, classified_failures, test_user):
    client = APIClient()
    client.force_authenticate(user=test_user)

    new = ClassifiedFailure(bug_number=1234)
    new.save()
    classified_failures.append(new)

    resp = client.put(reverse("classified-failure-list"),
                      [{"id": classified_failures[0].id, "bug_number": 1234},
                       {"id": classified_failures[1].id, "bug_number": 5678}],
                      format="json")

    actual = resp.data
    assert len(actual) == 2
    expected = [{"id": classified_failures[2].id,
                 "bug_number": 1234,
                 "bug": None},
                {"id": classified_failures[1].id,
                 "bug_number": 5678,
                 "bug": None}]
    assert actual == expected

    new_classified_failures = ClassifiedFailure.objects.all()
    assert len(new_classified_failures) == len(classified_failures) - 1
Ejemplo n.º 3
0
def test_put_duplicate_multiple_repeated(webapp, classified_failures, test_user):
    client = APIClient()
    client.force_authenticate(user=test_user)

    new = ClassifiedFailure(bug_number=1234)
    new.save()
    classified_failures.append(new)

    client.put(reverse("classified-failure-list"),
               [{"id": classified_failures[0].id, "bug_number": 1234}],
               format="json")
    new_classified_failures = ClassifiedFailure.objects.all()
    assert [item.id for item in new_classified_failures] == [2, 3]
    assert [item.bug_number for item in new_classified_failures] == [None, 1234]
    resp = client.put(reverse("classified-failure-list"),
                      [{"id": classified_failures[0].id, "bug_number": 1234},
                       {"id": classified_failures[1].id, "bug_number": 1234}],
                      format="json")

    actual = resp.data
    assert len(actual) == 2
    expected = [{"id": new.id,
                 "bug_number": 1234,
                 "bug": None},
                {"id": new.id,
                 "bug_number": 1234,
                 "bug": None}]
    assert actual == expected
def test_put_duplicate_repeated(client, classified_failures, test_user):
    client.force_authenticate(user=test_user)

    new = ClassifiedFailure(bug_number=1234)
    new.save()
    classified_failures.append(new)

    resp = client.put(
        reverse("classified-failure-list"),
        [{"id": classified_failures[0].id, "bug_number": 1234}],
    )
    assert resp.status_code == 200
    new_classified_failures = ClassifiedFailure.objects.all()
    assert [item.id for item in new_classified_failures] == [2, 3]
    assert [item.bug_number for item in new_classified_failures] == [None, 1234]

    resp = client.put(reverse("classified-failure-list"),
                      [{"id": classified_failures[0].id, "bug_number": 1234}],
                      )
    assert resp.status_code == 200

    actual = resp.data
    assert len(actual) == 1
    expected = [{"id": new.id,
                 "bug_number": 1234,
                 "bug": None}]
    assert actual == expected

    new_classified_failures = ClassifiedFailure.objects.all()
    assert len(new_classified_failures) == len(classified_failures) - 1
Ejemplo n.º 5
0
    def _create(self, data, many=False):
        rv = []

        for item in data:
            bug = item.get('bug_number')
            if bug >= 0:
                obj, _ = ClassifiedFailure.objects.get_or_create(bug_number=bug)
            else:
                obj = ClassifiedFailure()
                obj.save()
            rv.append(obj)

        if not many:
            rv = rv[0]

        return self.serializer_class(rv, many=many).data
Ejemplo n.º 6
0
def classified_failures(request, jm, eleven_jobs_stored, failure_lines,
                        test_matcher, failure_classifications):
    from treeherder.model.models import ClassifiedFailure

    job_1 = jm.get_job(1)[0]

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == job_1["job_guid"]:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            failure_line.set_classification(test_matcher.db_object, classified_failure,
                                            mark_best=True)
            classified_failures.append(classified_failure)

    return classified_failures
Ejemplo n.º 7
0
def classified_failures(test_job, failure_lines, test_matcher,
                        failure_classifications):
    from treeherder.model.models import ClassifiedFailure
    from treeherder.model.search import refresh_all

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == test_job.guid:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            failure_line.set_classification(test_matcher.db_object,
                                            classified_failure,
                                            mark_best=True)
            classified_failures.append(classified_failure)

    refresh_all()
    return classified_failures
def test_put_duplicate_multiple_repeated(client, classified_failures,
                                         test_user):
    client.force_authenticate(user=test_user)

    new = ClassifiedFailure(bug_number=1234)
    new.save()
    classified_failures.append(new)

    resp = client.put(
        reverse("classified-failure-list"),
        [{
            "id": classified_failures[0].id,
            "bug_number": 1234
        }],
    )
    assert resp.status_code == 200
    new_classified_failures = ClassifiedFailure.objects.all()
    assert [item.id for item in new_classified_failures] == [2, 3]
    assert [item.bug_number
            for item in new_classified_failures] == [None, 1234]
    resp = client.put(
        reverse("classified-failure-list"),
        [{
            "id": classified_failures[0].id,
            "bug_number": 1234
        }, {
            "id": classified_failures[1].id,
            "bug_number": 1234
        }],
    )

    actual = resp.data
    assert len(actual) == 2
    expected = [{
        "id": new.id,
        "bug_number": 1234,
        "bug": None
    }, {
        "id": new.id,
        "bug_number": 1234,
        "bug": None
    }]
    assert actual == expected
Ejemplo n.º 9
0
def classified_failures(test_job, text_log_errors_failure_lines, test_matcher,
                        failure_classifications):
    from treeherder.model.models import ClassifiedFailure
    from treeherder.model.search import refresh_all

    _, failure_lines = text_log_errors_failure_lines

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == test_job.guid:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            failure_line.set_classification(test_matcher.db_object,
                                            classified_failure,
                                            mark_best=True)
            classified_failures.append(classified_failure)

    refresh_all()
    return classified_failures
Ejemplo n.º 10
0
def classified_failures(request, jm, eleven_jobs_stored, failure_lines,
                        test_matcher, failure_classifications):
    from treeherder.model.models import ClassifiedFailure
    from treeherder.model.search import refresh_all

    job_1 = jm.get_job(1)[0]

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == job_1["job_guid"]:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            failure_line.set_classification(test_matcher.db_object,
                                            classified_failure,
                                            mark_best=True)
            classified_failures.append(classified_failure)

    refresh_all()
    return classified_failures
Ejemplo n.º 11
0
def classified_failures(test_job, text_log_errors_failure_lines, test_matcher,
                        failure_classifications):
    from treeherder.model.models import ClassifiedFailure
    from treeherder.services.elasticsearch import refresh_index

    _, failure_lines = text_log_errors_failure_lines

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == test_job.guid:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            failure_line.set_classification(test_matcher.db_object,
                                            classified_failure,
                                            mark_best=True)
            classified_failures.append(classified_failure)

    if settings.ELASTICSEARCH_URL:
        refresh_index()

    return classified_failures
Ejemplo n.º 12
0
def classified_failures(test_job, text_log_errors_failure_lines, test_matcher,
                        failure_classifications):
    from treeherder.model.models import ClassifiedFailure
    from treeherder.services.elasticsearch import refresh_index

    _, failure_lines = text_log_errors_failure_lines

    classified_failures = []

    for failure_line in failure_lines:
        if failure_line.job_guid == test_job.guid:
            classified_failure = ClassifiedFailure()
            classified_failure.save()
            failure_line.set_classification(test_matcher,
                                            classified_failure,
                                            mark_best=True)
            classified_failures.append(classified_failure)

    if settings.ELASTICSEARCH_URL:
        refresh_index()

    return classified_failures