[Patchew-devel] [PATCH v3] rest: add support for series DELETE in the REST API, and a corresponding unit test

Paolo Bonzini pbonzini at redhat.com
Wed Apr 4 14:39:58 UTC 2018


On 04/04/2018 15:13, Shubham Jain wrote:
> 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 message id and not just the series head
> - wrote tests for the same
> Message-Id: <20180331122557.44970-1-shubhamjain7495 at gmail.com>
> 
> rest: Added permission class
> 
> - Added permission to deletion and restricted it to avoid public deletion.
> - Added a corresponding unit test to it.
> - Also overrode perform_destroy instead of destory to perform series deletion.
> ---
>  api/rest.py        |  7 ++++++-
>  tests/test_rest.py | 25 +++++++++++++++++++++++++
>  2 files changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/api/rest.py b/api/rest.py
> index 7c131a4..6aa744d 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -229,9 +229,11 @@ class SeriesViewSet(BaseMessageViewSet):
>      queryset = Message.objects.filter(is_series_head=True).order_by('-last_reply_date')
>      filter_backends = (PatchewSearchFilter,)
>      search_fields = (SEARCH_PARAM,)
> +    permission_classes = (IsAdminUserOrReadOnly,)

Thanks!

I changed this to IsMaintainerOrReadOnly and pushed the resulting patch.

As a next step, perhaps you can implement POST for /api/v1/messages?
That should accept a text/plain object; can you find the corresponding
legacy API endpoint?

Thanks,

Paolo

> +
>  
>  class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
> -                           SeriesViewSet):
> +                           SeriesViewSet, mixins.DestroyModelMixin):
>      def collect_patches(self, series):
>          if series.is_patch:
>              patches = [series]
> @@ -265,6 +267,9 @@ class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
>                  self.collect_replies(i, series.replies)
>          return series
>  
> +    def perform_destroy(self, instance):
> +        Message.objects.delete_subthread(instance)
> +
>  # Messages
>  
>  # TODO: add POST endpoint connected to email plugin?
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 28ca10b..5b22067 100755
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -218,6 +218,31 @@ class RestTest(PatchewTestCase):
>          resp = self.api_client.get(self.REST_BASE + 'projects/12345/series/?q=project:QEMU')
>          self.assertEqual(resp.data['count'], 0)
>  
> +    def test_series_delete(self):
> +        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_without_login = self.api_client.delete(self.REST_BASE + 'projects/' + str(self.p.id) 
> +                                      + '/series/' + test_message_id + '/')
> +        self.api_client.login(username=self.user, password=self.password)        
> +        resp = self.api_client.delete(self.REST_BASE + 'projects/' + str(self.p.id) 
> +                                      + '/series/' + test_message_id + '/')
> +        self.api_client.logout()
> +        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)
> +        self.assertEqual(resp_reply_before.status_code, 200)
> +        self.assertEqual(resp_without_login.status_code, 403)
> +        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 = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
>                                           self.p.id, '20160628014747.20971-1-famz at redhat.com')
> 




More information about the Patchew-devel mailing list