[PATCH v6 08/10] REST: Add Patch.mbox_url

Andy Doan andy.doan at linaro.org
Fri Jun 17 07:13:23 AEST 2016


Provide a URL to the raw patch.

Signed-off-by: Andy Doan <andy.doan at linaro.org>
Reviewed-by: Stephen Finucane <stephen.finucane at intel.com>
---
 patchwork/models.py              | 4 ++++
 patchwork/rest_serializers.py    | 5 +++++
 patchwork/tests/test_rest_api.py | 1 +
 3 files changed, 10 insertions(+)

diff --git a/patchwork/models.py b/patchwork/models.py
index 6324273..6209527 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -458,6 +458,10 @@ class Patch(Submission):
     def get_absolute_url(self):
         return ('patch-detail', (), {'patch_id': self.id})
 
+    @models.permalink
+    def get_mbox_url(self):
+        return ('patch-mbox', (), {'patch_id': self.id})
+
     def __str__(self):
         return self.name
 
diff --git a/patchwork/rest_serializers.py b/patchwork/rest_serializers.py
index bfeaca8..962f875 100644
--- a/patchwork/rest_serializers.py
+++ b/patchwork/rest_serializers.py
@@ -85,11 +85,16 @@ class PatchSerializer(URLSerializer):
         # there's no need to expose an entire "tags" endpoint, so we custom
         # render this field
         exclude = ('tags',)
+    mbox_url = SerializerMethodField()
     state = SerializerMethodField()
 
     def get_state(self, obj):
         return obj.state.name
 
+    def get_mbox_url(self, patch):
+        request = self.context.get('request', None)
+        return request.build_absolute_uri(patch.get_mbox_url())
+
     def to_representation(self, instance):
         data = super(PatchSerializer, self).to_representation(instance)
         data['checks_url'] = data['url'] + 'checks/'
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index 3ed8469..f303e42 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -246,6 +246,7 @@ class TestPatchAPI(APITestCase):
         self.assertIn(TestPersonAPI.api_url(patches[0].submitter.id),
                       resp.data['submitter_url'])
         self.assertEqual(patches[0].state.name, resp.data['state'])
+        self.assertIn(patches[0].get_mbox_url(), resp.data['mbox_url'])
 
     def test_detail_tags(self):
         patches = create_patches()
-- 
2.7.4



More information about the Patchwork mailing list