[PATCH 2/3] REST: Expose cover mbox link via REST API
Stephen Finucane
stephen at that.guru
Fri May 26 18:34:16 AEST 2017
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
patchwork/api/cover.py | 6 +++++-
patchwork/tests/test_rest_api.py | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py
index 797cadf..f69d329 100644
--- a/patchwork/api/cover.py
+++ b/patchwork/api/cover.py
@@ -38,10 +38,14 @@ class CoverLetterListSerializer(HyperlinkedModelSerializer):
submitter = PersonSerializer(read_only=True)
series = SeriesSerializer(many=True, read_only=True)
+ def get_mbox(self, instance):
+ request = self.context.get('request')
+ return request.build_absolute_uri(instance.get_mbox_url())
+
class Meta:
model = CoverLetter
fields = ('id', 'url', 'project', 'msgid', 'date', 'name', 'submitter',
- 'series')
+ 'mbox', 'series')
read_only_fields = fields
extra_kwargs = {
'url': {'view_name': 'api-cover-detail'},
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index 8d64625..abffd17 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -457,6 +457,7 @@ class TestCoverLetterAPI(APITestCase):
def assertSerialized(self, cover_obj, cover_json):
self.assertEqual(cover_obj.id, cover_json['id'])
self.assertEqual(cover_obj.name, cover_json['name'])
+ self.assertIn(cover_obj.get_mbox_url(), cover_json['mbox'])
# nested fields
--
2.9.4
More information about the Patchwork
mailing list