@@ -8,6 +8,7 @@ import unittest
from django.conf import settings
from django.urls import reverse
+from patchwork.tests.api import utils
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_person
from patchwork.tests.utils import create_user
@@ -42,31 +43,49 @@ class TestPersonAPI(APITestCase):
self.assertEqual(person_obj.user.id,
person_json['user']['id'])
- def test_list(self):
- """This API requires authenticated users."""
- person = create_person()
+ def test_list_empty(self):
+ """List people when none are present."""
+ # authentication is required
+ user = create_user(link_person=False)
+
+ self.client.force_authenticate(user=user)
+ resp = self.client.get(self.api_url())
+ self.assertEqual(status.HTTP_200_OK, resp.status_code)
+ self.assertEqual(0, len(resp.data))
+
+ @utils.store_samples('people-list-error-forbidden')
+ def test_list_anonymous(self):
+ """List people as anonymous user."""
+ create_person()
# anonymous user
resp = self.client.get(self.api_url())
self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
- # authenticated user
+ @utils.store_samples('people-list')
+ def test_list_authenticated(self):
+ """List people as an authenticated user."""
+ person = create_person()
user = create_user(link_person=False)
- self.client.force_authenticate(user=user)
+ self.client.force_authenticate(user=user)
resp = self.client.get(self.api_url())
self.assertEqual(status.HTTP_200_OK, resp.status_code)
self.assertEqual(1, len(resp.data))
self.assertSerialized(person, resp.data[0])
- def test_detail(self):
+ @utils.store_samples('people-detail-error-forbidden')
+ def test_detail_anonymous(self):
+ """Show person as anonymous user."""
person = create_person()
# anonymous user
resp = self.client.get(self.api_url(person.id))
self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code)
- # authenticated, unlinked user
+ def test_detail_unlinked(self):
+ """Show unlinked person as authenticted user."""
+ person = create_person()
user = create_user(link_person=False)
self.client.force_authenticate(user=user)
@@ -74,7 +93,9 @@ class TestPersonAPI(APITestCase):
self.assertEqual(status.HTTP_200_OK, resp.status_code)
self.assertSerialized(person, resp.data, has_user=False)
- # authenticated, linked user
+ @utils.store_samples('people-detail')
+ def test_detail_linked(self):
+ """Show linked person as authenticated user."""
user = create_user(link_person=True)
person = user.person_set.all().first()
self.client.force_authenticate(user=user)
Signed-off-by: Stephen Finucane <stephen@that.guru> --- patchwork/tests/api/test_person.py | 37 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-)