def test_autoclassified_after_manual_classification(test_user,
                                                    test_job_2,
                                                    text_log_errors_failure_lines,
                                                    failure_classifications, bugs):
    lines = [(test_line, {})]
    test_error_lines, test_failure_lines = create_lines(test_job_2, lines)
    bug = bugs.first()

    BugJobMap.create(
        job_id=test_job_2.id,
        bug_id=bug.id,
        user=test_user
    )
    JobNote.objects.create(job=test_job_2,
                           failure_classification_id=4,
                           user=test_user,
                           text="")

    for error_line, failure_line in zip(test_error_lines, test_failure_lines):
        error_line.refresh_from_db()
        error_line.metadata.refresh_from_db()
        failure_line.refresh_from_db()

    tle1 = test_error_lines[0]
    fl1 = test_failure_lines[0]

    assert tle1.matches.count() == 1
    assert tle1.metadata.best_classification == tle1.classified_failures.first()
    assert tle1.metadata.best_is_verified

    assert fl1.error.matches.count() == 1
    assert fl1.error.metadata.best_classification == fl1.error.classified_failures.first()
    assert fl1.text_log_error_metadata.best_is_verified
Esempio n. 2
0
def test_update_autoclassification_bug(test_job, test_job_2,
                                       classified_failures):
    classified_failure = classified_failures[0]
    user = User.objects.create()

    # create some TextLogErrors attached to test_job_2
    text_log_errors, _ = create_lines(test_job_2, [(test_line, {})])

    # Job 1 has two failure lines so nothing should be updated
    assert classified_failure.bug_number is None

    # Create a BugJobMap
    BugJobMap.create(
        job_id=test_job.id,
        bug_id=1234,
        user=user,
    )
    mark_best_classification(text_log_errors[0], classified_failure)
    assert classified_failure.bug_number is None

    metadata = TextLogErrorMetadata.objects.get(
        text_log_error__step__job=test_job_2)
    metadata.failure_line = FailureLine.objects.get(pk=3)
    metadata.save()

    BugJobMap.create(
        job_id=test_job_2.id,
        bug_id=1234,
        user=user,
    )
    classified_failure.refresh_from_db()
    assert classified_failure.bug_number == 1234
Esempio n. 3
0
def test_bug_job_map_delete(
    client, eleven_jobs_stored, test_repository, test_user, test_no_auth, bugs
):
    """
    test deleting a bug_job_map object
    """
    job = Job.objects.first()
    bug = bugs[0]

    BugJobMap.create(
        job_id=job.id, bug_id=bug.id, user=test_user,
    )

    if not test_no_auth:
        client.force_authenticate(user=test_user)

    pk = "{0}-{1}".format(job.id, bug.id)

    resp = client.delete(
        reverse("bug-job-map-detail", kwargs={"project": test_repository.name, "pk": pk})
    )

    if test_no_auth:
        assert resp.status_code == 403
        assert BugJobMap.objects.count() == 1
    else:
        content = json.loads(resp.content)
        assert content == {"message": "Bug job map deleted"}
        assert BugJobMap.objects.count() == 0
def test_update_autoclassification_bug(test_job, test_job_2, classified_failures):
    classified_failure = classified_failures[0]
    user = User.objects.create()

    # create some TextLogErrors attached to test_job_2
    text_log_errors, _ = create_lines(test_job_2, [(test_line, {})])

    # Job 1 has two failure lines so nothing should be updated
    assert classified_failure.bug_number is None

    # Create a BugJobMap
    BugJobMap.create(
        job_id=test_job.id,
        bug_id=1234,
        user=user,
    )
    mark_best_classification(text_log_errors[0], classified_failure)
    assert classified_failure.bug_number is None

    metadata = TextLogErrorMetadata.objects.get(text_log_error__step__job=test_job_2)
    metadata.failure_line = FailureLine.objects.get(pk=3)
    metadata.save()

    BugJobMap.create(
        job_id=test_job_2.id,
        bug_id=1234,
        user=user,
    )
    classified_failure.refresh_from_db()
    assert classified_failure.bug_number == 1234
