[Patchew-devel] [PATCH v2] rest: Add endpoint from update-project-head

Shubham Jain posted 1 patch 5 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20180605031742.16613-1-shubhamjain7495@gmail.com
api/rest.py        | 23 ++++++++++++++++++++++-
tests/test_rest.py | 18 ++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
[Patchew-devel] [PATCH v2] rest: Add endpoint from update-project-head
Posted by Shubham Jain 5 years, 10 months ago
Added extra action in the ProjectViewSet which will update the project head at endpoint /projects/../update_project_head. This is legacy conversion(UpdateProjectHeadView) into rest
---
 api/rest.py        | 23 ++++++++++++++++++++++-
 tests/test_rest.py | 18 ++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/api/rest.py b/api/rest.py
index fa6ca3f..084dbbc 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -18,7 +18,7 @@ from .models import Project, Message
 from .search import SearchEngine
 from rest_framework import (permissions, serializers, viewsets, filters,
     mixins, generics, renderers, status)
-from rest_framework.decorators import detail_route
+from rest_framework.decorators import detail_route, action
 from rest_framework.fields import SerializerMethodField, CharField, JSONField, EmailField
 from rest_framework.relations import HyperlinkedIdentityField
 from rest_framework.response import Response
@@ -141,6 +141,27 @@ class ProjectsViewSet(viewsets.ModelViewSet):
     serializer_class = ProjectSerializer
     permission_classes = (PatchewPermission,)
 
+    @action(methods=['post'], detail=True, permission_classes=[ImportPermission])
+    def update_project_head(self, request, pk=None):
+        """
+        updates the project head and message_id which are matched are merged. 
+        Data input format:
+        {
+            "old_head": "..",
+            "new_head": "..",
+            "message_ids": []
+        }
+        """
+        project = self.get_object()
+        head = project.project_head
+        old_head = request.data['old_head']
+        message_ids = request.data['message_ids']
+        if head and head != old_head:
+            return Response('Wrong old head', status_code=status.HTTP_409_CONFLICT)
+        ret = project.series_update(message_ids)
+        project.project_head = request.data['new_head']
+        return Response({"new_head": project.project_head, "count": ret})
+
 # Common classes for series and messages
 
 class HyperlinkedMessageField(HyperlinkedIdentityField):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 1399801..2a85815 100755
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -86,6 +86,24 @@ class RestTest(PatchewTestCase):
         self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.org")
         self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE)
 
+    def test_update_project_head(self):
+       	resp = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
+                                       self.p.id, '20160628014747.20971-1-famz@redhat.com')
+        self.api_client.login(username=self.user, password=self.password)        
+        resp_before = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
+        data = {
+                "message_ids": ["20160628014747.20971-1-famz@redhat.com"],
+                "old_head": "None",
+                "new_head": "000000"
+                }
+        resp = self.api_client.post(self.PROJECT_BASE + "update_project_head/", data=json.dumps(data), content_type='application/json')
+        resp_after = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
+        self.assertEquals(resp_before.data['is_merged'], False)
+        self.assertEquals(resp.status_code, 200)
+        self.assertEquals(resp.data['count'], 1)
+        self.assertEquals(resp.data['new_head'], "000000")
+        self.assertEquals(resp_after.data['is_merged'], True)
+
     def test_project_post_no_login(self):
         data = {
             'name': 'keycodemapdb',
-- 
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 v2] rest: Add endpoint from update-project-head
Posted by Fam Zheng 5 years, 10 months ago
On Tue, 06/05 08:47, Shubham Jain wrote:
> Added extra action in the ProjectViewSet which will update the project head at endpoint /projects/../update_project_head. This is legacy conversion(UpdateProjectHeadView) into rest
> ---
>  api/rest.py        | 23 ++++++++++++++++++++++-
>  tests/test_rest.py | 18 ++++++++++++++++++
>  2 files changed, 40 insertions(+), 1 deletion(-)
> 
> diff --git a/api/rest.py b/api/rest.py
> index fa6ca3f..084dbbc 100644
> --- a/api/rest.py
> +++ b/api/rest.py
> @@ -18,7 +18,7 @@ from .models import Project, Message
>  from .search import SearchEngine
>  from rest_framework import (permissions, serializers, viewsets, filters,
>      mixins, generics, renderers, status)
> -from rest_framework.decorators import detail_route
> +from rest_framework.decorators import detail_route, action
>  from rest_framework.fields import SerializerMethodField, CharField, JSONField, EmailField
>  from rest_framework.relations import HyperlinkedIdentityField
>  from rest_framework.response import Response
> @@ -141,6 +141,27 @@ class ProjectsViewSet(viewsets.ModelViewSet):
>      serializer_class = ProjectSerializer
>      permission_classes = (PatchewPermission,)
>  
> +    @action(methods=['post'], detail=True, permission_classes=[ImportPermission])
> +    def update_project_head(self, request, pk=None):
> +        """
> +        updates the project head and message_id which are matched are merged. 
> +        Data input format:
> +        {
> +            "old_head": "..",
> +            "new_head": "..",
> +            "message_ids": []
> +        }
> +        """
> +        project = self.get_object()
> +        head = project.project_head
> +        old_head = request.data['old_head']
> +        message_ids = request.data['message_ids']
> +        if head and head != old_head:
> +            return Response('Wrong old head', status_code=status.HTTP_409_CONFLICT)
> +        ret = project.series_update(message_ids)
> +        project.project_head = request.data['new_head']
> +        return Response({"new_head": project.project_head, "count": ret})
> +
>  # Common classes for series and messages
>  
>  class HyperlinkedMessageField(HyperlinkedIdentityField):
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 1399801..2a85815 100755
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -86,6 +86,24 @@ class RestTest(PatchewTestCase):
>          self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.org")
>          self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE)
>  
> +    def test_update_project_head(self):
> +       	resp = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
> +                                       self.p.id, '20160628014747.20971-1-famz@redhat.com')

