<commit_before># Copyright (C) 2014 Linaro Limited
#
# Author: <NAME> <<EMAIL>>
#
# This file is part of Testmanager.
#
# Testmanager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3
# as published by the Free Software Foundation
#
# Testmanager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Testmanager.  If not, see <http://www.gnu.org/licenses/>.

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import (
    HttpResponse,
    HttpResponseRedirect
)
from django.shortcuts import get_object_or_404
from django.template import RequestContext, loader

from testmanager.testrunner.models import (
    JenkinsJob,
    JenkinsBuild,
    LavaJob,
    LavaJobTestResult,
)
from testmanager.testrunner.forms import ResultComparisonForm


@login_required
def index(request):
    jenkins_jobs = JenkinsJob.objects.all()
    template = loader.get_template('testrunner/index.html')
    context = RequestContext(request, {
        'jenkins_jobs': jenkins_jobs,
    })
    return HttpResponse(template.render(context))

@login_required
def jenkins_job_view(request, job_name):
    jenkins_job = get_object_or_404(JenkinsJob, name=job_name)
    jenkins_builds = jenkins_job.builds.filter(is_umbrella=False).order_by("-timestamp")[:10]
    template = loader.get_template('testrunner/jenkins_job_view.html')
    context = RequestContext(request, {
        'jenkins_job': jenkins_job,
        'jenkins_builds': jenkins_builds
    })
    return HttpResponse(template.render(context))

@login_required
def jenkins_build_view(request, job_name, build_number):
    jenkins_job = get_object_or_404(JenkinsJob, name=job_name)
    jenkins_build = jenkins_job.builds.filter(number = build_number)
    jenkins_umbrella_build = jenkins_build.filter(is_umbrella = True)
    if jenkins_umbrella_build.all():
        jenkins_build = jenkins_umbrella_build
    template = loader.get_template('testrunner/jenkins_build_view.html')
    context = RequestContext(request, {
        'jenkins_build': jenkins_build,
        'lava_url': settings.LAVA_JOB_ID_REGEXP.rsplit("/", 1)[0],
    })
    return HttpResponse(template.render(context))

@login_required
def lava_job_view(request, job_name, build_number, lava_job_number):
    lava_job = get_object_or_404(LavaJob, number=lava_job_number)
    template = loader.get_template('testrunner/lava_job_view.html')
    context = RequestContext(request, {
        'lava_job': lava_job,
        'lava_url': settings.LAVA_JOB_ID_REGEXP.rsplit("/", 1)[0],
    })
    return HttpResponse(template.render(context))

@login_required
def compare_results(request):
    if request.method == "GET":
        form = ResultComparisonForm(request.GET)
        if form.is_valid():
            testsets = form.cleaned_data['testresults']
            testcase_names = LavaJobTestResult.objects.filter(
                lava_job_result__in=testsets).order_by("test_case_id").values("test_case_id").distinct("test_case_id")
            testcase_list = []
            for testcase in testcase_names:
                tc_id = testcase['test_case_id']
                testcase_list.append({'name': tc_id, 'results': [], 'is_different': False})
                for testset in testsets:
                    result = testset.lavajobtestresult_set.filter(test_case_id=tc_id)
                    if result:
                        testcase_list[-1]['results'].append(result[0].status.name) # there should be only one?
                    else:
                        testcase_list[-1]['results'].append("-")
                if len(set(testcase_list[-1]['results'])) > 1:
                    testcase_list[-1]['is_different'] = True

            template = loader.get_template('testrunner/compare_results.html')
            context = RequestContext(request, {
                'testsets': testsets,
                'testcases': testcase_list,
            })
            return HttpResponse(template.render(context))
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
<commit_msg>unused imports<commit_after># Copyright (C) 2014 Linaro Limited
#
# Author: <NAME> <<EMAIL>>
#
# This file is part of Testmanager.
#
# Testmanager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3
# as published by the Free Software Foundation
#
# Testmanager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Testmanager.  If not, see <http://www.gnu.org/licenses/>.

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import (
    HttpResponse,
    HttpResponseRedirect
)
from django.shortcuts import get_object_or_404
from django.template import RequestContext, loader

from testmanager.testrunner.models import (
    JenkinsJob,
    LavaJob,
    LavaJobTestResult,
)
from testmanager.testrunner.forms import ResultComparisonForm


@login_required
def index(request):
    jenkins_jobs = JenkinsJob.objects.all()
    template = loader.get_template('testrunner/index.html')
    context = RequestContext(request, {
        'jenkins_jobs': jenkins_jobs,
    })
    return HttpResponse(template.render(context))

@login_required
def jenkins_job_view(request, job_name):
    jenkins_job = get_object_or_404(JenkinsJob, name=job_name)
    jenkins_builds = jenkins_job.builds.filter(is_umbrella=False).order_by("-timestamp")[:10]
    template = loader.get_template('testrunner/jenkins_job_view.html')
    context = RequestContext(request, {
        'jenkins_job': jenkins_job,
        'jenkins_builds': jenkins_builds
    })
    return HttpResponse(template.render(context))

@login_required
def jenkins_build_view(request, job_name, build_number):
    jenkins_job = get_object_or_404(JenkinsJob, name=job_name)
    jenkins_build = jenkins_job.builds.filter(number = build_number)
    jenkins_umbrella_build = jenkins_build.filter(is_umbrella = True)
    if jenkins_umbrella_build.all():
        jenkins_build = jenkins_umbrella_build
    template = loader.get_template('testrunner/jenkins_build_view.html')
    context = RequestContext(request, {
        'jenkins_build': jenkins_build,
        'lava_url': settings.LAVA_JOB_ID_REGEXP.rsplit("/", 1)[0],
    })
    return HttpResponse(template.render(context))

@login_required
def lava_job_view(request, job_name, build_number, lava_job_number):
    lava_job = get_object_or_404(LavaJob, number=lava_job_number)
    template = loader.get_template('testrunner/lava_job_view.html')
    context = RequestContext(request, {
        'lava_job': lava_job,
        'lava_url': settings.LAVA_JOB_ID_REGEXP.rsplit("/", 1)[0],
    })
    return HttpResponse(template.render(context))

@login_required
def compare_results(request):
    if request.method == "GET":
        form = ResultComparisonForm(request.GET)
        if form.is_valid():
            testsets = form.cleaned_data['testresults']
            testcase_names = LavaJobTestResult.objects.filter(
                lava_job_result__in=testsets).order_by("test_case_id").values("test_case_id").distinct("test_case_id")
            testcase_list = []
            for testcase in testcase_names:
                tc_id = testcase['test_case_id']
                testcase_list.append({'name': tc_id, 'results': [], 'is_different': False})
                for testset in testsets:
                    result = testset.lavajobtestresult_set.filter(test_case_id=tc_id)
                    if result:
                        testcase_list[-1]['results'].append(result[0].status.name) # there should be only one?
                    else:
                        testcase_list[-1]['results'].append("-")
                if len(set(testcase_list[-1]['results'])) > 1:
                    testcase_list[-1]['is_different'] = True

            template = loader.get_template('testrunner/compare_results.html')
            context = RequestContext(request, {
                'testsets': testsets,
                'testcases': testcase_list,
            })
            return HttpResponse(template.render(context))
    return HttpResponseRedirect(request.META['HTTP_REFERER'])

{'fraction_non_alphanumeric': 0.09829499942785215, 'fraction_numerical': 0.0066369149788305295, 'mean_word_length': 3.493573264781491, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4309845', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2582, 'n_words': 552}