[Patchew-devel] [PATCH v5 5/6] Make Delete Command use REST

Paolo Bonzini pbonzini at redhat.com
Thu Jul 12 14:09:10 UTC 2018


On 12/07/2018 06:21, Shubham Jain wrote:
> Make patchew-cli's delete use REST api and added the missing test for delete
> ---
>  api/rest.py           |  2 ++
>  patchew-cli           | 16 +++++++++++++++-
>  tests/patchewtest.py  |  3 +++
>  tests/test_message.py | 15 +++++++++++++++
>  4 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/api/rest.py b/api/rest.py
> index 3045516..d714d09 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -320,6 +320,8 @@ class SeriesViewSet(BaseMessageViewSet):
>  
>  class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
>                             SeriesViewSet, mixins.DestroyModelMixin):
> +    authentication_classes = (CsrfExemptSessionAuthentication, )
> +    
>      def collect_patches(self, series):
>          if series.is_patch:
>              patches = [series]
> diff --git a/patchew-cli b/patchew-cli
> index 8029751..cb0b650 100755
> --- a/patchew-cli
> +++ b/patchew-cli
> @@ -181,7 +181,21 @@ class DeleteCommand(SubCommand):
>          if not argv and not args.all:
>              print("Must specify --all to delete all patches")
>              return 1
> -        self.api_do("delete", terms=argv)
> +        series_list = []
> +        if len(argv)==0:
> +            resp = self.rest_api_do("projects")
> +            for project in len(resp['result']):

This should be

   for project in resp('results']:

but apart from this it seems to work.

It's slow, but that should be fixed separately.  Profiling with "python
-m cProfile venv/bin/gunicorn patchew.wsgi" shows not much going on,
while "strace -ff venv/bin/gunicorn patchew.wsgi" shows a huge amount of
lstat and readlink calls.  I'm not sure why.

Paolo

> +                url = project['series']
> +                series_resp = self.rest_api_do(url)
> +                series_list = series_list + series_resp['results']
> +        else:
> +            for term in argv:
> +                url = str(self.base_url) + "/api/v1/series/?q=" + term
> +                series_resp = self.rest_api_do(url)
> +            series_list =  series_list + series_resp['results']
> +        for series in series_list:
> +            url = series['resource_uri']
> +            self.rest_api_do(url, request_method='delete')
>          return 0
>  
>  class ImportCommand(SubCommand):
> diff --git a/tests/patchewtest.py b/tests/patchewtest.py
> index 5bed3b9..847b3f9 100644
> --- a/tests/patchewtest.py
> +++ b/tests/patchewtest.py
> @@ -100,6 +100,9 @@ class PatchewTestCase(django.test.LiveServerTestCase):
>      def cli_import(self, mbox, rc=0):
>          self.check_cli(["import", self.get_data_path(mbox)], rc)
>  
> +    def cli_delete(self, terms, rc=0):
> +        self.check_cli(["delete", terms], rc)
> +
>      def get_data_path(self, fname):
>          r = tempfile.NamedTemporaryFile(dir=RUN_DIR, prefix="test-data-", delete=False)
>          d = os.path.join(BASE_DIR, "tests", "data", fname)
> diff --git a/tests/test_message.py b/tests/test_message.py
> index 9448aee..4b60c1d 100755
> --- a/tests/test_message.py
> +++ b/tests/test_message.py
> @@ -10,6 +10,7 @@
>  
>  import time
>  import datetime
> +import json
>  from tests.patchewtest import PatchewTestCase, main
>  
>  class ProjectTest(PatchewTestCase):
> @@ -40,6 +41,20 @@ class ProjectTest(PatchewTestCase):
>          age = message.get_age()
>          self.assertEqual(age, "1 day")
>  
> +    def test_delete(self):
> +        self.cli_login()
> +        self.add_project("QEMU", "qemu-devel at nongnu.org")
> +        self.cli_import("0002-unusual-cased-tags.mbox.gz")
> +        self.cli_import("0004-multiple-patch-reviewed.mbox.gz")
> +        a, b = self.check_cli(["search", "-r", "-o", "subject,properties,message-id"])
> +        ao = json.loads(a)[0]
> +        self.assertEqual(["Fam Zheng", "famz at redhat.com"],
> +                         ao["properties"]["reviewers"][0])
> +        self.cli_delete("from:Fam")
> +        a, b = self.check_cli(["search", "-r", "-o", "message-id"])
> +        ao = json.loads(a)[0]
> +        self.assertEqual("1469192015-16487-1-git-send-email-berrange at redhat.com", ao['message-id'])
> +
>      def test_asctime(self):
>          from api.models import Message
>          message = Message()
> 




More information about the Patchew-devel mailing list