diff options
author | Stephen Finucane <stephen@that.guru> | 2017-05-24 11:29:31 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2017-05-30 21:42:55 +0100 |
commit | 5cbcd3ab6072ecef51d03a35856958242b3ca700 (patch) | |
tree | 910407296be1d186c0ebdd155881a9ffd11c2415 | |
parent | 5b716d482f3b612421c422966edf31a40beb7d3e (diff) | |
download | patchwork-5cbcd3ab6072ecef51d03a35856958242b3ca700.tar patchwork-5cbcd3ab6072ecef51d03a35856958242b3ca700.tar.gz |
REST: Expose cover mbox link via REST API
Signed-off-by: Stephen Finucane <stephen@that.guru>
-rw-r--r-- | patchwork/api/cover.py | 8 | ||||
-rw-r--r-- | patchwork/tests/test_rest_api.py | 1 |
2 files changed, 8 insertions, 1 deletions
diff --git a/patchwork/api/cover.py b/patchwork/api/cover.py index 797cadf..5d829eb 100644 --- a/patchwork/api/cover.py +++ b/patchwork/api/cover.py @@ -36,12 +36,17 @@ class CoverLetterListSerializer(HyperlinkedModelSerializer): project = ProjectSerializer(read_only=True) submitter = PersonSerializer(read_only=True) + mbox = SerializerMethodField() 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'}, @@ -49,6 +54,7 @@ class CoverLetterListSerializer(HyperlinkedModelSerializer): class CoverLetterDetailSerializer(CoverLetterListSerializer): + headers = SerializerMethodField() def get_headers(self, instance): 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 |