]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Only list checks for the given patch
authorStephen Finucane <stephen@that.guru>
Wed, 12 Sep 2018 15:46:56 +0000 (09:46 -0600)
committerStephen Finucane <stephen@that.guru>
Sun, 14 Oct 2018 13:37:53 +0000 (14:37 +0100)
This is either a regression or it never worked. In any case, fix it and
add a test to ensure it doesn't happen again.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Veronika Kabatova <vkabatov@redhat.com>
Closes: #203
(cherry picked from commit e80216a96eac6b1f1ed10aa9effd1d3120f2c3a1)

patchwork/api/check.py
patchwork/tests/api/test_check.py

index 8753c7de4e6c9c46485784649a35b4de2b378d15..1cfa5375b9b92d31e51adb7c3bfa896d8f3add70 100644 (file)
@@ -83,7 +83,8 @@ class CheckMixin(object):
     filter_class = CheckFilterSet
 
     def get_queryset(self):
-        return Check.objects.prefetch_related('patch', 'user')
+        patch_id = self.kwargs['patch_id']
+        return Check.objects.prefetch_related('user').filter(patch=patch_id)
 
 
 class CheckListCreate(CheckMixin, ListCreateAPIView):
index 43181af3d85d71a873af6e4296dcd20ce3c67abc..57d5b775b34b4330f9801c8ca431c7ac0a57249a 100644 (file)
@@ -54,9 +54,9 @@ class TestCheckAPI(APITestCase):
         self.user = create_maintainer(project)
         self.patch = create_patch(project=project)
 
-    def _create_check(self):
+    def _create_check(self, patch=None):
         values = {
-            'patch': self.patch,
+            'patch': patch if patch else self.patch,
             'user': self.user,
         }
         return create_check(**values)
@@ -75,6 +75,7 @@ class TestCheckAPI(APITestCase):
         self.assertEqual(0, len(resp.data))
 
         check_obj = self._create_check()
+        self._create_check(create_patch())  # second, unrelated patch
 
         resp = self.client.get(self.api_url())
         self.assertEqual(status.HTTP_200_OK, resp.status_code)