From nobody Thu Apr 25 11:44:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1524909180974370.5166329676324; Sat, 28 Apr 2018 02:53:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D35B030BEA79; Sat, 28 Apr 2018 09:52:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C679C1C05A; Sat, 28 Apr 2018 09:52:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3B184180886C; Sat, 28 Apr 2018 09:52:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3S9olNu003186 for ; Sat, 28 Apr 2018 05:50:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8B69A39BA; Sat, 28 Apr 2018 09:50:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8574C17C47 for ; Sat, 28 Apr 2018 09:50:45 +0000 (UTC) Received: from mail-pg0-f47.google.com (mail-pg0-f47.google.com [74.125.83.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4BB8804F8 for ; Sat, 28 Apr 2018 09:50:33 +0000 (UTC) Received: by mail-pg0-f47.google.com with SMTP id l2-v6so3234549pgc.7 for ; Sat, 28 Apr 2018 02:50:33 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.75]) by smtp.gmail.com with ESMTPSA id w1sm6955135pfb.39.2018.04.28.02.50.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Apr 2018 02:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=GAaDYnTW7Sp7kLhnBZQ+U9+FErbRUy+Bz9YntgIQ7EM=; b=T5TvaJ0JiOzAqy0gkKXjZxveySXqlaRcd9SMU1cqBEQstDuXqUvBweRPKsL64BwdOP GgEp4SjNmt9ryFY3NaQAmKwCNzF2RaKbwGDrsJNa82m4VDFrO5SmAlQ7pAitjWQwNBhr ALOt6HIbsQuKQnnzp25enivRr6WRFWoonlvKCgUQkM1uCnBuq99l/ZPB+VVFaX/T2gRT w3z98Ij6va6U6i1/c1p2VcKQv6u6pvH+I07hZ4pM5aVpzJxRsm6zZsce5ivE0+NztZR9 m7vX+w4Ksaq4NbIA4bPv0bPvNOIfdORa7U9Ud0UshSBi3eqPXKR2qRU7WBAlS0jeKEd9 u3+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GAaDYnTW7Sp7kLhnBZQ+U9+FErbRUy+Bz9YntgIQ7EM=; b=UEXRnJ4wykd6OZE+13ArjtIKwyf5U2bkS4TJ7VU6B8ef/rq04BSaoFatkZTk8UkHfH EXZ2eKPkMXzM1D5/pWdRu+O4Govtw51QVcGrN/1P7ERBcDUcttIWoxuHNMw0ghjCldNO 9h2dPKgN/yOqybVafVg+ebm8B04K+KJdkliesJbhWyQjtFXNBkFvsnTiITGj7bIZEmZR d++iz+mqYbgg5O0VR+RHfuk0f3V0VGczLbgNcX4jam4ixshdqVtOHvJG0L4fXujynbou wu256J5p9GXEYp9acj+1jUgELiaapJLssPM7tKZmbLBQeSd/zQ2cGTJ/Ssk+X5aeMOEj mvEA== X-Gm-Message-State: ALQs6tCcBHzaYKx3jDDB8g9AzmsRWaFSzfqh2wfwxfmEZydsQATXBJMv edJsuz6dxyGG+jBd62jiF0sfJw== X-Google-Smtp-Source: AB8JxZr1i0DIMm7voHzxBLhsrg+zuZMjWE7Tbx4pRyeMo7+kG52t5s4smURXEaVJb3z+gb8AOi1xdg== X-Received: by 2002:a65:6645:: with SMTP id z5-v6mr672580pgv.43.1524909032453; Sat, 28 Apr 2018 02:50:32 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Sat, 28 Apr 2018 15:20:17 +0530 Message-Id: <20180428095017.46366-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 28 Apr 2018 09:50:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 28 Apr 2018 09:50:33 +0000 (UTC) for IP:'74.125.83.47' DOMAIN:'mail-pg0-f47.google.com' HELO:'mail-pg0-f47.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.55 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 74.125.83.47 mail-pg0-f47.google.com 74.125.83.47 mail-pg0-f47.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v3] Text to json convertor for mbox X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 28 Apr 2018 09:52:59 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Mbox would now return a dictionary object which would help REST API deser= ialize easily into model object. - Added test for text to json converter. [WIP] POST endpoint for messages. - It's a work in progress for creating new message which is improvement of = legacy endpoint: "import" --- api/rest.py | 4 +- mbox.py | 18 +++++++++ tests/test_mbox.py | 110 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 129 insertions(+), 3 deletions(-) diff --git a/api/rest.py b/api/rest.py index 381b569..cced462 100644 --- a/api/rest.py +++ b/api/rest.py @@ -286,7 +286,6 @@ class MessageSerializer(BaseMessageSerializer): class Meta: model =3D Message fields =3D BaseMessageSerializer.Meta.fields + ('mbox', ) - def get_mbox(self, obj): return obj.get_mbox() mbox =3D SerializerMethodField() @@ -311,9 +310,8 @@ class StaticTextRenderer(renderers.BaseRenderer): return data =20 class MessagesViewSet(ProjectMessagesViewSetMixin, - BaseMessageViewSet): + BaseMessageViewSet, mixins.CreateModelMixin): serializer_class =3D MessageSerializer - @detail_route(renderer_classes=3D[StaticTextRenderer]) def mbox(self, request, *args, **kwargs): message =3D self.get_object() diff --git a/mbox.py b/mbox.py index fe108f3..c391fb0 100644 --- a/mbox.py +++ b/mbox.py @@ -269,3 +269,21 @@ class MboxMessage(object): if c =3D=3D 0: return True return False + + def get_json(self): + """Return the JSON format of the mbox """ + msg =3D {} + msg['message_id'] =3D self.get_message_id() + msg['in_reply_to'] =3D self.get_in_reply_to() or "" + msg['date'] =3D self.get_date() + msg['subject'] =3D self.get_subject() + msg['stripped_subject'] =3D self.get_subject(strip_tags=3DTrue) + msg['version'] =3D self.get_version() + msg['sender'] =3D self.get_from() + msg['recipients'] =3D self.get_to() + self.get_cc() + msg['prefixes']=3D self.get_prefixes() + msg['is_series_head'] =3D self.is_series_head() + msg['is_patch'] =3D self.is_patch() + msg['patch_num'] =3D self.get_num()[0] + msg['mbox'] =3D self.get_mbox() + return msg diff --git a/tests/test_mbox.py b/tests/test_mbox.py index 8493df7..5b7f10e 100755 --- a/tests/test_mbox.py +++ b/tests/test_mbox.py @@ -13,6 +13,7 @@ import sys import mbox sys.path.append(os.path.dirname(__file__)) from patchewtest import PatchewTestCase, main +import datetime =20 class MboxTest(PatchewTestCase): =20 @@ -52,5 +53,114 @@ Virtualization: qemu.org | libvirt.org msg =3D mbox.MboxMessage(f.read()) self.assertTrue(msg.is_patch()) =20 + def test_get_json(self): + expected =3D {'message_id': '20160628014747.20971-1-famz@redhat.co= m',=20 + 'in_reply_to': '',=20 + 'date': datetime.datetime(2016, 6, 28, 1, 47, 47),=20 + 'subject': '[Qemu-devel] [PATCH] quorum: Only compile = when supported',=20 + 'stripped_subject': 'quorum: Only compile when support= ed',=20 + 'version': 1,=20 + 'sender': ('Fam Zheng', 'famz@redhat.com'),=20 + 'recipients': [('qemu-devel@nongnu.org', 'qemu-devel@n= ongnu.org'),=20 + ('Kevin Wolf', 'kwolf@redhat.com'),=20 + ('Alberto Garcia', 'berto@igalia.com'), + ('qemu-block@nongnu.org', 'qemu-block@n= ongnu.org'),=20 + ('Max Reitz', 'mreitz@redhat.com')], + 'prefixes': ['Qemu-devel', 'PATCH'], + 'is_series_head': True,=20 + 'is_patch': True,=20 + 'patch_num': None, + 'mbox': 'Delivered-To: importer@patchew.org\nReceived-= SPF: ' + 'Pass (zoho.com: domain of qemu-devel-bounces@= nongnu.org ' + 'designates 208.118.235.17 as permitted sender= ) client-ip: ' + '208.118.235.17\nReceived-SPF: pass (zoho.com:= domain of ' + 'gnu.org designates 208.118.235.17 as permitte= d sender) ' + 'client-ip=3D208.118.235.17; envelope-from=3Dq= emu-devel-bounces+' + 'importer=3Dpatchew.org@nongnu.org; helo=3Dlis= ts.gnu.org;\n' + 'Return-Path: ' + '\nReceived: from lists.gnu.org (lists.gnu.org= [208.118.235.17]) ' + 'by mx.zohomail.com\n\twith SMTPS id 146707897= 1424862.8927889595075;' + ' Mon, 27 Jun 2016 18:56:11 -0700 (PDT)\nRecei= ved: from localhost ' + '([::1]:33689 helo=3Dlists.gnu.org)\n\tby list= s.gnu.org with esmtp ' + '(Exim 4.71)\n\t(envelope-from )\n\tid 1bHi94-0006LP-= Ok\n\tfor ' + 'importer@patchew.org; Mon, 27 Jun 2016 21:48:= 58 -0400\nReceived: ' + 'from eggs.gnu.org ([2001:4830:134:3::10]:5327= 0)\n\tby lists.gnu.org' + ' with esmtp (Exim 4.71)\n\t(envelope-from ) id ' + '1bHi8E-0002Lm-KR\n\tfor qemu-devel@nongnu.org= ; Mon, 27 Jun 2016 ' + '21:48:07 -0400\nReceived: from Debian-exim by= eggs.gnu.org with ' + 'spam-scanned (Exim 4.71)\n\t(envelope-from ) ' + 'id 1bHi8D-0008T4-N7\n\tfor qemu-devel@nongnu.= org; Mon, 27 Jun ' + '2016 21:48:06 -0400\nReceived: from mx1.redha= t.com ' + '([209.132.183.28]:47972)\n\tby eggs.gnu.org w= ith esmtp ' + '(Exim 4.71)\n\t(envelope-from )\n\tid ' + '1bHi86-0008SN-IZ; Mon, 27 Jun 2016 21:47:58 -= 0400\nReceived: ' + 'from int-mx10.intmail.prod.int.phx2.redhat.co= m\n\t' + '(int-mx10.intmail.prod.int.phx2.redhat.com [1= 0.5.11.23])\n\t' + '(using TLSv1.2 with cipher ECDHE-RSA-AES256-G= CM-SHA384 ' + '(256/256 bits))\n\t(No client certificate req= uested)\n\tby ' + 'mx1.redhat.com (Postfix) with ESMTPS id BDB00= 7F088;\n\tTue, ' + '28 Jun 2016 01:47:57 +0000 (UTC)\nReceived: ' + 'from ad.usersys.redhat.com (dhcp-15-133.nay.r= edhat.com\n\t' + '[10.66.15.133])\n\tby int-mx10.intmail.prod.i= nt.phx2.redhat.com' + ' (8.14.4/8.14.4) with ESMTP\n\tid u5S1lssT024= 908; Mon, 27 Jun ' + '2016 21:47:55 -0400\nFrom: Fam Zheng \nTo: ' + 'qemu-devel@nongnu.org\nDate: Tue, 28 Jun 2016= 09:47:47 ' + '+0800\nMessage-Id: <20160628014747.20971-1-fa= mz@redhat.com>\n' + 'X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23\n= X-Greylist: ' + 'Sender IP whitelisted, not delayed by milter-= greylist-4.5.16\n\t' + '(mx1.redhat.com [10.5.110.26]);\n\tTue, 28 Ju= n 2016 01:47:57 ' + '+0000 (UTC)\nX-detected-operating-system: by = eggs.gnu.org: ' + 'GNU/Linux 2.2.x-3.x [generic]\nX-Received-Fro= m: 209.132.183.28\n' + 'Subject: [Qemu-devel] [PATCH] quorum: Only co= mpile when supported\n' + 'X-BeenThere: qemu-devel@nongnu.org\nX-Mailman= -Version: 2.1.21\n' + 'Precedence: list\nList-Id: \nList-Unsubscribe:' + ' ,\n\t' + '\n' + 'List-Archive: \n' + 'List-Post: \nLi= st-Help: ' + '\nList-Subscribe:' + ' ,\n\t' + '\nCc:' + ' Kevin Wolf , Alberto Garci= a ,' + '\n\tqemu-block@nongnu.org, Max Reitz \nErrors-To:' + ' qemu-devel-bounces+importer=3Dpatchew.org@no= ngnu.org\nSender: ' + '"Qemu-devel" \n' + 'X-ZohoMail-Owner: <20160628014747.20971-1-fam= z@redhat.com>+zmo_0_' + '\n' + 'X-ZohoMail-Sender: 209.132.183.28\nX-ZohoMail= : RSF_0 Z_629925259 ' + 'SPT_1 Z_629926901 SPT_1 SS_1 SFPD SFPP UW246= 8 UB2468 ZFF-EB_1' + ' COSF ODL SGR3_1_2_0_27046_53\nX-Zoho-Viru= s-Status: 2\n\n' + 'This was the only exceptional module init fun= ction that does ' + 'something\nelse than a simple list of bdrv_re= gister() calls, ' + 'in all the block\ndrivers.\n\nThe qcrypto_has= h_supports is actually' + ' a static check, determined at\ncompile time.= Follow the ' + 'block-job-$(CONFIG_FOO) convention for\nconsi= stency.\n\n' + 'Signed-off-by: Fam Zheng \n-= --\n block/' + 'Makefile.objs | 2 +-\n block/quorum.c | = 4 ----\n 2 files' + ' changed, 1 insertion(+), 5 deletions(-)\n\nd= iff --git a/block/' + 'Makefile.objs b/block/Makefile.objs\nindex 44= a5416..c87d605 ' + '100644\n--- a/block/Makefile.objs\n+++ b/bloc= k/Makefile.objs\n@@' + ' -3,7 +3,7 @@ block-obj-y +=3D qcow2.o qcow2-= refcount.o qcow2-cluster.o' + ' qcow2-snapshot.o qcow2-c\n block-obj-y +=3D = qed.o qed-gencb.o ' + 'qed-l2-cache.o qed-table.o qed-cluster.o\n bl= ock-obj-y +=3D ' + 'qed-check.o\n block-obj-$(CONFIG_VHDX) +=3D v= hdx.o vhdx-endian.o' + ' vhdx-log.o\n-block-obj-y +=3D quorum.o\n+blo= ck-obj-$(CONFIG_GNUTLS_HASH)' + ' +=3D quorum.o\n block-obj-y +=3D parallels.o= blkdebug.o blkverify.o ' + 'blkreplay.o\n block-obj-y +=3D block-backend.= o snapshot.o qapi.o\n ' + 'block-obj-$(CONFIG_WIN32) +=3D raw-win32.o wi= n32-aio.o\ndiff --git ' + 'a/block/quorum.c b/block/quorum.c\nindex 331b= 726..18fbed8 100644\n' + '--- a/block/quorum.c\n+++ b/block/quorum.c\n@= @ -1113,10 +1113,6 @@' + ' static BlockDriver bdrv_quorum =3D {\n \n st= atic void bdrv_quorum_init' + '(void)\n {\n- if (!qcrypto_hash_supports(Q= CRYPTO_HASH_ALG_SHA256))' + ' {\n- /* SHA256 hash support is requir= ed for quorum device */\n-' + ' return;\n- }\n bdrv_register(&= bdrv_quorum);\n }\n \n-- \n' + '2.9.0\n\n\n'} + dp =3D self.get_data_path("0001-simple-patch.mbox.gz") + with open(dp, "r") as f: + msg =3D mbox.MboxMessage(f.read()).get_json() + self.assertEqual(msg, expected) + + if __name__ =3D=3D '__main__': main() --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel