From nobody Tue May 13 12:01:03 2025 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 1525807974592616.4217010067574; Tue, 8 May 2018 12:32:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C59F61BB4; Tue, 8 May 2018 19:32:53 +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 8CFC2600CC; Tue, 8 May 2018 19:32:53 +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 81607180BADC; Tue, 8 May 2018 19:32:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w48JWpZ2017124 for ; Tue, 8 May 2018 15:32:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC2655D9CC; Tue, 8 May 2018 19:32:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3D035D9CA for ; Tue, 8 May 2018 19:32:47 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (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 80E1480C29 for ; Tue, 8 May 2018 19:32:36 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id az12-v6so2803979plb.8 for ; Tue, 08 May 2018 12:32:36 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.149]) by smtp.gmail.com with ESMTPSA id d19sm62749993pfk.59.2018.05.08.12.32.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 12:32:34 -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:in-reply-to:references; bh=tSi8kRt8vLRtbeltawAP7j3GJadC384Kzbl2JwDy2Ww=; b=SPzQfhvcg6nrtPyo2e+vYd7nYcYVPhnM02OZb6adLkuKBNfroiCX81e+C6narVaRY0 P5jdRpFOFhNUTJTHd0s24P3etg1XV4o5Vz9rKL4thUOrcUcdRoazS3aad59u18QvQ4rL 4GJ6obBpHUb/62yojfeSrx6+2f3fA403qhH7JI2WJDWb6DFFhJlhu+AK4TcFQ1Mi7eYm ZYo2sI0K/04bRTQDuTr91nhrwp6lx4PqKOYBIONLBMcT1SIGQClKd49Vj8typ/SE5UwA 9nyknxo5nWLiJAGdpk8chooDZg5Pnag1Xg8mrFZ6nD+0taGiz0LvD/pNX4/tKkIpqIsT dscg== 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:in-reply-to :references; bh=tSi8kRt8vLRtbeltawAP7j3GJadC384Kzbl2JwDy2Ww=; b=oVODa7/RSgftCO33pkXXs6l3gyfexYLL+1UBYl1QV9PYLsH06UITcJRa1iNfqdurJ3 ViBv0NHgCdfS4L9vb84MhW1RbPJz/N2wtxRDknBvwagGlLqR64KH16MF0ekFl1axcX/P CtOGAQzLyo4+vaPUgVEaGCu9tFovpslJj4W2IKpGz6jGELC6UbmC3hp26OiT3Ch3xNyr RIHjzUkINgX4COACWyA9UqpIipSAvzF7rzffQhasnxGvyEf6MZ7832hQE2kNJj9puShx 215vtUjkNYusAHPLS/RaMH5l9OtLef9kokpxip2FYcU5AuGOSKCAX6DBvNw+5ApDnwAi Cp8Q== X-Gm-Message-State: ALQs6tAm3JapAIgipNrdSkU5eWPkJrxJcHigpAz4xvytHFTNaZGTSoIn QVmkN9pGt5NaZnylAWxLywhqvw== X-Google-Smtp-Source: AB8JxZrNQ43V518vwN0Tpvc8LHg3NPSDexa/IULnWYmtj7wzfhK4rgMl1edxh28IZXCU07FSb1419g== X-Received: by 2002:a17:902:564:: with SMTP id 91-v6mr42310427plf.63.1525807955456; Tue, 08 May 2018 12:32:35 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Wed, 9 May 2018 01:02:07 +0530 Message-Id: <20180508193207.7663-3-shubhamjain7495@gmail.com> In-Reply-To: <20180508193207.7663-1-shubhamjain7495@gmail.com> References: <20180508193207.7663-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 08 May 2018 19:32:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 08 May 2018 19:32:36 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.531 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH 2/2] rest : POST for message api endpoint 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.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 08 May 2018 19:32:53 +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" Add text/plain support to ProjectMessageSerializer's create (POST) action a= nd add corresponding test to it. --- api/rest.py | 13 ++++++++++++- tests/test_rest.py | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/api/rest.py b/api/rest.py index 06faf57..4bd064d 100644 --- a/api/rest.py +++ b/api/rest.py @@ -23,7 +23,8 @@ from rest_framework.fields import SerializerMethodField, = CharField, JSONField, E from rest_framework.relations import HyperlinkedIdentityField from rest_framework.response import Response import rest_framework -from mbox import addr_db_to_rest +from mbox import addr_db_to_rest, MboxMessage +from rest_framework.parsers import JSONParser, BaseParser =20 SEARCH_PARAM =3D 'q' =20 @@ -316,9 +317,19 @@ class StaticTextRenderer(renderers.BaseRenderer): else: return data =20 +class MessagePlainTextParser(BaseParser): + media_type =3D 'text/plain' + + def parse(self, stream, media_type=3DNone, parser_context=3DNone): + =20 + data =3D stream.read().decode("utf-8") + return MboxMessage(data).get_json() + class MessagesViewSet(ProjectMessagesViewSetMixin, BaseMessageViewSet, mixins.CreateModelMixin): serializer_class =3D MessageSerializer + parser_classes =3D (JSONParser, MessagePlainTextParser, ) + @detail_route(renderer_classes=3D[StaticTextRenderer]) def mbox(self, request, *args, **kwargs): message =3D self.get_object() diff --git a/tests/test_rest.py b/tests/test_rest.py index 3baadd5..1911800 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -268,6 +268,15 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data['subject'], "[Qemu-devel] [PATCH v2 10/= 27] imx_fec: Reserve full 4K " "page for the register file") =20 + def test_create_text_message(self): + dp =3D self.get_data_path("0004-multiple-patch-reviewed.mbox.gz") + with open(dp, "r") as f: + data =3D f.read() + resp =3D self.api_client.post(self.PROJECT_BASE + "messages/", dat= a, content_type=3D'text/plain') + self.assertEqual(resp.status_code, 201) + resp_get =3D self.api_client.get(self.PROJECT_BASE + "messages/146= 9192015-16487-1-git-send-email-berrange@redhat.com/") + self.assertEqual(resp_get.status_code, 200) + self.assertEqual(resp.data['subject'], "[Qemu-devel] [PATCH v4 0/2= ] Report format specific info for LUKS block driver") =20 def test_message(self): series =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', --=20 2.14.3 (Apple Git-98) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel