[Patchew-devel] [PATCH v2 2/2] rest: Imporoved series DELETE in the REST API

Fam Zheng famz at redhat.com
Fri Mar 30 16:21:19 UTC 2018


On Fri, 03/30 21:15, Shubham Jain wrote:
> - Fixed the char limit in line to make code more readable
> - overrode perform_destroy function so that that endpoint accepts any message id and not just the series head
> - wrote tests for the same

Hi Shubham,

This patch is improving things only existent in patch 1 but not in master, so
both patches can be squashed into one commit.

Fam

> ---
>  api/rest.py        |  9 +++++++--
>  tests/test_rest.py | 22 ++++++++++++++--------
>  2 files changed, 21 insertions(+), 10 deletions(-)
> 
> diff --git a/api/rest.py b/api/rest.py
> index e966559..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, mixins, renderers
> +from rest_framework import permissions, serializers, viewsets, filters, mixins, 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 = (SEARCH_PARAM,)
>  
>  class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
> -                           SeriesViewSet,mixins.DestroyModelMixin):
> +                           SeriesViewSet, mixins.DestroyModelMixin):
>      def collect_patches(self, series):
>          if series.is_patch:
>              patches = [series]
> @@ -265,6 +265,11 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
>                  self.collect_replies(i, series.replies)
>          return series
>  
> +    def destroy(self, request, *args, **kwargs):
> +        instance = self.get_object()
> +        Message.objects.delete_subthread(instance)
> +        return Response(status=status.HTTP_204_NO_CONTENT)
> +
>  # Messages
>  
>  # TODO: add POST endpoint connected to email plugin?
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 458f54e..d64e047 100755
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -219,17 +219,23 @@ class RestTest(PatchewTestCase):
>          self.assertEqual(resp.data['count'], 0)
>  
>      def test_series_delete(self):
> -        resp1 = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
> -                                       self.p.id, '20160628014747.20971-1-famz at redhat.com')
> -        
> -        resp_before = self.api_client.get(self.REST_BASE + 'projects/' + str(self.p.id) + '/series/20160628014747.20971-1-famz at redhat.com/')
> +        test_message_id = '1469192015-16487-1-git-send-email-berrange at redhat.com'
> +        series = self.apply_and_retrieve('0004-multiple-patch-reviewed.mbox.gz',self.p.id,
> +                                         test_message_id)
> +        message = series.data['message']
> +        resp_before = self.api_client.get(self.REST_BASE + 'projects/' + str(self.p.id) 
> +                                          + '/series/' + test_message_id + '/')
> +        resp_reply_before = self.api_client.get(message + 'replies/')
> +        resp = self.api_client.delete(self.REST_BASE + 'projects/' + str(self.p.id) 
> +                                      + '/series/' + test_message_id + '/')
> +        resp_after = self.api_client.get(self.REST_BASE + 'projects/' + str(self.p.id) 
> +                                         + '/series/' + test_message_id + '/')
> +        resp_reply_after = self.api_client.get(message + 'replies/')
>          self.assertEqual(resp_before.status_code, 200)
> -
> -        resp = self.api_client.delete(self.REST_BASE + 'projects/' + str(self.p.id) + '/series/20160628014747.20971-1-famz at redhat.com/')
> +        self.assertEqual(resp_reply_before.status_code, 200)
>          self.assertEqual(resp.status_code, 204)
> -
> -        resp_after = self.api_client.get(self.REST_BASE + 'projects/' + str(self.p.id) + '/series/20160628014747.20971-1-famz at redhat.com/')
>          self.assertEqual(resp_after.status_code, 404)
> +        self.assertEqual(resp_reply_after.status_code, 404)
>  
>      def test_message(self):
>          series = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
> -- 
> 2.14.3 (Apple Git-98)
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel




More information about the Patchew-devel mailing list