[Patchew-devel] [PATCH 2/2] rest : POST for message api endpoint

Shubham Jain shubhamjain7495 at gmail.com
Wed May 9 13:54:23 UTC 2018


Sure. At what time?

On Wed, May 9, 2018 at 7:21 PM Paolo Bonzini <pbonzini at redhat.com> wrote:

> On 08/05/2018 21:32, Shubham Jain wrote:
> > Add text/plain support to ProjectMessageSerializer's create (POST)
> action and 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
> >
> >  SEARCH_PARAM = 'q'
> >
> > @@ -316,9 +317,19 @@ class StaticTextRenderer(renderers.BaseRenderer):
> >          else:
> >              return data
> >
> > +class MessagePlainTextParser(BaseParser):
> > +    media_type = 'text/plain'
>
> Thinking more about it, 'message/rfc822' is a better content type.
>
> > +    def parse(self, stream, media_type=None, parser_context=None):
> > +
> > +        data = stream.read().decode("utf-8")
> > +        return MboxMessage(data).get_json()
>
> Beautiful. :)
>
> Technically, the decode here is wrong, MboxMessage should use the raw
> bytes.  But that is a preexisting problem, we can fix it later.  I'll
> create an issue on GitHub.
>
> I'll apply the two patches after a little bit of testing.  Ok to meet on
> IRC tomorrow (morning European time) and discuss the next part?
>
> Paolo
>
>
> >  class MessagesViewSet(ProjectMessagesViewSetMixin,
> >                        BaseMessageViewSet, mixins.CreateModelMixin):
> >      serializer_class = MessageSerializer
> > +    parser_classes = (JSONParser, MessagePlainTextParser, )
> > +
> >      @detail_route(renderer_classes=[StaticTextRenderer])
> >      def mbox(self, request, *args, **kwargs):
> >          message = 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")
> >
> > +    def test_create_text_message(self):
> > +        dp = self.get_data_path("0004-multiple-patch-reviewed.mbox.gz")
> > +        with open(dp, "r") as f:
> > +            data = f.read()
> > +        resp = self.api_client.post(self.PROJECT_BASE + "messages/",
> data, content_type='text/plain')
> > +        self.assertEqual(resp.status_code, 201)
> > +        resp_get = self.api_client.get(self.PROJECT_BASE + "messages/
> 1469192015-16487-1-git-send-email-berrange at 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")
> >
> >      def test_message(self):
> >          series = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/patchew-devel/attachments/20180509/e8b8363b/attachment.htm>


More information about the Patchew-devel mailing list