[Patchew-devel] [PATCH 4/5] rest: create separate results endpoint

Fam Zheng famz at redhat.com
Wed Mar 21 02:33:15 UTC 2018


On Sat, 03/17 15:47, Paolo Bonzini wrote:
> In the REST API, each series can have one or more results.  Right now
> results are synthesized from message properties which are set by
> the applier-report and tester-report API.  In order to simplify the
> conversion to REST of those APIs (e.g. using POST, PUT or PATCH
> requests), move the results out of the SeriesSerializer and into
> their own collection.
> 
> For now, the ViewSet is not model-based, but I am including
> paginator-like fields so that it should be possible to change it
> to a ModelViewSet in the future.
> 
> Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
> ---
>  api/rest.py           | 75 +++++++++++++++++++++++++++++++++++++++++----------
>  api/urls.py           |  5 ++++
>  mods/git.py           |  4 +--
>  mods/testing.py       |  4 +--
>  tests/test_git.py     | 40 +++++++++++++++------------
>  tests/test_rest.py    |  6 +++++
>  tests/test_testing.py | 28 +++++++++----------
>  7 files changed, 111 insertions(+), 51 deletions(-)
> 
> diff --git a/api/rest.py b/api/rest.py
> index 7df7618..3d22de8 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -8,19 +8,22 @@
>  # This work is licensed under the MIT License.  Please see the LICENSE file or
>  # http://opensource.org/licenses/MIT.
>  
> -from collections import namedtuple
> +from collections import namedtuple, OrderedDict
>  
>  from django.contrib.auth.models import User
> +from django.http import Http404
>  from django.template import loader
>  
>  from mod import dispatch_module_hook
>  from .models import Project, Message
>  from .search import SearchEngine
> -from rest_framework import permissions, serializers, viewsets, filters, mixins, renderers
> +from rest_framework import (permissions, serializers, viewsets, filters,
> +    mixins, generics, renderers)
>  from rest_framework.decorators import detail_route
> -from rest_framework.fields import SerializerMethodField
> +from rest_framework.fields import SerializerMethodField, CharField, JSONField
>  from rest_framework.relations import HyperlinkedIdentityField
>  from rest_framework.response import Response
> +import rest_framework
>  
>  SEARCH_PARAM = 'q'
>  
> @@ -143,16 +146,16 @@ class ProjectMessagesViewSetMixin(mixins.RetrieveModelMixin):
>      def get_queryset(self):
>          return self.queryset.filter(project=self.kwargs['projects_pk'])
>  
> -class Result(namedtuple("Result", "name status log_url data")):
> +class Result(namedtuple("Result", "name status log_url message data")):
>      __slots__ = ()
>  
> -    def __new__(cls, name, status, log_url=None, data=None, request=None):
> +    def __new__(cls, name, status, message, log_url=None, data=None, request=None):
>          if log_url is not None and request is not None:
>              log_url = request.build_absolute_uri(log_url)
>          if status not in ('pending', 'success', 'failure'):
>              raise ValueError("invalid value '%s' for status field" % status)
>          return super(cls, Result).__new__(cls, status=status, log_url=log_url,
> -                                          data=data, name=name)
> +                                          message=message, data=data, name=name)

Result model is useful for Project as well (we want to test project master too?
It will be important when we add this:

https://github.com/patchew-project/patchew/issues/32
(Test base branch as well when testing on topic failed, and use it as a
reference)

Fam




More information about the Patchew-devel mailing list