def test_autoclassified_after_manual_classification(
        test_user, test_job_2, text_log_errors_failure_lines,
        failure_classifications, bugs):
    lines = [(test_line, {})]
    test_error_lines, test_failure_lines = create_lines(test_job_2, lines)
    bug = bugs.first()

    BugJobMap.create(job_id=test_job_2.id, bug_id=bug.id, user=test_user)
    JobNote.objects.create(job=test_job_2,
                           failure_classification_id=4,
                           user=test_user,
                           text="")

    for error_line, failure_line in zip(test_error_lines, test_failure_lines):
        error_line.refresh_from_db()
        error_line.metadata.refresh_from_db()
        failure_line.refresh_from_db()

    tle1 = test_error_lines[0]
    fl1 = test_failure_lines[0]

    assert tle1.matches.count() == 1
    assert tle1.metadata.best_classification == tle1.classified_failures.first(
    )
    assert tle1.metadata.best_is_verified

    assert fl1.error.matches.count() == 1
    assert fl1.error.metadata.best_classification == fl1.error.classified_failures.first(
    )
    assert fl1.text_log_error_metadata.best_is_verified
Esempio n. 6
0
def test_bug_job_map_delete(client, eleven_jobs_stored, test_repository,
                            test_user, test_no_auth, bugs):
    """
    test deleting a bug_job_map object
    """
    job = Job.objects.first()
    bug = bugs[0]

    BugJobMap.create(
        job_id=job.id,
        bug_id=bug.id,
        user=test_user,
    )

    if not test_no_auth:
        client.force_authenticate(user=test_user)

    pk = "{0}-{1}".format(job.id, bug.id)

    resp = client.delete(
        reverse("bug-job-map-detail", kwargs={
            "project": test_repository.name,
            "pk": pk
        })
    )

    if test_no_auth:
        assert resp.status_code == 403
        assert BugJobMap.objects.count() == 1
    else:
        content = json.loads(resp.content)
        assert content == {"message": "Bug job map deleted"}
        assert BugJobMap.objects.count() == 0
Esempio n. 7
0
    def create(self, request, project):
        """Add a new relation between a job and a bug."""
        job_id = int(request.data['job_id'])
        bug_id = int(request.data['bug_id'])

        try:
            BugJobMap.create(
                job_id=job_id, bug_id=bug_id, user=request.user,
            )
            message = "Bug job map saved"
        except IntegrityError:
            message = "Bug job map skipped: mapping already exists"

        return Response({"message": message})
Esempio n. 8
0
def test_bug_job_map_list(client, test_repository, eleven_jobs_stored, test_user, bugs):
    """
    test retrieving a list of bug_job_map
    """
    jobs = Job.objects.all()[:10]

    expected = list()

    for (i, job) in enumerate(jobs):
        bjm = BugJobMap.create(job_id=job.id, bug_id=bugs[i].id, user=test_user,)

        expected.append(
            {
                "job_id": job.id,
                "bug_id": bugs[i].id,
                "created": bjm.created.isoformat(),
                "who": test_user.email,
            }
        )

    # verify that API works with different combinations of job_id= parameters
    for job_range in [(0, 1), (0, 2), (0, 9)]:
        resp = client.get(
            reverse("bug-job-map-list", kwargs={"project": test_repository.name}),
            data={'job_id': [job.id for job in jobs[job_range[0] : job_range[1]]]},
        )
        assert resp.status_code == 200
        assert resp.json() == expected[job_range[0] : job_range[1]]
Esempio n. 9
0
def test_bug_job_map_detail(client, eleven_jobs_stored, test_repository,
                            test_user, bugs):
    """
    test retrieving a list of bug_job_map
    """
    job = Job.objects.first()
    bug = bugs[0]
    expected = list()

    bjm = BugJobMap.create(
        job_id=job.id,
        bug_id=bug.id,
        user=test_user,
    )

    pk = "{0}-{1}".format(job.id, bug.id)

    resp = client.get(
        reverse("bug-job-map-detail",
                kwargs={
                    "project": test_repository.name,
                    "pk": pk
                }))
    assert resp.status_code == 200

    expected = {
        "job_id": job.id,
        "bug_id": bug.id,
        "created": bjm.created.isoformat(),
        "who": test_user.email,
    }
    assert resp.json() == expected
