[Patchew-devel] [PATCH v2] rest: add support for series DELETE in the REST API, and a corresponding unit test
Paolo Bonzini
pbonzini at redhat.com
Wed Apr 4 09:12:12 UTC 2018
On 31/03/2018 14:25, Shubham Jain wrote:
> @@ -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)
There are still some issues:
- if you override perform_destroy, rather than destroy, you have
slightly shorter code. (If you override destroy it's fine, but then you
don't need to include the mixin. I prefer using it and overriding
perform_destroy).
- deletion must not be public, so you need to change the
permission_classes (for example in BaseMessageViewSet). You can then
add another unit test that looks for failures when you don't login.
Sorry for not spotting this in v1.
Thanks,
Paolo
> # Messages
>
> # 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 = 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 = 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)
> + 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 = 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