[Patchew-devel] [PATCH 2/3] add support for result PUT to mods/*

Shubham Jain posted 3 patches 6 years, 4 months ago
[Patchew-devel] [PATCH 2/3] add support for result PUT to mods/*
Posted by Shubham Jain 6 years, 4 months ago
Added serializer to validate data field in the PUT of the result
---
 mods/git.py     | 11 ++++++++++-
 mods/testing.py | 10 ++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/mods/git.py b/mods/git.py
index 924547a..0e1de86 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -23,6 +23,9 @@ from api.rest import PluginMethodField
 from api.views import APILoginRequiredView, prepare_series
 from patchew.logviewer import LogView
 from schema import *
+from rest_framework import serializers
+from rest_framework import serializers
+from rest_framework.fields import CharField
 
 _instance = None
 
@@ -42,11 +45,17 @@ class GitLogViewer(LogView):
             raise Http404("Object not found: " + series)
         return obj.git_result
 
+class DataSerializer(serializers.Serializer):
+    repo = CharField()
+    url = CharField()
+    base = CharField()
+    tag = CharField()
 
 class GitModule(PatchewModule):
     """Git module"""
     name = "git"
-
+    allowed_groups = ('importers', )
+    result_data_serializer_class = DataSerializer
     project_property_schema = \
         ArraySchema("git", desc="Configuration for git module",
                     members=[
diff --git a/mods/testing.py b/mods/testing.py
index 0a80b3d..37831b7 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -24,7 +24,8 @@ from api.search import SearchEngine
 from event import emit_event, declare_event, register_handler
 from patchew.logviewer import LogView
 from schema import *
-
+from rest_framework import serializers
+from rest_framework.fields import CharField, BooleanField
 _instance = None
 
 TESTING_SCRIPT_DEFAULT = """#!/bin/bash
@@ -46,12 +47,17 @@ class TestingLogViewer(LogView):
             raise Http404("Object not found: " + project_or_series)
         return _instance.get_testing_result(obj, testing_name)
 
+class DataSerializer(serializers.Serializer):
+    is_timeout = BooleanField()
+    head = CharField()
+    tester = CharField()
 
 class TestingModule(PatchewModule):
     """Testing module"""
 
     name = "testing"
-
+    allowed_groups = ('testers', )
+    result_data_serializer_class = DataSerializer
     test_schema = \
         ArraySchema("{name}", "Test", desc="Test spec",
                     members=[
-- 
2.15.1 (Apple Git-101)

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH 2/3] add support for result PUT to mods/*
Posted by Shubham Jain 6 years, 4 months ago
Please let me know if there is any corner case I'm missing or add general
tests.

On Wed, Aug 8, 2018 at 4:42 PM Shubham Jain <shubhamjain7495@gmail.com>
wrote:

> Added serializer to validate data field in the PUT of the result
> ---
>  mods/git.py     | 11 ++++++++++-
>  mods/testing.py | 10 ++++++++--
>  2 files changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/mods/git.py b/mods/git.py
> index 924547a..0e1de86 100644
> --- a/mods/git.py
> +++ b/mods/git.py
> @@ -23,6 +23,9 @@ from api.rest import PluginMethodField
>  from api.views import APILoginRequiredView, prepare_series
>  from patchew.logviewer import LogView
>  from schema import *
> +from rest_framework import serializers
> +from rest_framework import serializers
> +from rest_framework.fields import CharField
>
>  _instance = None
>
> @@ -42,11 +45,17 @@ class GitLogViewer(LogView):
>              raise Http404("Object not found: " + series)
>          return obj.git_result
>
> +class DataSerializer(serializers.Serializer):
> +    repo = CharField()
> +    url = CharField()
> +    base = CharField()
> +    tag = CharField()
>
>  class GitModule(PatchewModule):
>      """Git module"""
>      name = "git"
> -
> +    allowed_groups = ('importers', )
> +    result_data_serializer_class = DataSerializer
>      project_property_schema = \
>          ArraySchema("git", desc="Configuration for git module",
>                      members=[
> diff --git a/mods/testing.py b/mods/testing.py
> index 0a80b3d..37831b7 100644
> --- a/mods/testing.py
> +++ b/mods/testing.py
> @@ -24,7 +24,8 @@ from api.search import SearchEngine
>  from event import emit_event, declare_event, register_handler
>  from patchew.logviewer import LogView
>  from schema import *
> -
> +from rest_framework import serializers
> +from rest_framework.fields import CharField, BooleanField
>  _instance = None
>
>  TESTING_SCRIPT_DEFAULT = """#!/bin/bash
> @@ -46,12 +47,17 @@ class TestingLogViewer(LogView):
>              raise Http404("Object not found: " + project_or_series)
>          return _instance.get_testing_result(obj, testing_name)
>
> +class DataSerializer(serializers.Serializer):
> +    is_timeout = BooleanField()
> +    head = CharField()
> +    tester = CharField()
>
>  class TestingModule(PatchewModule):
>      """Testing module"""
>
>      name = "testing"
> -
> +    allowed_groups = ('testers', )
> +    result_data_serializer_class = DataSerializer
>      test_schema = \
>          ArraySchema("{name}", "Test", desc="Test spec",
>                      members=[
> --
> 2.15.1 (Apple Git-101)
>
>
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH 2/3] add support for result PUT to mods/*
Posted by Paolo Bonzini 6 years, 4 months ago
On 08/08/2018 14:07, Shubham Jain wrote:
> Please let me know if there is any corner case I'm missing or add
> general tests. 

I have only looked quickly, but at least some fields should be marked as
required=false.

Paolo

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH 2/3] add support for result PUT to mods/*
Posted by Shubham Jain 6 years, 4 months ago
I didn’t understand. Can you please elaborate?
Thanks.

On Wed, 8 Aug 2018 at 6:33 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 08/08/2018 14:07, Shubham Jain wrote:
> > Please let me know if there is any corner case I'm missing or add
> > general tests.
>
> I have only looked quickly, but at least some fields should be marked as
> required=false.
>
> Paolo
>
_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel