From nobody Mon Dec 15 01:57:10 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557925128; cv=none; d=zoho.com; s=zohoarc; b=lyP+Sn2Ysmb/02g6Pt5V+7MMZTDqgK5OxJ9604BPg6TDOF5/QPbyv7fdhsjfasFWvM5e+dLumA+s/G3/ksWANU/X39qbSDiQSsrj8gqTxPa9fyyvdnV2lCwezBPp+8r/ovckA56xl6ebRCHK6OFnzuwDM6+m3UAIJUOaeZLWlpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925128; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=N/yCLpe7itOvMFGX6EkktnTysqw0i4vl1jaE8jrDbpw=; b=OjueQoP1sdSIy05kgjdtMsj4GvIe74/CKhuMK3MK9kEMCuL7x6NMvbouoe/2u5X6RDS3OqJKtpqVytKDC76mye5DlS4XH2Va12iN7OrMQTL3ANVJ29ofeRhfbyY6GWDYLkdq7xZF+NsqrCqB5S6uz2SFQ9liLjuVFarntqP25po= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557925128821744.7698778234418; Wed, 15 May 2019 05:58:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8CCF530B7B9D; Wed, 15 May 2019 12:58:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81CAD5C1A3; Wed, 15 May 2019 12:58:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7902C18089CB; Wed, 15 May 2019 12:58:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4FCwjuK012698 for ; Wed, 15 May 2019 08:58:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9EE9360CDA; Wed, 15 May 2019 12:58:45 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-34.ams2.redhat.com [10.36.112.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04FC760F81 for ; Wed, 15 May 2019 12:58:43 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:04 +0200 Message-Id: <20190515125808.27716-8-pbonzini@redhat.com> In-Reply-To: <20190515125808.27716-1-pbonzini@redhat.com> References: <20190515125808.27716-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 07/11] testing: add a version of testing-get under /api/v1/project/ X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 15 May 2019 12:58:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- api/rest.py | 4 +++ mods/testing.py | 76 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/api/rest.py b/api/rest.py index 9525a27..c3ec3e1 100644 --- a/api/rest.py +++ b/api/rest.py @@ -120,6 +120,10 @@ class ImportPermission(PatchewPermission): allowed_groups =3D ('importers',) =20 =20 +class TestPermission(PatchewPermission): + allowed_groups =3D ('testers',) + + # utility function to generate REST API URLs =20 def reverse_detail(obj, request): diff --git a/mods/testing.py b/mods/testing.py index 7ef8267..90bb2be 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -20,13 +20,14 @@ import time import math from api.views import APILoginRequiredView from api.models import (Message, MessageResult, Project, ProjectResult, Re= sult) -from api.rest import PluginMethodField, reverse_detail +from api.rest import PluginMethodField, TestPermission, reverse_detail from api.search import SearchEngine from event import emit_event, declare_event, register_handler from patchew.logviewer import LogView from schema import * -from rest_framework import serializers +from rest_framework import serializers, generics from rest_framework.fields import CharField, BooleanField +from rest_framework.response import Response =20 _instance =3D None =20 @@ -249,6 +250,10 @@ class TestingModule(PatchewModule): urlpatterns.append(url(r"^(?P[^/]*)/badge.(?Psvg|png= )$", self.www_view_badge, name=3D"testing-badge")) =20 + def api_url_hook(self, urlpatterns): + urlpatterns.append(url(r"^v1/projects/(?P[^/]*)/get-test/$", G= etTestView.as_view(), + name=3D"get-test")) + def reverse_testing_log(self, obj, test, request=3DNone, html=3DFalse): if isinstance(obj, Message): log_url =3D reverse("testing-log", @@ -413,21 +418,8 @@ class TestingModule(PatchewModule): return po.set_property('testing.check_in.' + tester, time.time()) =20 -class TestingGetView(APILoginRequiredView): - name =3D "testing-get" - allowed_groups =3D ["testers"] - - def _generate_test_data(self, project, repo, head, base, identity, res= ult_uri, test): - r =3D {"project": project, - "repo": repo, - "head": head, - "base": base, - "test": test, - "identity": identity, - "result_uri": result_uri, - } - return r =20 +class GetTestViewMixin(object): def _generate_series_test_data(self, request, s, result, test): gr =3D s.git_result assert gr.is_success() @@ -499,20 +491,64 @@ class TestingGetView(APILoginRequiredView): return r, s, td return None =20 - def handle(self, request, project, tester, capabilities): + def _do_testing_get(self, request, po, tester, capabilities): # Try project head test first - _instance.tester_check_in(project, tester or request.user.username) - po =3D Project.objects.get(name=3Dproject) + _instance.tester_check_in(po.name, tester or request.user.username) candidate =3D self._find_project_test(request, po, tester, capabil= ities) if not candidate: candidate =3D self._find_series_test(request, po, tester, capa= bilities) if not candidate: - return + return None r, obj, test_data =3D candidate r.status =3D Result.RUNNING r.save() return test_data =20 + +class TestingGetView(APILoginRequiredView, GetTestViewMixin): + name =3D "testing-get" + allowed_groups =3D ["testers"] + + def _generate_test_data(self, project, repo, head, base, identity, res= ult_uri, test): + r =3D {"project": project, + "repo": repo, + "head": head, + "base": base, + "test": test, + "identity": identity, + "result_uri": result_uri, + } + return r + + def handle(self, request, project, tester, capabilities): + po =3D Project.objects.get(name=3Dproject) + return self._do_testing_get(request, po, tester, capabilities) + + +class GetTestView(generics.GenericAPIView, GetTestViewMixin): + queryset =3D Project.objects.all() + permission_classes =3D (TestPermission,) + + def _generate_test_data(self, project, repo, head, base, identity, res= ult_uri, test): + r =3D {"repo": repo, + "head": head, + "base": base, + "test": test, + "identity": identity, + "result_uri": result_uri, + } + return r + + def post(self, request, *args, **kwargs): + tester =3D request.data.get('tester', '') + capabilities =3D request.data.get('capabilities', []) + test_data =3D self._do_testing_get(request, self.get_object(), tes= ter, capabilities) + if test_data: + return Response(test_data) + else: + return Response(status=3D204) + + class TestingReportView(APILoginRequiredView): name =3D "testing-report" allowed_groups =3D ["testers"] --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel