[Patchew-devel] [PATCH v4 4/4] Make Import Command use Rest
Fam Zheng
famz at redhat.com
Tue Jul 10 07:52:50 UTC 2018
On Sat, 07/07 00:02, Shubham Jain wrote:
> Make patchew-cli's Import REST apis. For an authenticated but unauthorised user the exit status would be 1 ie when no projects are imported.
> Now importing same message to a project again would not give 404 error.
> Also changed a test case in test_tags accordingly.
> ---
> api/models.py | 3 +++
> api/rest.py | 5 +++--
> patchew-cli | 18 +++++++++++++-----
> tests/test_tags.py | 4 +---
> 4 files changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/api/models.py b/api/models.py
> index e712149..813a56f 100644
> --- a/api/models.py
> +++ b/api/models.py
> @@ -359,6 +359,9 @@ class MessageManager(models.Manager):
> def create(self, project, **validated_data):
> mbox = validated_data.pop('mbox')
> m = MboxMessage(mbox)
> + msg = Message.objects.filter(message_id=m.get_message_id(), project=project).first()
> + if msg is not None:
> + return msg
> msg = Message(**validated_data)
> if 'in_reply_to' not in validated_data:
> msg.in_reply_to = m.get_in_reply_to() or ""
> diff --git a/api/rest.py b/api/rest.py
> index c7818c4..876be75 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -321,7 +321,7 @@ class SeriesViewSet(BaseMessageViewSet):
> class ProjectSeriesViewSet(ProjectMessagesViewSetMixin,
> SeriesViewSet, mixins.DestroyModelMixin):
> authentication_classes = (CsrfExemptSessionAuthentication, )
> -
> +
> def collect_patches(self, series):
> if series.is_patch:
> patches = [series]
> @@ -423,7 +423,8 @@ class MessagesViewSet(BaseMessageViewSet):
> serializer_class = MessageSerializer
> permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
> parser_classes = (JSONParser, MessagePlainTextParser, )
> -
> + authentication_classes = (CsrfExemptSessionAuthentication, )
> +
> def create(self, request, *args, **kwargs):
> m = MboxMessage(request.data['mbox'])
> projects = [p for p in Project.objects.all() if p.recognizes(m)]
> diff --git a/patchew-cli b/patchew-cli
> index 509bb62..d553ea1 100755
> --- a/patchew-cli
> +++ b/patchew-cli
> @@ -220,11 +220,16 @@ class ImportCommand(SubCommand):
> print("[OLD] " + mo["Subject"])
> return
> print("[NEW] " + mo["Subject"])
> - r = self.api_do("import", mboxes=[mo.as_string()])
> - for p in r:
> - if p not in projects:
> - projects.add(p)
> - print(p)
> + for mbox in [mo.as_string()]:
> + r = self.rest_api_do(url_cmd="messages",
> + request_method='post',
> + content_type='message/rfc822',
> + data=mbox)
> + projects_list = [x['resource_uri'].split("messages")[0] for x in r['results']]
> + for p in projects_list:
> + if p not in projects:
> + projects.add(p)
> + print(p)
> if ff:
> open(ff, "wb").close()
>
> @@ -250,6 +255,9 @@ class ImportCommand(SubCommand):
> for f in args.file:
> try:
> import_one(f)
> + if len(projects)==0:
s/==0/ == 0/
> + print("The message was not imported to any project. Perhaps you're not logged in as an importer or maintainer")
> + r =1
s/=1/= 1/
> except:
> print("Error in importing:", f)
> traceback.print_exc()
> diff --git a/tests/test_tags.py b/tests/test_tags.py
> index 6c162de..c91e9c1 100755
> --- a/tests/test_tags.py
> +++ b/tests/test_tags.py
> @@ -22,9 +22,7 @@ class ImportTest(PatchewTestCase):
> self.p.save()
>
> def test_import_one(self):
> - resp = self.apply_and_retrieve('0017-qemu-web-is-not-qemu.mbox.gz',
> - self.p.id, '1504250391-6353-1-git-send-email-thuth at redhat.com')
> - self.assertEquals(resp.status_code, 404)
> + self.cli_import("0017-qemu-web-is-not-qemu.mbox.gz", rc=1)
>
> def test_rest_single(self):
> resp = self.apply_and_retrieve('0003-single-patch-reviewed.mbox.gz',
> --
> 2.15.1 (Apple Git-101)
>
> _______________________________________________
> 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