From nobody Thu Apr 25 13:40:39 2024 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=1557925103; cv=none; d=zoho.com; s=zohoarc; b=MV3Mw8GrzW0FRWHd62ud+59JzHJJzJ7w4FNIf1eQIrfLpVCINvTLD9xZzISkVLJvc1kgXFjj61XvQGaYoE1VdqbAcE1IkA7yXoXmA0gD2omV9ZkBWwN0E4uAlS2TwMa6XHOcuD4o5bbk6NehQagn9uNQ3/lwLpYtdG2xYcqQzLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925103; 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=EMOkIeNHtayq0yWmMg+ToBx45Z9Pa5vVHb5XhqOM8QM=; b=DSqqWIFTXczp+/tImZR6ZqCO7ChaZ0RXa9yU+88B82jaFvxnnJCz7Jzdffti5f6ofhgD6nYRtOrY654/E2jrC5tQsfT8A8bfujt2G0NJL8FejGRUwCvpE+DKq4qvamaJbAyRsNtKP31o9Pf0PL7vUP4zcd7t3CQPWKJZ353Mxg0= 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 1557925103351559.4929059727525; Wed, 15 May 2019 05:58:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 030083001C62; Wed, 15 May 2019 12:58:22 +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 EAF271001E61; Wed, 15 May 2019 12:58:21 +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 E1C5418089CB; Wed, 15 May 2019 12:58:21 +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 x4FCwL65012629 for ; Wed, 15 May 2019 08:58:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 150C460CDA; Wed, 15 May 2019 12:58:21 +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 ABB1C60CC0 for ; Wed, 15 May 2019 12:58:16 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:57:58 +0200 Message-Id: <20190515125808.27716-2-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 01/11] rest: add PATCH support for series and messages 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.84 on 10.5.11.22 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:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Allow modifying those fields that are not directly derived from the mbox. The complication is that PATCH and POST now support a different set of fields (POST allows writing arbitrary data to the message) so we need to use get_serializer_class() instead of the simpler serializer_class. Signed-off-by: Paolo Bonzini --- api/rest.py | 52 +++++++++++++++++++++++++++++++++------------- tests/test_rest.py | 32 ++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/api/rest.py b/api/rest.py index 1bd637d..3b6ab2f 100644 --- a/api/rest.py +++ b/api/rest.py @@ -22,9 +22,10 @@ from rest_framework.decorators import action from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField, ListField from rest_framework.relations import HyperlinkedIdentityField from rest_framework.response import Response +from rest_framework.views import APIView import rest_framework from mbox import addr_db_to_rest, MboxMessage -from rest_framework.parsers import JSONParser, BaseParser +from rest_framework.parsers import BaseParser =20 SEARCH_PARAM =3D 'q' =20 @@ -274,7 +275,8 @@ class AddressSerializer(serializers.Serializer): class BaseMessageSerializer(serializers.ModelSerializer): class Meta: model =3D Message - fields =3D ('resource_uri', 'message_id', 'subject', 'date', 'send= er', 'recipients', 'tags') + read_only_fields =3D ('resource_uri', 'message_id', 'subject', 'da= te', 'sender', 'recipients') + fields =3D read_only_fields + ('tags', ) =20 resource_uri =3D HyperlinkedMessageField(view_name=3D'messages-detail') recipients =3D AddressSerializer(many=3DTrue) @@ -300,7 +302,7 @@ class BaseMessageViewSet(mixins.ListModelMixin, viewset= s.GenericViewSet): =20 =20 # a (project, message_id) tuple is unique, so we can always retrieve an ob= ject -class ProjectMessagesViewSetMixin(mixins.RetrieveModelMixin): +class ProjectMessagesViewSetMixin(mixins.RetrieveModelMixin, mixins.Update= ModelMixin): def get_queryset(self): return self.queryset.filter(project=3Dself.kwargs['projects_pk']) =20 @@ -342,10 +344,12 @@ class PatchSerializer(BaseMessageSerializer): class SeriesSerializer(BaseMessageSerializer): class Meta: model =3D Message - fields =3D ('resource_uri',) + BaseMessageSerializer.Meta.fields += ( - 'message', 'stripped_subject', 'last_comment_date', 'last_repl= y_date', - 'is_complete', 'is_merged', 'num_patches', 'total_patches', 'r= esults', + subclass_read_only_fields =3D ('message', 'stripped_subject', 'num= _patches', + 'total_patches', 'results') + fields =3D BaseMessageSerializer.Meta.fields + subclass_read_only_= fields + ( + 'last_comment_date', 'last_reply_date', 'is_complete', 'is_mer= ged', 'is_obsolete', 'is_tested', 'is_reviewed', 'maintainers') + read_only_fields =3D BaseMessageSerializer.Meta.read_only_fields += subclass_read_only_fields =20 resource_uri =3D HyperlinkedMessageField(view_name=3D'series-detail') message =3D HyperlinkedMessageField(view_name=3D'messages-detail') @@ -416,7 +420,8 @@ class SeriesViewSet(BaseMessageViewSet): =20 =20 class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, - SeriesViewSet, mixins.DestroyModelMixin): + SeriesViewSet, mixins.UpdateModelMixin, + mixins.DestroyModelMixin): def collect_patches(self, series): if series.is_patch: patches =3D [series] @@ -456,11 +461,12 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixi= n, =20 # Messages =20 -# TODO: add POST endpoint connected to email plugin? class MessageSerializer(BaseMessageSerializer): class Meta: model =3D Message fields =3D BaseMessageSerializer.Meta.fields + ('mbox', ) + read_only_fields =3D BaseMessageSerializer.Meta.read_only_fields += ('mbox', ) + mbox =3D CharField() =20 def get_fields(self): @@ -476,6 +482,14 @@ class MessageSerializer(BaseMessageSerializer): return fields =20 =20 +class MessageCreationSerializer(BaseMessageSerializer): + class Meta: + model =3D Message + fields =3D BaseMessageSerializer.Meta.fields + ('mbox', ) + read_only_fields =3D [] + + mbox =3D CharField() + class StaticTextRenderer(renderers.BaseRenderer): media_type =3D 'text/plain' format =3D 'mbox' @@ -497,10 +511,15 @@ class MessagePlainTextParser(BaseParser): return MboxMessage(data).get_json() =20 =20 -class ProjectMessagesViewSet(ProjectMessagesViewSetMixin, - BaseMessageViewSet, mixins.CreateModelMixin): - serializer_class =3D MessageSerializer - parser_classes =3D (JSONParser, MessagePlainTextParser, ) +class ProjectMessagesViewSet(ProjectMessagesViewSetMixin, BaseMessageViewS= et, + mixins.CreateModelMixin, mixins.UpdateModelMi= xin): + parser_classes =3D APIView.parser_classes + [MessagePlainTextParser] + + def get_serializer_class(self, *args, **kwargs): + if self.request.method =3D=3D 'POST': + return MessageCreationSerializer + else: + return MessageSerializer =20 @action(detail=3DTrue, renderer_classes=3D[StaticTextRenderer]) def mbox(self, request, *args, **kwargs): @@ -519,9 +538,14 @@ class ProjectMessagesViewSet(ProjectMessagesViewSetMix= in, =20 =20 class MessagesViewSet(BaseMessageViewSet): - serializer_class =3D MessageSerializer permission_classes =3D (permissions.IsAuthenticatedOrReadOnly,) - parser_classes =3D (JSONParser, MessagePlainTextParser, ) + parser_classes =3D APIView.parser_classes + [MessagePlainTextParser] + + def get_serializer_class(self, *args, **kwargs): + if self.request.method =3D=3D 'POST': + return MessageCreationSerializer + else: + return MessageSerializer =20 def create(self, request, *args, **kwargs): m =3D MboxMessage(request.data['mbox']) diff --git a/tests/test_rest.py b/tests/test_rest.py index dd38035..d6cbf62 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -353,6 +353,24 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data['subject'], "[Qemu-devel] [PATCH v2 10/= 27] imx_fec: Reserve full 4K " "page for the register file") =20 + def test_patch_message(self): + the_tags =3D ['Reviewed-by: Paolo Bonzini (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 1557925108169733.1053436590329; Wed, 15 May 2019 05:58:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 187843082A2A; Wed, 15 May 2019 12:58:27 +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 0E7DE1995D; Wed, 15 May 2019 12:58:27 +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 05F3418089CB; Wed, 15 May 2019 12:58:27 +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 x4FCwPwb012640 for ; Wed, 15 May 2019 08:58:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC1FE60CC0; Wed, 15 May 2019 12:58:25 +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 144E260E39 for ; Wed, 15 May 2019 12:58:21 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:57:59 +0200 Message-Id: <20190515125808.27716-3-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 02/11] rest: switch pagination to limit/offset 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 15 May 2019 12:58:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This will come in handy to fetch only one unapplied series in the importer. --- patchew/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patchew/settings.py b/patchew/settings.py index 4e10b44..c5b5295 100644 --- a/patchew/settings.py +++ b/patchew/settings.py @@ -68,7 +68,7 @@ REST_FRAMEWORK =3D { 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication', ), - 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagin= ation', + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagi= nation', 'URL_FIELD_NAME': 'resource_uri', 'PAGE_SIZE': 50, 'UPLOADED_FILES_USE_URL': True, --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925112; cv=none; d=zoho.com; s=zohoarc; b=W1r9239TnTo+qIpoAxLexP6Uho7YKWL/mt3Q+cUUQnk2eyNchqPQsp9q9KzmyM6KkTeqfayWoFeP9FSqU5jt1WwGOzltmU5bQFHqDzgMtyec2qGPFmitUG2DExDzQVwX6yw3On16PuqBAq6DfqCCA8hw9mv3enzslxQS6PSFnmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925112; 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=awbIx3PhFhyR87Cnz2Hk5VsdLpjI70mcI1aWq9EKsRU=; b=IxherV7eABmeekJgl6jN9mK97p4sgRTTJYPHMHKqOKNrBqCNDw4jpsDA2ieTfACbfjvKtiV6LI16l63AHVGYUZhkyGBRmUoQEeBsm9CNIxCdebcKYU/JA2Fw6Hqn7jnbC8q7OmTW8EGtF1bt50Ot+tig0eTeXJyXY1CG4IuhDF4= 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 155792511252036.57355910405738; Wed, 15 May 2019 05:58:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31FFD307CDC1; Wed, 15 May 2019 12:58:31 +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 27E8D5D9C3; Wed, 15 May 2019 12:58:31 +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 1FCBA18089CB; Wed, 15 May 2019 12:58:31 +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 x4FCwTZv012650 for ; Wed, 15 May 2019 08:58:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id E85B760CDA; Wed, 15 May 2019 12:58:29 +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 14E7960E39 for ; Wed, 15 May 2019 12:58:26 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:00 +0200 Message-Id: <20190515125808.27716-4-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 03/11] rest: include everything after .../by-name/NAME/ in the redirect location 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 15 May 2019 12:58:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This will allow patchew-cli to do a request to project/by-name/QEMU/tester-= get, for example. Signed-off-by: Paolo Bonzini --- api/rest.py | 24 ++++++++++++++++++++---- api/urls.py | 2 +- tests/test_rest.py | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api/rest.py b/api/rest.py index 3b6ab2f..e64c828 100644 --- a/api/rest.py +++ b/api/rest.py @@ -16,7 +16,7 @@ from django.template import loader from mod import dispatch_module_hook from .models import Project, ProjectResult, Message, MessageResult, Result from .search import SearchEngine -from rest_framework import (permissions, serializers, viewsets, filters, +from rest_framework import (permissions, serializers, generics, viewsets, = filters, mixins, renderers, status) from rest_framework.decorators import action from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField, ListField @@ -237,16 +237,32 @@ class ProjectsViewSet(viewsets.ModelViewSet): return Response({"new_head": project.project_head, "count": ret}) =20 =20 -class ProjectsByNameViewSet(viewsets.GenericViewSet): +class ProjectsByNameView(generics.GenericAPIView): + serializer_class =3D ProjectSerializer queryset =3D Project.objects.all() - permission_classes =3D (PatchewPermission,) lookup_field =3D 'name' =20 - def retrieve(self, request, *args, **kwargs): + def _redirect(self, request, *args, **kwargs): instance =3D self.get_object() url =3D reverse_detail(instance, request) + if kwargs['tail']: + tail =3D kwargs['tail'] + if kwargs['tail'][0] =3D=3D '/' and url[-1] =3D=3D '/': + tail =3D tail[1:] + url +=3D tail + params =3D request.query_params.urlencode() + if params: + url +=3D "?" + params return HttpResponseRedirect(url, status=3Dstatus.HTTP_307_TEMPORAR= Y_REDIRECT) =20 + delete =3D _redirect + get =3D _redirect + head =3D _redirect + options =3D _redirect + patch =3D _redirect + post =3D _redirect + put =3D _redirect + =20 # Common classes for series and messages =20 diff --git a/api/urls.py b/api/urls.py index b1e259f..2383f2a 100644 --- a/api/urls.py +++ b/api/urls.py @@ -34,7 +34,6 @@ router =3D DefaultRouter(trailing_slash=3DTrue) router.include_format_suffixes =3D False router.register('users', rest.UsersViewSet) router.register('projects', rest.ProjectsViewSet) -router.register('projects/by-name', rest.ProjectsByNameViewSet) router.register('series', rest.SeriesViewSet, base_name=3D'series') router.register('messages', rest.MessagesViewSet) =20 @@ -51,6 +50,7 @@ results_router.register('results', rest.SeriesResultsView= Set, base_name=3D'results schema_view =3D get_schema_view(title=3D'API schema') =20 urlpatterns =3D _build_urls() + [ + url(r'^v1/projects/by-name/(?P[^/]*)(?P/.*|$)', rest.Proje= ctsByNameView.as_view()), url(r'^v1/users/login/$', LoginView.as_view(), name=3D'rest_login'), url(r'^v1/users/logout/$', LogoutView.as_view(), name=3D'rest_logout'), url(r"^v1/", include(router.urls)), diff --git a/tests/test_rest.py b/tests/test_rest.py index d6cbf62..36ff739 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -91,6 +91,10 @@ class RestTest(PatchewTestCase): self.assertEquals(resp.data['resource_uri'], self.PROJECT_BASE) self.assertEquals(resp.data['name'], "QEMU") self.assertEquals(resp.data['mailing_list'], "qemu-devel@nongnu.or= g") + resp =3D self.api_client.get(self.REST_BASE + 'projects/by-name/QE= MU/?some=3Dthing&foo=3Dbar') + self.assertEquals(resp.status_code, 307) + self.assertIn('some=3Dthing', resp['Location']) + self.assertIn('foo=3Dbar', resp['Location']) =20 def test_project_config_get(self): self.p.config =3D { --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925117; cv=none; d=zoho.com; s=zohoarc; b=g0UDm4Bvlp4bKLYz1D7bjrhew7e6upqhY4+Qnucm1WVFSBMrWO2lJ683bfD4HjZP2BP4f1g6BLEfkf+d/JKXrWlU1l0FAQl7Kwow0tBP+vmFsxW4VbzxzxPwpHEVSF4Vk5GEOQtWw8FWxkbXCBsxtfRPu3NP7lMo0FvpgN+p/DM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925117; 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=gu+SGAqMiiHXDgX5lkBElV4FhCj6nAeDH+Zo+K+6sas=; b=mjwgfm1dtR2zjnJi4PbdpaSMwDld4lwnJm2UIKEp+8PyWXT1qIDPHCo7U0gghs0T8bPPrS3uFu6PAaOn5w9FjkBkmLiwRKZFY5k55j1UV8OplmnlJc9UeJrZSsssT5jXFPuvWTBZ7ByippE+EMcSyiSW/4pPUnu60E1+Z64myCU= 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 1557925117480548.5629757934771; Wed, 15 May 2019 05:58:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C0083086208; Wed, 15 May 2019 12:58:36 +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 415BA1001E61; Wed, 15 May 2019 12:58:36 +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 3773C18089CB; Wed, 15 May 2019 12:58:36 +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 x4FCwYW3012663 for ; Wed, 15 May 2019 08:58:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id C142760CC0; Wed, 15 May 2019 12:58:34 +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 6C6156114C for ; Wed, 15 May 2019 12:58:30 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:01 +0200 Message-Id: <20190515125808.27716-5-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 04/11] models: move here the code to add tags and generate a new mbox 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 15 May 2019 12:58:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This code will be reused by the REST API, move it under the Message class. Signed-off-by: Paolo Bonzini --- api/models.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- www/views.py | 60 +++------------------------------------------------ 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/api/models.py b/api/models.py index 806a184..525be36 100644 --- a/api/models.py +++ b/api/models.py @@ -8,6 +8,8 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. import datetime +import email +import quopri import re =20 from django.core import validators @@ -17,7 +19,8 @@ from django.urls import reverse import jsonfield import lzma =20 -from mbox import MboxMessage +from mbox import MboxMessage, decode_payload +from patchew.tags import lines_iter from event import emit_event, declare_event from .blobs import save_blob, load_blob import mod @@ -542,6 +545,61 @@ class Message(models.Model): =20 mbox =3D property(get_mbox) =20 + def _get_mbox_with_tags(self, series_tags=3D[]): + def mbox_with_tags_iter(mbox, tags): + regex =3D "^[-A-Za-z]*:" + old_tags =3D set() + lines =3D lines_iter(mbox) + need_minusminusminus =3D False + for line in lines: + if line.startswith('---'): + need_minusminusminus =3D True + break + yield line + if re.match(regex, line): + old_tags.add(line) + + # If no --- line, tags go at the end as there's no better place + for tag in sorted(tags): + if tag not in old_tags: + yield tag + if need_minusminusminus: + yield line + yield from lines + + mbox =3D self.get_mbox() + msg =3D email.message_from_string(mbox) + container =3D msg.get_payload(0) if msg.is_multipart() else msg + if container.get_content_type() !=3D "text/plain": + return msg.as_bytes(unixfrom=3DTrue) + + payload =3D decode_payload(container) + # We might be adding 8-bit trailers to a message with 7bit CTE. F= or + # patches, quoted-printable is safe and mostly human-readable. + try: + container.replace_header('Content-Transfer-Encoding', 'quoted-= printable') + except KeyError: + msg.add_header('Content-Transfer-Encoding', 'quoted-printable') + payload =3D '\n'.join(mbox_with_tags_iter(payload, set(self.tags).= union(series_tags))) + payload =3D quopri.encodestring(payload.encode('utf-8')) + container.set_payload(payload, charset=3D'utf-8') + return msg.as_bytes(unixfrom=3DTrue) + + def get_mbox_with_tags(self): + if not self.is_patch: + if not self.is_complete: + return None + messages =3D self.get_patches() + series_tags =3D set(self.tags) + else: + messages =3D [self] + series_tags =3D set() + + mbox_list =3D [] + for message in messages: + mbox_list.append(message._get_mbox_with_tags(series_tags)) + return b"\n".join(mbox_list) + def get_num(self): assert self.is_patch or self.is_series_head cur, total =3D 1, 1 diff --git a/www/views.py b/www/views.py index f48a8ce..4436c7b 100644 --- a/www/views.py +++ b/www/views.py @@ -16,12 +16,8 @@ from django.urls import reverse from django.utils.html import format_html from django.conf import settings import api -import email -import quopri -from mbox import decode_payload import re from mod import dispatch_module_hook -from patchew.tags import lines_iter import subprocess =20 PAGE_SIZE =3D 50 @@ -264,62 +260,12 @@ def view_series_list(request, project): =20 =20 def view_mbox(request, project, message_id): - def mbox_with_tags_iter(mbox, tags): - regex =3D "^[-A-Za-z]*:" - old_tags =3D set() - lines =3D lines_iter(mbox) - need_minusminusminus =3D False - for line in lines: - if line.startswith('---'): - need_minusminusminus =3D True - break - yield line - if re.match(regex, line): - old_tags.add(line) - - # If no --- line, tags go at the end as there's no better place - for tag in sorted(tags): - if tag not in old_tags: - yield tag - if need_minusminusminus: - yield line - yield from lines - - def get_mbox_with_tags(m, series_tags): - mbox =3D m.get_mbox() - msg =3D email.message_from_string(mbox) - container =3D msg.get_payload(0) if msg.is_multipart() else msg - if container.get_content_type() !=3D "text/plain": - return msg.as_bytes(unixfrom=3DTrue) - - payload =3D decode_payload(container) - # We might be adding 8-bit trailers to a message with 7bit CTE. F= or - # patches, quoted-printable is safe and mostly human-readable. - try: - container.replace_header('Content-Transfer-Encoding', 'quoted-= printable') - except KeyError: - msg.add_header('Content-Transfer-Encoding', 'quoted-printable') - payload =3D '\n'.join(mbox_with_tags_iter(payload, set(m.tags).uni= on(series_tags))) - payload =3D quopri.encodestring(payload.encode('utf-8')) - container.set_payload(payload, charset=3D'utf-8') - return msg.as_bytes(unixfrom=3DTrue) - s =3D api.models.Message.objects.find_message(message_id, project) if not s: raise Http404("Series not found") - if not s.is_patch: - if not s.is_complete: - raise Http404("Series not complete") - messages =3D s.get_patches() - series_tags =3D set(s.tags) - else: - messages =3D [s] - series_tags =3D set() - - mbox_list =3D [] - for message in messages: - mbox_list.append(get_mbox_with_tags(message, series_tags)) - mbox =3D b"\n".join(mbox_list) + mbox =3D s.get_mbox_with_tags() + if not mbox: + raise Http404("Series not complete") return HttpResponse(mbox, content_type=3D"text/plain") =20 =20 --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925121; cv=none; d=zoho.com; s=zohoarc; b=OS0J3I/bFesjNFBW/j29ukBj5kpYKLpJ/KOLs+shRwpOt/9iCdvo0NoAI0Ax7D7RR3iH9knUeCdXwPmjaUlVe5/X7gDg0Kh9m27chiSkVh4+sKjwyaSWKMggMv3pYIkoXv/5qpo4QWooui+nAeq5m6JYLVhWYWE2rLZNjBeykWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925121; 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=sHQVjWMrmwZJGC0CSi3A5+N3Y7BukMwKqOBQ95KiYbQ=; b=EAxXQuITI6AGSnQc1luT9V+m8CKlz3hBMNR0Lzv1Bq+Zz5aiK36rvnmunm2piLuJpnYVcL1rHa3DQOupvdTjxtL/8kiJ0WeekcGVzD6SUXNQSnf/Uri1Q/hxs7Mx3w/v9GtiUBlMLZGG3YKFsBFQkB3WIhXjCoc+edVqtrlfiZk= 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 1557925121985931.472659931754; Wed, 15 May 2019 05:58:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8DEE13083394; Wed, 15 May 2019 12:58:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82DCF608AB; Wed, 15 May 2019 12:58:40 +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 784584BB43; Wed, 15 May 2019 12:58:40 +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 x4FCwc5N012673 for ; Wed, 15 May 2019 08:58:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id A5DCA60CDA; Wed, 15 May 2019 12:58:38 +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 0686460CC0 for ; Wed, 15 May 2019 12:58:35 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:02 +0200 Message-Id: <20190515125808.27716-6-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 05/11] git, rest: add mbox URI to API replies 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 15 May 2019 12:58:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Once this API is deployed, this will let us remove the filter-branch code from the applier. Instead, collecting tags reuses the existing code in www/urls.py. --- api/rest.py | 38 ++++++++++++++++++++++++-------------- mods/git.py | 7 +++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/api/rest.py b/api/rest.py index e64c828..9525a27 100644 --- a/api/rest.py +++ b/api/rest.py @@ -29,6 +29,20 @@ from rest_framework.parsers import BaseParser =20 SEARCH_PARAM =3D 'q' =20 + +class StaticTextRenderer(renderers.BaseRenderer): + media_type =3D 'text/plain' + format =3D 'mbox' + + def render(self, data, accepted_media_type=3DNone, renderer_context=3D= None): + renderer_context =3D renderer_context or {} + response =3D renderer_context.get('response') + if response and response.exception: + return '%d %s' % (response.status_code, response.status_text.t= itle()) + else: + return data + + # patchew-specific permission classes =20 =20 @@ -361,13 +375,14 @@ class SeriesSerializer(BaseMessageSerializer): class Meta: model =3D Message subclass_read_only_fields =3D ('message', 'stripped_subject', 'num= _patches', - 'total_patches', 'results') + 'total_patches', 'results', 'mbox_uri') fields =3D BaseMessageSerializer.Meta.fields + subclass_read_only_= fields + ( 'last_comment_date', 'last_reply_date', 'is_complete', 'is_mer= ged', 'is_obsolete', 'is_tested', 'is_reviewed', 'maintainers') read_only_fields =3D BaseMessageSerializer.Meta.read_only_fields += subclass_read_only_fields =20 resource_uri =3D HyperlinkedMessageField(view_name=3D'series-detail') + mbox_uri =3D HyperlinkedMessageField(view_name=3D'series-mbox') message =3D HyperlinkedMessageField(view_name=3D'messages-detail') results =3D HyperlinkedMessageField(view_name=3D'results-list', lookup= _field=3D'series_message_id') total_patches =3D SerializerMethodField() @@ -474,6 +489,14 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, def perform_destroy(self, instance): Message.objects.delete_subthread(instance) =20 + @action(detail=3DTrue, renderer_classes=3D[StaticTextRenderer]) + def mbox(self, request, *args, **kwargs): + message =3D self.get_object() + mbox =3D message.get_mbox_with_tags() + if not mbox: + raise Http404("Series not complete") + return Response(mbox) + =20 # Messages =20 @@ -506,19 +529,6 @@ class MessageCreationSerializer(BaseMessageSerializer): =20 mbox =3D CharField() =20 -class StaticTextRenderer(renderers.BaseRenderer): - media_type =3D 'text/plain' - format =3D 'mbox' - - def render(self, data, accepted_media_type=3DNone, renderer_context=3D= None): - renderer_context =3D renderer_context or {} - response =3D renderer_context.get('response') - if response and response.exception: - return '%d %s' % (response.status_code, response.status_text.t= itle()) - else: - return data - - class MessagePlainTextParser(BaseParser): media_type =3D 'message/rfc822' =20 diff --git a/mods/git.py b/mods/git.py index 6135f28..42a932e 100644 --- a/mods/git.py +++ b/mods/git.py @@ -12,6 +12,7 @@ import os import subprocess import hashlib import json +import rest_framework from django.conf.urls import url from django.http import Http404, HttpResponseRedirect from django.urls import reverse @@ -275,6 +276,12 @@ class ApplierGetView(APILoginRequiredView): response["git.repo"] =3D base.data["repo"] response["git.base"] =3D base.data["tag"] response["project.git"] =3D po.git + response["mbox_uri"] =3D rest_framework.reverse.reverse("series-mb= ox", + kwargs=3D{ + 'project= s_pk': m.project_id, + 'message= _id': m.message_id, + }, + request=3Dre= quest) response["result_uri"] =3D reverse_detail(m.git_result, request) return response =20 --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925125; cv=none; d=zoho.com; s=zohoarc; b=BhSh2RebkvUrtYkcRmNG+xOiw1Q+JRK8xQylfPQ1W6xLGoENGq5YcKDFRI5HklseAarq03Ac2YjkDO9tMOvWH9iLTlGhGFLgQoseUtnacXAuwuPt1TGO9Ulf6WVxGkO+Bm/26J/260jc6zbaomX/hojcVy01prc5lgFx/L2TJQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925125; 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=oQtmXUxrdh7udkQFVBUJ5RfWL+dp///eyT1a8txQyEA=; b=HgdcK6nKg3303W1D8pneVPHQgiFfUi9pwu5Oz+rtWffGzpj8Zzj844Bi/Ei7iLnmQ1xww1loNsBA4lTPex39dpKl1ImK3F23cG1YHEZOxv7fxcLxmKZnlDbSz/WsIgJIfNpJYn4CXZkUX7lQXzDMX2vV2C1l5/BS7IUB4s/kXdc= 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 1557925125611851.2416703645865; Wed, 15 May 2019 05:58:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DEF83003B36; Wed, 15 May 2019 12:58:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61A415D70A; Wed, 15 May 2019 12:58:44 +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 54A724BB45; Wed, 15 May 2019 12:58:44 +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 x4FCwgSd012688 for ; Wed, 15 May 2019 08:58:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF13060F81; Wed, 15 May 2019 12:58:42 +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 7E09760CDA for ; Wed, 15 May 2019 12:58:39 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:03 +0200 Message-Id: <20190515125808.27716-7-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 06/11] git: reimplement applier-get under /api/v1/series 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 15 May 2019 12:58:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- api/urls.py | 5 ++++- mods/git.py | 50 +++++++++++++++++++++++++++++++++++++++-------- tests/test_git.py | 15 ++++++++++++++ 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/api/urls.py b/api/urls.py index 2383f2a..c44e3ce 100644 --- a/api/urls.py +++ b/api/urls.py @@ -17,6 +17,7 @@ from rest_framework.schemas import get_schema_view =20 from . import views from . import rest +from mod import dispatch_module_hook =20 =20 def _build_urls(base=3DNone, r=3D[]): @@ -49,7 +50,9 @@ results_router.register('results', rest.SeriesResultsView= Set, base_name=3D'results =20 schema_view =3D get_schema_view(title=3D'API schema') =20 -urlpatterns =3D _build_urls() + [ +urlpatterns =3D _build_urls() +dispatch_module_hook("api_url_hook", urlpatterns=3Durlpatterns) +urlpatterns +=3D [ url(r'^v1/projects/by-name/(?P[^/]*)(?P/.*|$)', rest.Proje= ctsByNameView.as_view()), url(r'^v1/users/login/$', LoginView.as_view(), name=3D'rest_login'), url(r'^v1/users/logout/$', LogoutView.as_view(), name=3D'rest_logout'), diff --git a/mods/git.py b/mods/git.py index 42a932e..78939b8 100644 --- a/mods/git.py +++ b/mods/git.py @@ -22,12 +22,12 @@ from django.db.models import Q from mod import PatchewModule from event import declare_event, register_handler, emit_event from api.models import (Message, Project, Result) -from api.rest import PluginMethodField, reverse_detail +from api.rest import PluginMethodField, SeriesSerializer, reverse_detail from api.views import APILoginRequiredView, prepare_series from patchew.logviewer import LogView from schema import * -from rest_framework import serializers -from rest_framework.fields import CharField +from rest_framework import generics, mixins, serializers +from rest_framework.fields import CharField, SerializerMethodField =20 _instance =3D None =20 @@ -239,11 +239,12 @@ class GitModule(PatchewModule): GitLogViewer.as_view(), name=3D"git-log")) =20 -class ApplierGetView(APILoginRequiredView): - name =3D "applier-get" - allowed_groups =3D ["importers"] + def api_url_hook(self, urlpatterns): + urlpatterns.append(url(r"^v1/series/unapplied/$", + UnappliedSeriesView.as_view(), + name=3D"unapplied")) =20 - def handle(self, request, target_repo=3DNone): + def pending_series(self, target_repo): q =3D Message.objects.filter(results__name=3D"git", results__statu= s=3D"pending") if target_repo is not None and target_repo !=3D '': # Postgres could use JSON fields instead. Fortunately project= s are @@ -260,7 +261,14 @@ class ApplierGetView(APILoginRequiredView): projects =3D Project.objects.values_list('id', 'config').all() projects =3D [pid for pid, config in projects if match_target_= repo(config, target_repo)] q =3D q.filter(project__pk__in=3Dprojects) - m =3D q.first() + return q + +class ApplierGetView(APILoginRequiredView): + name =3D "applier-get" + allowed_groups =3D ["importers"] + + def handle(self, request, target_repo=3DNone): + m =3D _instance.pending_series(target_repo).first() if not m: return None =20 @@ -285,6 +293,32 @@ class ApplierGetView(APILoginRequiredView): response["result_uri"] =3D reverse_detail(m.git_result, request) return response =20 + +class UnappliedSeriesSerializer(SeriesSerializer): + class Meta: + model =3D Message + fields =3D SeriesSerializer.Meta.fields + ('mirror', 'result_uri') + + mirror =3D SerializerMethodField() + result_uri =3D SerializerMethodField() + + def get_result_uri(self, obj): + request =3D self.context['request'] + return reverse_detail(obj.git_result, request) + + def get_mirror(self, obj): + request =3D self.context['request'] + mirror =3D _instance.get_mirror(obj.project, request, None) + mirror['source'] =3D obj.project.git + return mirror + +class UnappliedSeriesView(generics.ListAPIView): + name =3D "unapplied" + serializer_class =3D UnappliedSeriesSerializer + + def get_queryset(self, target_repo=3DNone): + return _instance.pending_series(target_repo) + class ApplierReportView(APILoginRequiredView): name =3D "applier-report" allowed_groups =3D ["importers"] diff --git a/tests/test_git.py b/tests/test_git.py index 0b9fa50..e99755f 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -144,6 +144,21 @@ class GitTest(PatchewTestCase): self.assertEqual(log.status_code, 200) self.assertEqual(log.content.decode(), resp.data['log']) =20 + def test_rest_unapplied(self): + self.cli_import('0004-multiple-patch-reviewed.mbox.gz') + self.cli_import('0001-simple-patch.mbox.gz') + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) + self.api_client.put(self.PROJECT_BASE + 'series/20160628014747.209= 71-1-famz@redhat.com/results/git/', + { 'status': 'success' }) + resp =3D self.api_client.get(self.REST_BASE + 'series/unapplied/') + self.assertEqual(resp.status_code, 200) + self.assertEquals(len(resp.data['results']), 1) + self.assertEquals(resp.data['results'][0]['message_id'], '14691920= 15-16487-1-git-send-email-berrange@redhat.com') + self.do_apply() + resp =3D self.api_client.get(self.REST_BASE + 'series/unapplied/') + self.assertEqual(resp.status_code, 200) + self.assertEquals(len(resp.data['results']), 0) + =20 if __name__ =3D=3D '__main__': main() --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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 From nobody Thu Apr 25 13:40:39 2024 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=1557925142; cv=none; d=zoho.com; s=zohoarc; b=U3mz4L4wDPOXWrQmPFatjMgwQfKoadfbLX5ftMZN0yxLhYJpfE05jB57DvDEa0p1+koW9Dl/OCMTS5EX6bQf1cKYLw8Dr5ZTN95QNK9KmcvYAq6POnWcysO2BM4w/rPQfvvEec82DwikLwjC6cWJxh+xqmvFOdPE03sM7V1myD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925142; 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=zZ9ehONCYw8luLIyHYoYtbuSY4Zi75rlIpDzfkDFJv4=; b=MOqgjAFKaVlxTWUz5hJR+bD2B/IW+KpFthDJLEHxgiIjF5IZorY/cqrOPCW5r5dG+7N/ZKfZ7gBey6vUZi+iIedruiIlHOBFhurB3+QKI6CkkxD+SqFkjCqSC1KcoBOYhzKeS3OTpzngrvImDzBU910CZscnI0vi5Lv1lLOxs1M= 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 1557925142886450.8211410170361; Wed, 15 May 2019 05:59:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEB0F3060310; Wed, 15 May 2019 12:59:01 +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 A4AAD5D9DC; Wed, 15 May 2019 12:59:01 +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 9A64118089CB; Wed, 15 May 2019 12:59:01 +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 x4FCx0ho012711 for ; Wed, 15 May 2019 08:59:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4922060CC0; Wed, 15 May 2019 12:59:00 +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 44B4F60F81 for ; Wed, 15 May 2019 12:58:46 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:05 +0200 Message-Id: <20190515125808.27716-9-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 08/11] testing: remove the untest command 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 15 May 2019 12:59:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- mods/testing.py | 10 ---------- patchew-cli | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/mods/testing.py b/mods/testing.py index 90bb2be..1b914ce 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -571,13 +571,3 @@ class TestingCapabilitiesView(APILoginRequiredView): raise Http404("Project '%s' not found" % project) probes =3D _instance.get_capability_probes(po) return probes - -class UntestView(APILoginRequiredView): - name =3D "untest" - allowed_groups =3D ["testers"] - - def handle(self, request, terms): - se =3D SearchEngine() - q =3D se.search_series(user=3Drequest.user, *terms) - for s in q: - _instance.clear_and_start_testing(s) diff --git a/patchew-cli b/patchew-cli index bfff69c..9ea7834 100755 --- a/patchew-cli +++ b/patchew-cli @@ -378,16 +378,6 @@ class SearchCommand(SubCommand): print(x[a]) return 0 =20 -class UntestCommand(SubCommand): - name =3D "untest" - - def arguments(self, parser): - parser.add_argument("term", nargs=3D"*", type=3Dstr) - - def do(self, args, argv): - self.api_do("untest", terms=3Dargs.term) - return 0 - class TesterCommand(SubCommand): name =3D "tester" want_argv =3D True --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925163; cv=none; d=zoho.com; s=zohoarc; b=eXBnU47EPZCCogVJG6S4p3or2pz7FgDY709VuyhAgqONMYrBr+2qxQ07XM/t08N+IKT40GMZiFZ1Ymop4iVKuRM6I7PwSylq3x8mNCbO4tcOhnPP/1GhMnfpwgC3JiEIozgoYXWdsW86q89BiJ3Uwl/J/DgrybyRTIV0K2+GlKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925163; 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=tpM11fljNDol64KH3FRGR2JgopQe5JWI95YKzX2WuRw=; b=C4VCX1VNEWtZkMmdjmbx+zDXtJgDRKdFWQOmNUZ/D+p1oXq0OGExXy+WuqauiNqYE64OFMvSOebxfHpNzacP2RtrwFtzjRDZ6F3PB28JqpeQdshgUSa9GTRXJ9cxtLjd9VAMg5qnsWlWxHc9R/sSvqu1yu76WRtR+i18mxiEGlg= 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 1557925163709330.71689713992896; Wed, 15 May 2019 05:59:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85F072CD7E9; Wed, 15 May 2019 12:59:22 +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 7AC785D72E; Wed, 15 May 2019 12:59:22 +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 72FFB18089D1; Wed, 15 May 2019 12:59:22 +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 x4FCxLWx012723 for ; Wed, 15 May 2019 08:59:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 442C660CDA; Wed, 15 May 2019 12:59:21 +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 E86B77D4F0 for ; Wed, 15 May 2019 12:59:02 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:06 +0200 Message-Id: <20190515125808.27716-10-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 09/11] testing: convert test_testing to use REST API 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 15 May 2019 12:59:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- tests/patchewtest.py | 20 +++++++++----- tests/test_testing.py | 62 +++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/tests/patchewtest.py b/tests/patchewtest.py index e58e5b9..d511954 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -138,13 +138,19 @@ class PatchewTestCase(dj_test.LiveServerTestCase): p.save() return p =20 - def api_login(self): - r =3D self.client.login(username=3Dself.user, password=3Dself.pass= word) - self.assertTrue(r) - - def api_call(self, method, **params): - resp =3D self.client.post('/api/%s/' % method, {"params": json.dum= ps(params)}) - return json.loads(resp.content.decode('utf-8')) if resp.content el= se None + def api_login(self, username=3DNone, password=3DNone): + username =3D username or self.user + password =3D password or self.password + user =3D User.objects.get(username=3Dusername) + resp =3D self.api_client.post(self.REST_BASE + 'users/login/', + { 'username': username, 'password': password }) + self.assertEquals(resp.status_code, 200) + self.api_client.force_authenticate(user, resp.data['key']) + + def api_logout(self): + resp =3D self.api_client.post(self.REST_BASE + 'users/logout/') + self.assertEquals(resp.status_code, 200) + self.api_client.force_authenticate(None, None) =20 def apply_and_retrieve(self, mbox, project_id, msgid): # TODO: change this to a REST import when it is added diff --git a/tests/test_testing.py b/tests/test_testing.py index 3fa912e..df155c7 100755 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -70,29 +70,27 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dabc.= ABCMeta): kwargs['status'] =3D Result.SUCCESS self.modify_test_result(obj, **kwargs) =20 - def do_testing_report(self, **report): + def do_testing_report(self, passed=3DTrue, log=3DNone, is_timeout=3DFa= lse): self.api_login() - r =3D self.api_call( - "testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[], - ) - report['project'] =3D r["project"] - report['identity'] =3D r["identity"] - report['test'] =3D r["test"]["name"] - report['tester'] =3D 'dummy_tester' - report['head'] =3D r["head"] - report['base'] =3D r["base"] - if 'passed' not in report: - report['passed'] =3D True - if 'log' not in report: - report['log'] =3D None - if 'is_timeout' not in report: - report['is_timeout'] =3D False - - self.api_call("testing-report", **report) - return r['identity'] + resp =3D self.api_client.post(self.PROJECT_BASE + "get-test/", { + 'tester': "dummy tester", + 'capabilities': [], + }) + self.assertEqual(resp.status_code, 200) + r =3D resp.data + data =3D { + "status": "success" if passed else 'failure', + 'data': { + "head": r["head"], + "is_timeout": is_timeout, + "tester": "dummy_tester" + } + } + if log is not None: + data['log'] =3D log + + self.api_client.put(r['result_uri'], data, format=3D'json') + return r["identity"] =20 @abc.abstractmethod def do_testing_done(self, log=3DNone, **report): @@ -104,10 +102,12 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dab= c.ABCMeta): =20 def test_basic(self): self.api_login() - td =3D self.api_call("testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[]) + resp =3D self.api_client.post(self.PROJECT_BASE + "get-test/", { + 'tester': "dummy tester", + 'capabilities': [], + }) + self.assertEqual(resp.status_code, 200) + td =3D resp.data self.assertIn("head", td) resp =3D self.get_test_result('a') self.assertEquals(resp.data['status'], 'running') @@ -115,11 +115,11 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dab= c.ABCMeta): def test_done(self): self.do_testing_done() self.api_login() - td =3D self.api_call("testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[]) - self.assertFalse(td) + resp =3D self.api_client.post(self.PROJECT_BASE + "get-test/", { + 'tester': "dummy tester", + 'capabilities': [], + }) + self.assertEqual(resp.status_code, 204) =20 def test_rest_basic(self): resp =3D self.get_test_result('a') --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925169; cv=none; d=zoho.com; s=zohoarc; b=a3Bg8fxlDHMgyDZyhpc9wY3f2YcpKs3PZUqrZQwPx+cCf4tMs9bAauOUYfkShqhcPDIJ/Genb+Dhx/Mn4VqKhXSy3aEz+24NniK8MlYZdHKZrG09B9S6ojYvZ6Olb3s0HQSadGvLeO+KsIAuZ/Rcf0UB9fjzdAv41eBAetPPlxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925169; 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=YDaCzXPjAkYUpsfn3XYK/Q2GeHx8qpxSodoTOp+87kY=; b=kehsZHnaOcYlbU8HSTi+kHvL4pRtZhQBUgbWDDxyjMFmrMZylaO6PJwFGli4dFbEKr8HdH58uCDP8gW4fasacvXttKlMVYkTdtjYJmUWegwvEohFAd1iVndkIRoUIbknCXV7Kwaa989+GCYLdTuJFEZKP/iHcN08LXM++LE3hpM= 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 1557925169005380.13119094474416; Wed, 15 May 2019 05:59:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CEA623DBDB; Wed, 15 May 2019 12:59:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C307E6590A; Wed, 15 May 2019 12:59:27 +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 B831A4BB43; Wed, 15 May 2019 12:59:27 +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 x4FCxQpS012734 for ; Wed, 15 May 2019 08:59:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CE4360CDA; Wed, 15 May 2019 12:59:26 +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 7FAFB60FA7 for ; Wed, 15 May 2019 12:59:21 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:07 +0200 Message-Id: <20190515125808.27716-11-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 10/11] git: automatically derive the URL for result PUT 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 15 May 2019 12:59:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Similar to commit 4efd0d21145a973f3321e9ec93700fb061b289f5 (git: allow not passing the URL to applier-report) but for the REST API. --- api/rest.py | 25 ++++++++++++++++++++++--- mods/git.py | 12 +++++++++++- mods/testing.py | 3 ++- tests/test_git.py | 13 +++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/api/rest.py b/api/rest.py index c3ec3e1..e893e74 100644 --- a/api/rest.py +++ b/api/rest.py @@ -609,6 +609,16 @@ class HyperlinkedResultField(HyperlinkedIdentityField): return self.reverse(view_name, kwargs=3Dkwargs, request=3Drequest,= format=3Dformat) =20 =20 +class ResultDataSerializer(serializers.Serializer): + def __init__(self, *args, **kwargs): + # Don't pass the 'project' arg up to the superclass + self.project =3D kwargs.pop('project', None) + super(ResultDataSerializer, self).__init__(*args, **kwargs) + + def create(self, data): + return data + + class ResultSerializer(serializers.ModelSerializer): class Meta: model =3D Result @@ -623,11 +633,19 @@ class ResultSerializer(serializers.ModelSerializer): request =3D self.context['request'] return obj.get_log_url(request) =20 + def get_data_serializer(self, *args, **kwargs): + project =3D self.context['parent'].project + data_serializer_class =3D self.context['renderer'].result_data_ser= ializer_class + return data_serializer_class(*args, **kwargs, project=3Dproject, c= ontext=3Dself.context) + + def update(self, instance, validated_data): + if 'data' in validated_data: + validated_data['data'] =3D self.get_data_serializer().create(v= alidated_data['data']) + return super(ResultSerializer, self).update(instance, validated_da= ta) + def validate(self, data): if 'data' in data: - data_serializer_class =3D self.context['renderer'].result_data= _serializer_class - data_serializer_class(data=3Ddata['data'], - context=3Dself.context).is_valid(raise_e= xception=3DTrue) + self.get_data_serializer(data=3Ddata['data']).is_valid(raise_e= xception=3DTrue) return data =20 =20 @@ -671,6 +689,7 @@ class ResultsViewSet(mixins.ListModelMixin, mixins.Retr= ieveModelMixin, context =3D super(ResultsViewSet, self).get_serializer_context() if 'name' in self.kwargs: context['renderer'] =3D self.result_renderer + context['parent'] =3D self return context =20 def get_serializer_class(self, *args, **kwargs): diff --git a/mods/git.py b/mods/git.py index 78939b8..b544b58 100644 --- a/mods/git.py +++ b/mods/git.py @@ -22,6 +22,7 @@ from django.db.models import Q from mod import PatchewModule from event import declare_event, register_handler, emit_event from api.models import (Message, Project, Result) +import api.rest from api.rest import PluginMethodField, SeriesSerializer, reverse_detail from api.views import APILoginRequiredView, prepare_series from patchew.logviewer import LogView @@ -47,7 +48,7 @@ class GitLogViewer(LogView): raise Http404("Object not found: " + series) return obj.git_result =20 -class ResultDataSerializer(serializers.Serializer): +class ResultDataSerializer(api.rest.ResultDataSerializer): # TODO: should be present iff the result is success or failure base =3D CharField(required=3DFalse) =20 @@ -56,6 +57,15 @@ class ResultDataSerializer(serializers.Serializer): url =3D CharField(required=3DFalse) tag =3D CharField(required=3DFalse) =20 + def create(self, data): + if 'tag' in data and 'url' not in data and self.project: + config =3D _instance.get_project_config(self.project) + url_template =3D config.get("url_template") + tag =3D data['tag'] + if url_template and tag.startswith('refs/tags/'): + data['url'] =3D url_template.replace("%t", tag[10:]) + return super(ResultDataSerializer, self).create(data) + class GitModule(PatchewModule): """Git module""" =20 diff --git a/mods/testing.py b/mods/testing.py index 1b914ce..16e652a 100644 --- a/mods/testing.py +++ b/mods/testing.py @@ -20,6 +20,7 @@ import time import math from api.views import APILoginRequiredView from api.models import (Message, MessageResult, Project, ProjectResult, Re= sult) +import api.rest from api.rest import PluginMethodField, TestPermission, reverse_detail from api.search import SearchEngine from event import emit_event, declare_event, register_handler @@ -50,7 +51,7 @@ class TestingLogViewer(LogView): raise Http404("Object not found: " + project_or_series) return _instance.get_testing_result(obj, testing_name) =20 -class ResultDataSerializer(serializers.Serializer): +class ResultDataSerializer(api.rest.ResultDataSerializer): # TODO: is_timeout should be present iff the result is a failure is_timeout =3D BooleanField(required=3DFalse) head =3D CharField() diff --git a/tests/test_git.py b/tests/test_git.py index e99755f..9b8de6d 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -144,6 +144,19 @@ class GitTest(PatchewTestCase): self.assertEqual(log.status_code, 200) self.assertEqual(log.content.decode(), resp.data['log']) =20 + def test_result_data_automatic_url(self): + self.cli_import('0001-simple-patch.mbox.gz') + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) + resp =3D self.api_client.put(self.PROJECT_BASE + 'series/201606280= 14747.20971-1-famz@redhat.com/results/git/', { + 'status': 'success', + 'data': { + 'repo': self.repo, + 'tag': 'refs/tags/patchew/20160628014747.20971-1-famz@= redhat.com' + } + }, format=3D'json') + resp =3D self.api_client.get(self.PROJECT_BASE + 'series/201606280= 14747.20971-1-famz@redhat.com/results/git/') + self.assertIn('url', resp.data['data']) + def test_rest_unapplied(self): self.cli_import('0004-multiple-patch-reviewed.mbox.gz') self.cli_import('0001-simple-patch.mbox.gz') --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 25 13:40:39 2024 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=1557925175; cv=none; d=zoho.com; s=zohoarc; b=ByHtxlkZJGrU6FHoLaU6p46mqMwLkT+OTZMtX6eVmIDqx6gSLBQ+nrTMhAPGWfayuqoCCjlX2YelveNGU3ROHMCvyDivohIR5v7Q1AZoGk1x1rfVbSbQZHVQTA9NFgevyZuNtFcrOEVgh8K/1plkZVNHgyhtD5Im/UkeYVqXctk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925175; 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=MHwKgjp3NXzo9vKJTvTuR8TsfbL7aUOr3JBYjqog5Ss=; b=kuNXFUW4MsDz2RfrfzZGftNowGINL8sOkM5x7MR19d0ZbZRNCNN2/rNG5G+5ElaHXO6l1j2j7kjK1215D6hLHaY3huI8w08hzpbGZ60IyHmNyIxh8PKA6/2+IzDBD8knaRse99StpSz+aE7OgtP5jrdDu4lSCfk3vFjuQT896SQ= 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 1557925175113318.52960365150443; Wed, 15 May 2019 05:59:35 -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 EFB3481E1C; Wed, 15 May 2019 12:59:33 +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 E00AC71CAE; Wed, 15 May 2019 12:59:33 +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 D431E18089CB; Wed, 15 May 2019 12:59:33 +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 x4FCxXqV012746 for ; Wed, 15 May 2019 08:59:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9348E60CDA; Wed, 15 May 2019 12:59:33 +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 425DF60E39 for ; Wed, 15 May 2019 12:59:27 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:08 +0200 Message-Id: <20190515125808.27716-12-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 11/11] tests: clean up duplicated defaulting in cli_login 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.25]); Wed, 15 May 2019 12:59:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- tests/patchewtest.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/patchewtest.py b/tests/patchewtest.py index d511954..2b1c3cd 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -93,11 +93,9 @@ class PatchewTestCase(dj_test.LiveServerTestCase): return a, b =20 def cli_login(self, username=3DNone, password=3DNone): - if not username: - username =3D self.user - if not password: - password =3D self.password - self.check_cli(["login", username or self.user, password or self.p= assword]) + username =3D username or self.user + password =3D password or self.password + self.check_cli(["login", username, password]) =20 def cli_logout(self): self.check_cli(["logout"]) --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel