From nobody Thu Apr 18 22:57:51 2024 Delivered-To: importer@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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522499181933223.84117787884463; Sat, 31 Mar 2018 05:26:21 -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 08CDB4E900; Sat, 31 Mar 2018 12:26:21 +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 EC8CA5C3FA; Sat, 31 Mar 2018 12:26:20 +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 E116D1808873; Sat, 31 Mar 2018 12:26:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2VCQKG0003524 for ; Sat, 31 Mar 2018 08:26:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F60A5D6A6; Sat, 31 Mar 2018 12:26:20 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78F945D6A3 for ; Sat, 31 Mar 2018 12:26:18 +0000 (UTC) Received: from mail-pg0-f54.google.com (mail-pg0-f54.google.com [74.125.83.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 075943DFCC for ; Sat, 31 Mar 2018 12:26:17 +0000 (UTC) Received: by mail-pg0-f54.google.com with SMTP id n11so6589849pgp.4 for ; Sat, 31 Mar 2018 05:26:16 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.186]) by smtp.gmail.com with ESMTPSA id o2sm19442662pgq.87.2018.03.31.05.26.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Mar 2018 05:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Jv4Xm8NyFOU2y8jYsqS6J9MpOX+sVUbVJz0/YeQzPBU=; b=GV5UxbGaBieg6YTt7icC6JiGiP7dz8/mSo8lDD10yxzKz8CiG0lthl6LTSUc3CEAom BmYsPp2cxGvFmOBYsniXS+EmSTf4ROolHhj/2nX+nqwysYvHv3iKm4Mxj8gRy9DftXCl e0/QH0+ErmbhWTsAUlhtXxAKvzPpHg6+jzwfOHUUWsvmU9Z5pHL1HWq9+Q8bq9X3BRCL qxLi7rviM/dMxccYTJe95xzxSxO6GUAfi1coT2HjlNnxCm9PulOzlgWryJSrZkmoQB9H SEtN3akz4Z7ApOq0ZUSKj7ALFIJFbTPr3ecKoRb2ClflN0Ceb/1MwmUzXfZulZX7jeiq fynw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Jv4Xm8NyFOU2y8jYsqS6J9MpOX+sVUbVJz0/YeQzPBU=; b=UZDVDn79WnWZkBl0wXGLNxXsaHsydcxD73M9dHxkctbnT6G55xy2q9ixrYlccrLSOi VxWNVa/mFG9IdfyjMPEuCY7qw3k6kNAqJQ2Lms8q6/Tq/j+jcklMdu6/QVtpReDoLZlP K/Ni9uUJXNimr6wmu3Qj6tVPYH00jjNVhBFd2+GNZtXfiLEfujXl4IL8To+c87h9ABwN N+4pEcfE3rpCZqAqhM6jwrnCV8boUblWZYIjqdCyQ+fMyHx/rNDX4Yajdu/xl6I/d6/l R3PEOSMKMVehSPH1sq0HzNQIAkhUSCFuXdKwalAkZsphOA/18ecSVI6rZzBLaDV4q51h f1Tw== X-Gm-Message-State: AElRT7GxUHqO8VPR0SsB0ZKCwPkBr2cRu1nt9i7eorw4gdgCnrWkcQq6 cBTA3hpobwfpbxXM35YEnTfKQQ== X-Google-Smtp-Source: AIpwx4/SuekumFFqXg7yd801UtkujgmhJSI56j59UjqmNML4pif7gfLHJJl9SujqXtkfAmIY+Jdaqg== X-Received: by 2002:a17:902:8482:: with SMTP id c2-v6mr2895450plo.295.1522499175995; Sat, 31 Mar 2018 05:26:15 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Sat, 31 Mar 2018 17:55:57 +0530 Message-Id: <20180331122557.44970-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 31 Mar 2018 12:26:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 31 Mar 2018 12:26:17 +0000 (UTC) for IP:'74.125.83.54' DOMAIN:'mail-pg0-f54.google.com' HELO:'mail-pg0-f54.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.62 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 74.125.83.54 mail-pg0-f54.google.com 74.125.83.54 mail-pg0-f54.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v2] rest: add support for series DELETE in the REST API, and a corresponding unit test 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: , MIME-Version: 1.0 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.38]); Sat, 31 Mar 2018 12:26:21 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" rest: Imporoved series DELETE in the REST API - Fixed the char limit in line to make code more readable - overrode perform_destroy function so that that endpoint accepts any messa= ge id and not just the series head - wrote tests for the same --- api/rest.py | 9 +++++++-- tests/test_rest.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/rest.py b/api/rest.py index 7c131a4..16810bb 100644 --- a/api/rest.py +++ b/api/rest.py @@ -14,7 +14,7 @@ from django.template import loader from mod import dispatch_module_hook from .models import Project, Message from .search import SearchEngine -from rest_framework import permissions, serializers, viewsets, filters, mi= xins, renderers +from rest_framework import permissions, serializers, viewsets, filters, mi= xins, renderers, status from rest_framework.decorators import detail_route from rest_framework.fields import SerializerMethodField from rest_framework.relations import HyperlinkedIdentityField @@ -231,7 +231,7 @@ class SeriesViewSet(BaseMessageViewSet): search_fields =3D (SEARCH_PARAM,) =20 class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, - SeriesViewSet): + SeriesViewSet, mixins.DestroyModelMixin): def collect_patches(self, series): if series.is_patch: patches =3D [series] @@ -265,6 +265,11 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixin, self.collect_replies(i, series.replies) return series =20 + def destroy(self, request, *args, **kwargs): + instance =3D self.get_object() + Message.objects.delete_subthread(instance) + return Response(status=3Dstatus.HTTP_204_NO_CONTENT) + # Messages =20 # TODO: add POST endpoint connected to email plugin? diff --git a/tests/test_rest.py b/tests/test_rest.py index 28ca10b..d64e047 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -218,6 +218,25 @@ class RestTest(PatchewTestCase): resp =3D self.api_client.get(self.REST_BASE + 'projects/12345/seri= es/?q=3Dproject:QEMU') self.assertEqual(resp.data['count'], 0) =20 + def test_series_delete(self): + test_message_id =3D '1469192015-16487-1-git-send-email-berrange@re= dhat.com' + series =3D self.apply_and_retrieve('0004-multiple-patch-reviewed.m= box.gz',self.p.id, + test_message_id) + message =3D series.data['message'] + resp_before =3D self.api_client.get(self.REST_BASE + 'projects/' += str(self.p.id)=20 + + '/series/' + test_message_id += '/') + resp_reply_before =3D self.api_client.get(message + 'replies/') + resp =3D self.api_client.delete(self.REST_BASE + 'projects/' + str= (self.p.id)=20 + + '/series/' + test_message_id + '/') + resp_after =3D self.api_client.get(self.REST_BASE + 'projects/' + = str(self.p.id)=20 + + '/series/' + test_message_id + = '/') + resp_reply_after =3D self.api_client.get(message + 'replies/') + self.assertEqual(resp_before.status_code, 200) + self.assertEqual(resp_reply_before.status_code, 200) + self.assertEqual(resp.status_code, 204) + self.assertEqual(resp_after.status_code, 404) + self.assertEqual(resp_reply_after.status_code, 404) + def test_message(self): series =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-= 1-famz@redhat.com') --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel