From 3cf8ef463242ae8e432d35ec5313b51b4d63f3c5 Mon Sep 17 00:00:00 2001 From: Andy Doan Date: Thu, 16 Jun 2016 16:13:23 -0500 Subject: [PATCH] REST: Add Patch.mbox_url Provide a URL to the raw patch. Signed-off-by: Andy Doan Reviewed-by: Stephen Finucane --- 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 63242731..6209527d 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 552f84d3..688d8af5 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 837007d6..4f5886f7 100644 --- a/patchwork/tests/test_rest_api.py +++ b/patchwork/tests/test_rest_api.py @@ -260,6 +260,7 @@ class TestPatchAPI(APITestCase): self.assertIn(TestPersonAPI.api_url(self.patches[0].submitter.id), resp.data['submitter_url']) self.assertEqual(self.patches[0].state.name, resp.data['state']) + self.assertIn(self.patches[0].get_mbox_url(), resp.data['mbox_url']) def test_detail_tags(self): # defaults.project is remembered between TestCases and .save() is -- 2.47.3