]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Add 'store_samples' decorator to 'test_people'
authorStephen Finucane <stephen@that.guru>
Sun, 28 Oct 2018 15:36:46 +0000 (15:36 +0000)
committerStephen Finucane <stephen@that.guru>
Sat, 22 Dec 2018 16:13:26 +0000 (16:13 +0000)
Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/tests/api/test_person.py

index 3a89e73e8dd01f41551727d295b6ee71b82da219..aad37a7aab4f07418c7fb57b84b690f146fe2f6c 100644 (file)
@@ -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)