Esempio n. 10
0
def test_bug_job_map_detail(client, eleven_jobs_stored, test_repository,
                            test_user, bugs):
    """
    test retrieving a list of bug_job_map
    """
    job = Job.objects.first()
    bug = bugs[0]
    expected = list()

    bjm = BugJobMap.create(
        job_id=job.id,
        bug_id=bug.id,
        user=test_user,
    )

    pk = "{0}-{1}".format(job.id, bug.id)

    resp = client.get(
        reverse("bug-job-map-detail", kwargs={
            "project": test_repository.name,
            "pk": pk
        })
    )
    assert resp.status_code == 200

    expected = {
        "job_id": job.id,
        "bug_id": bug.id,
        "created": bjm.created.isoformat(),
        "who": test_user.email
    }
    assert resp.json() == expected
Esempio n. 11
0
def test_bug_job_map_list(client, test_repository, eleven_jobs_stored, test_user, bugs):
    """
    test retrieving a list of bug_job_map
    """
    jobs = Job.objects.all()[:10]

    expected = list()

    for (i, job) in enumerate(jobs):
        bjm = BugJobMap.create(
            job_id=job.id,
            bug_id=bugs[i].id,
            user=test_user,
        )

        expected.append({
            "job_id": job.id,
            "bug_id": bugs[i].id,
            "created": bjm.created.isoformat(),
            "who": test_user.email
        })

    # verify that API works with different combinations of job_id= parameters
    for job_range in [(0, 1), (0, 2), (0, 9)]:
        resp = client.get(
            reverse("bug-job-map-list", kwargs={"project": test_repository.name}),
            data={'job_id': [job.id for job in
                             jobs[job_range[0]:job_range[1]]]})
        assert resp.status_code == 200
        assert resp.json() == expected[job_range[0]:job_range[1]]
Esempio n. 12
0
    def create(self, request, project):
        """Add a new relation between a job and a bug."""
        job_id = int(request.data['job_id'])
        bug_id = int(request.data['bug_id'])

        try:
            BugJobMap.create(
                job_id=job_id,
                bug_id=bug_id,
                user=request.user,
            )
            message = "Bug job map saved"
        except IntegrityError:
            message = "Bug job map skipped: mapping already exists"

        return Response({"message": message})
Esempio n. 13
0
def bug_data(eleven_jobs_stored, test_repository, test_push, bugs):
    from treeherder.model.models import Job, BugJobMap, Option

    jobs = Job.objects.all()
    bug_id = bugs[0].id
    job_id = jobs[0].id
    BugJobMap.create(job_id=job_id, bug_id=bug_id)
    query_string = '?startday=2012-05-09&endday=2018-05-10&tree={}'.format(test_repository.name)

    return {
        'tree': test_repository.name,
        'option': Option.objects.first(),
        'bug_id': bug_id,
        'job': jobs[0],
        'jobs': jobs,
        'query_string': query_string,
    }
Esempio n. 14
0
def bug_data(eleven_jobs_stored, test_repository, test_push, bugs):
    from treeherder.model.models import (Job,
                                         BugJobMap,
                                         Option)
    jobs = Job.objects.all()
    bug_id = bugs[0].id
    job_id = jobs[0].id
    BugJobMap.create(job_id=job_id, bug_id=bug_id)
    query_string = '?startday=2012-05-09&endday=2018-05-10&tree={}'.format(
        test_repository.name)

    return {
        'tree': test_repository.name,
        'option': Option.objects.first(),
        'bug_id': bug_id,
        'job': jobs[0],
        'jobs': jobs,
        'query_string': query_string
    }