The tab should be whitespaces.

> +        self.api_client.login(username=self.user, password=self.password)        
> +        resp_before = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
> +        data = {
> +                "message_ids": ["20160628014747.20971-1-famz@redhat.com"],
> +                "old_head": "None",
> +                "new_head": "000000"
> +                }
> +        resp = self.api_client.post(self.PROJECT_BASE + "update_project_head/", data=json.dumps(data), content_type='application/json')
> +        resp_after = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
> +        self.assertEquals(resp_before.data['is_merged'], False)
> +        self.assertEquals(resp.status_code, 200)
> +        self.assertEquals(resp.data['count'], 1)
> +        self.assertEquals(resp.data['new_head'], "000000")
> +        self.assertEquals(resp_after.data['is_merged'], True)
> +
>      def test_project_post_no_login(self):
>          data = {
>              'name': 'keycodemapdb',
> -- 
> 2.15.1 (Apple Git-101)
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH v2] rest: Add endpoint from update-project-head
Posted by Paolo Bonzini 5 years, 10 months ago
On 05/06/2018 08:47, Fam Zheng wrote:
> On Tue, 06/05 08:47, Shubham Jain wrote:
>> Added extra action in the ProjectViewSet which will update the project head at endpoint /projects/../update_project_head. This is legacy conversion(UpdateProjectHeadView) into rest

Fixed the tab and applied, thanks!

Paolo

>> ---
>>  api/rest.py        | 23 ++++++++++++++++++++++-
>>  tests/test_rest.py | 18 ++++++++++++++++++
>>  2 files changed, 40 insertions(+), 1 deletion(-)
>>
>> diff --git a/api/rest.py b/api/rest.py
>> index fa6ca3f..084dbbc 100644
>> --- a/api/rest.py
>> +++ b/api/rest.py
>> @@ -18,7 +18,7 @@ from .models import Project, Message
>>  from .search import SearchEngine
>>  from rest_framework import (permissions, serializers, viewsets, filters,
>>      mixins, generics, renderers, status)
>> -from rest_framework.decorators import detail_route
>> +from rest_framework.decorators import detail_route, action
>>  from rest_framework.fields import SerializerMethodField, CharField, JSONField, EmailField
>>  from rest_framework.relations import HyperlinkedIdentityField
>>  from rest_framework.response import Response
>> @@ -141,6 +141,27 @@ class ProjectsViewSet(viewsets.ModelViewSet):
>>      serializer_class = ProjectSerializer
>>      permission_classes = (PatchewPermission,)
>>  
>> +    @action(methods=['post'], detail=True, permission_classes=[ImportPermission])
>> +    def update_project_head(self, request, pk=None):
>> +        """
>> +        updates the project head and message_id which are matched are merged. 
>> +        Data input format:
>> +        {
>> +            "old_head": "..",
>> +            "new_head": "..",
>> +            "message_ids": []
>> +        }
>> +        """
>> +        project = self.get_object()
>> +        head = project.project_head
>> +        old_head = request.data['old_head']
>> +        message_ids = request.data['message_ids']
>> +        if head and head != old_head:
>> +            return Response('Wrong old head', status_code=status.HTTP_409_CONFLICT)
>> +        ret = project.series_update(message_ids)
>> +        project.project_head = request.data['new_head']
>> +        return Response({"new_head": project.project_head, "count": ret})
>> +
>>  # Common classes for series and messages
>>  
>>  class HyperlinkedMessageField(HyperlinkedIdentityField):
>> diff --git a/tests/test_rest.py b/tests/test_rest.py
>> index 1399801..2a85815 100755
>> --- a/tests/test_rest.py
>> +++ b/tests/test_rest.py
>> @@ -86,6 +86,24 @@ class RestTest(PatchewTestCase):
>>          self.assertEquals(resp.data['mailing_list'], "qemu-block@nongnu.org")
>>          self.assertEquals(resp.data['parent_project'], self.PROJECT_BASE)
>>  
>> +    def test_update_project_head(self):
>> +       	resp = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
>> +                                       self.p.id, '20160628014747.20971-1-famz@redhat.com')
> 
> The tab should be whitespaces.
> 
>> +        self.api_client.login(username=self.user, password=self.password)        
>> +        resp_before = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
>> +        data = {
>> +                "message_ids": ["20160628014747.20971-1-famz@redhat.com"],
>> +                "old_head": "None",
>> +                "new_head": "000000"
>> +                }
>> +        resp = self.api_client.post(self.PROJECT_BASE + "update_project_head/", data=json.dumps(data), content_type='application/json')
>> +        resp_after = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
>> +        self.assertEquals(resp_before.data['is_merged'], False)
>> +        self.assertEquals(resp.status_code, 200)
>> +        self.assertEquals(resp.data['count'], 1)
>> +        self.assertEquals(resp.data['new_head'], "000000")
>> +        self.assertEquals(resp_after.data['is_merged'], True)
>> +
>>      def test_project_post_no_login(self):
>>          data = {
>>              'name': 'keycodemapdb',
>> -- 
>> 2.15.1 (Apple Git-101)
>>
>> _______________________________________________
>> Patchew-devel mailing list
>> Patchew-devel@redhat.com
>> https://www.redhat.com/mailman/listinfo/patchew-devel
> 
> _______________________________________________
> Patchew-devel mailing list
> Patchew-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/patchew-devel
> 

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel