[PATCH v3 13/16] REST: Add id field to all endpoints
Stephen Finucane
stephen at that.guru
Sat Nov 26 05:18:32 AEDT 2016
Signed-off-by: Stephen Finucane <stephen at that.guru>
Reviewed-by: Daniel Axtens <dja at axtens.net>
---
v3:
- Add missing unit tests
---
patchwork/api/check.py | 2 +-
patchwork/api/patch.py | 6 +++---
patchwork/api/person.py | 2 +-
patchwork/api/project.py | 2 +-
patchwork/api/user.py | 2 +-
patchwork/tests/test_rest_api.py | 5 +++++
6 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/patchwork/api/check.py b/patchwork/api/check.py
index 78c2141..a66106e 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -77,7 +77,7 @@ class CheckSerializer(HyperlinkedModelSerializer):
class Meta:
model = Check
- fields = ('url', 'patch', 'user', 'date', 'state', 'target_url',
+ fields = ('id', 'url', 'patch', 'user', 'date', 'state', 'target_url',
'context', 'description')
read_only_fields = ('date',)
extra_kwargs = {
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index f818f20..bff1c6a 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -79,9 +79,9 @@ class PatchListSerializer(HyperlinkedModelSerializer):
class Meta:
model = Patch
- fields = ('url', 'project', 'msgid', 'date', 'name', 'commit_ref',
- 'pull_url', 'state', 'archived', 'hash', 'submitter',
- 'delegate', 'mbox', 'check', 'checks', 'tags')
+ fields = ('id', 'url', 'project', 'msgid', 'date', 'name',
+ 'commit_ref', 'pull_url', 'state', 'archived', 'hash',
+ 'submitter', 'delegate', 'mbox', 'check', 'checks', 'tags')
read_only_fields = ('project', 'msgid', 'date', 'name', 'hash',
'submitter', 'mbox', 'mbox', 'series', 'check',
'checks', 'tags')
diff --git a/patchwork/api/person.py b/patchwork/api/person.py
index c84cff5..2c1ca15 100644
--- a/patchwork/api/person.py
+++ b/patchwork/api/person.py
@@ -28,7 +28,7 @@ from patchwork.models import Person
class PersonSerializer(HyperlinkedModelSerializer):
class Meta:
model = Person
- fields = ('url', 'name', 'email', 'user')
+ fields = ('id', 'url', 'name', 'email', 'user')
read_only_fields = fields
extra_kwargs = {
'url': {'view_name': 'api-person-detail'},
diff --git a/patchwork/api/project.py b/patchwork/api/project.py
index 52b1763..deaeb09 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -34,7 +34,7 @@ class ProjectSerializer(HyperlinkedModelSerializer):
class Meta:
model = Project
- fields = ('url', 'name', 'link_name', 'list_id', 'list_email',
+ fields = ('id', 'url', 'name', 'link_name', 'list_id', 'list_email',
'web_url', 'scm_url', 'webscm_url')
read_only_fields = ('name',)
extra_kwargs = {
diff --git a/patchwork/api/user.py b/patchwork/api/user.py
index c5f7c05..2153cc9 100644
--- a/patchwork/api/user.py
+++ b/patchwork/api/user.py
@@ -37,7 +37,7 @@ class UserSerializer(HyperlinkedModelSerializer):
class Meta:
model = User
- fields = ('url', 'username', 'first_name', 'last_name', 'email')
+ fields = ('id', 'url', 'username', 'first_name', 'last_name', 'email')
# we don't allow updating of emails via the API, as we need to
# validate that the User actually owns said email first
read_only_fields = ('username', 'email')
diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py
index 618c66c..f44a77f 100644
--- a/patchwork/tests/test_rest_api.py
+++ b/patchwork/tests/test_rest_api.py
@@ -53,6 +53,7 @@ class TestProjectAPI(APITestCase):
return reverse('api-project-detail', args=[item])
def assertSerialized(self, project_obj, project_json):
+ self.assertEqual(project_obj.id, project_json['id'])
self.assertEqual(project_obj.name, project_json['name'])
self.assertEqual(project_obj.linkname, project_json['link_name'])
self.assertEqual(project_obj.listid, project_json['list_id'])
@@ -153,6 +154,7 @@ class TestPersonAPI(APITestCase):
return reverse('api-person-detail', args=[item])
def assertSerialized(self, person_obj, person_json, has_user=False):
+ self.assertEqual(person_obj.id, person_json['id'])
if not has_user:
self.assertEqual(person_obj.name, person_json['name'])
self.assertEqual(person_obj.email, person_json['email'])
@@ -230,6 +232,7 @@ class TestUserAPI(APITestCase):
return reverse('api-user-detail', args=[item])
def assertSerialized(self, user_obj, user_json):
+ self.assertEqual(user_obj.id, user_json['id'])
self.assertEqual(user_obj.username, user_json['username'])
self.assertNotIn('password', user_json)
self.assertNotIn('is_superuser', user_json)
@@ -285,6 +288,7 @@ class TestPatchAPI(APITestCase):
return reverse('api-patch-detail', args=[item])
def assertSerialized(self, patch_obj, patch_json):
+ self.assertEqual(patch_obj.id, patch_json['id'])
self.assertEqual(patch_obj.name, patch_json['name'])
self.assertEqual(patch_obj.msgid, patch_json['msgid'])
self.assertEqual(patch_obj.state.name, patch_json['state'])
@@ -423,6 +427,7 @@ class TestCheckAPI(APITestCase):
return create_check(**values)
def assertSerialized(self, check_obj, check_json):
+ self.assertEqual(check_obj.id, check_json['id'])
self.assertEqual(check_obj.get_state_display(), check_json['state'])
self.assertEqual(check_obj.target_url, check_json['target_url'])
self.assertEqual(check_obj.context, check_json['context'])
--
2.7.4
More information about the Patchwork
mailing list