From e80216a96eac6b1f1ed10aa9effd1d3120f2c3a1 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 12 Sep 2018 09:46:56 -0600 Subject: [PATCH] REST: Only list checks for the given patch 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 Reviewed-by: Veronika Kabatova Closes: #203 --- patchwork/api/check.py | 3 ++- patchwork/tests/api/test_check.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 7dc97970..fbf05adb 100644 --- a/patchwork/api/check.py +++ b/patchwork/api/check.py @@ -69,7 +69,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): diff --git a/patchwork/tests/api/test_check.py b/patchwork/tests/api/test_check.py index 80e53cc0..783a6154 100644 --- a/patchwork/tests/api/test_check.py +++ b/patchwork/tests/api/test_check.py @@ -40,9 +40,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) @@ -62,6 +62,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) -- 2.47.3