Bug 1292270 - Pass a User object down to JobManager.update_after_verification. (#1760)

* Bug 1292270 - Pass a User object down to JobManager.update_after_verification.

This is required to create the BugJobMap instance in the post-datasource world.
This commit is contained in:
jgraham 2016-08-05 01:14:20 +01:00 коммит произвёл camd
Родитель 4c8d3f69e6
Коммит 223e5bcb33
5 изменённых файлов: 46 добавлений и 10 удалений

Просмотреть файл

@ -20,3 +20,5 @@ BZ_API_URL = "https://thisisnotbugzilla.org"
ELASTIC_SEARCH.update({
"index_prefix": "test",
})
AUTOCLASSIFY_JOBS = True

Просмотреть файл

@ -1,6 +1,11 @@
from django.core.urlresolvers import reverse
from rest_framework.test import APIClient
from treeherder.model.models import (BugJobMap,
FailureLine,
JobNote,
TextLogSummary)
def test_get_summary_line(webapp, text_summary_lines):
"""
@ -124,3 +129,31 @@ def test_put_multiple_duplicate(webapp, text_summary_lines, test_user):
format="json")
assert resp.status_code == 400
def test_put_verify_job(webapp, jm, text_summary_lines, test_user, failure_classifications):
client = APIClient()
client.force_authenticate(user=test_user)
job = jm.get_job(1)[0]
FailureLine.objects.filter(job_guid=job["job_guid"]).update(best_is_verified=True)
text_summary_lines = TextLogSummary.objects.filter(job_guid=job["job_guid"]).get().lines.all()
assert len(text_summary_lines) > 0
data = [{"id": item.id, "bug_number": i + 1, "verified": True} for
i, item in enumerate(text_summary_lines)]
resp = client.put(reverse("text-log-summary-line-list"),
data, format="json")
assert resp.status_code == 200
assert jm.is_fully_verified(1)
bug_job_items = BugJobMap.objects.filter(job__project_specific_id=1)
assert {item.bug_id for item in bug_job_items} == set(range(1, len(text_summary_lines) + 1))
assert all(item.user == test_user for item in bug_job_items)
note = JobNote.objects.filter(job__project_specific_id=1).get()
assert note.user == test_user
assert note.failure_classification.name == "intermittent"

Просмотреть файл

@ -407,7 +407,7 @@ SILENCED_SYSTEM_CHECKS = [
]
# Enable integration between autoclassifier and jobs
AUTOCLASSIFY_JOBS = env.bool("AUTOCLASSIFY_JOBS", default=False)
AUTOCLASSIFY_JOBS = env.bool("AUTOCLASSIFY_JOBS", default=True)
# Ordered list of matcher classes to use during autoclassification
AUTOCLASSIFY_MATCHERS = ["PreciseTestMatcher", "CrashSignatureMatcher",
"ElasticSearchTestMatcher"]

Просмотреть файл

@ -422,7 +422,7 @@ class JobsModel(TreeherderModelBase):
return failure_lines[0]
def update_after_autoclassification(self, job_id, user=None):
def update_after_autoclassification(self, job_id):
if not settings.AUTOCLASSIFY_JOBS:
return
@ -525,10 +525,11 @@ class JobsModel(TreeherderModelBase):
if item.bug_number}
for bug_number in bug_numbers:
BugJobMap.objects.create(job=job,
bug_id=bug_number,
created=datetime.now(),
user=user)
BugJobMap.objects.get_or_create(job=job,
bug_id=bug_number,
defaults={
'user': user
})
# if user is not specified, then this is an autoclassified job note
# and we should mark it as such

Просмотреть файл

@ -25,7 +25,7 @@ class TextLogSummaryLineViewSet(viewsets.ModelViewSet):
filter_class = TextLogSummaryLineFilter
pagination_class = pagination.IdPagination
def _update(self, data, email, many=False):
def _update(self, data, user, many=False):
line_ids = []
for item in data:
line_id = item.get("id")
@ -65,7 +65,7 @@ class TextLogSummaryLineViewSet(viewsets.ModelViewSet):
with JobsModel(project) as jm:
jobs = jm.get_job_ids_by_guid(job_guids)
for job in jobs.values():
jm.update_after_verification(job["id"], email)
jm.update_after_verification(job["id"], user)
if not many:
rv = rv[0]
@ -78,11 +78,11 @@ class TextLogSummaryLineViewSet(viewsets.ModelViewSet):
if k not in data:
data[k] = v
body, status = self._update([data], request.user.email, many=False)
body, status = self._update([data], request.user, many=False)
return Response(body, status=status)
def update_many(self, request):
body, status = self._update(request.data, request.user.email, many=True)
body, status = self._update(request.data, request.user, many=True)
if status == HTTP_404_NOT_FOUND:
# 404 doesn't make sense for updating many since the path is always