[PATCH] REST: Only list checks for the given patch

Veronika Kabatova vkabatov at redhat.com
Thu Sep 20 02:54:13 AEST 2018



----- Original Message -----
> From: "Stephen Finucane" <stephen at that.guru>
> To: patchwork at lists.ozlabs.org
> Cc: "Michael Ellerman" <mpe at ellerman.id.au>
> Sent: Wednesday, September 12, 2018 5:46:56 PM
> 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.
> 

This was driving me nuts for the past year but I thought it's a feature I
don't appreciate and not a bug. Anyways, the patch fixes the problem on my
instance and I don't see any problem with the filter addition either.

Reviewed-by: Veronika Kabatova <vkabatov at redhat.com>

> Signed-off-by: Stephen Finucane <stephen at that.guru>
> Cc: Michael Ellerman <mpe at ellerman.id.au>
> 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 5e461de6..712238eb 100644
> --- a/patchwork/api/check.py
> +++ b/patchwork/api/check.py
> @@ -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):
> diff --git a/patchwork/tests/api/test_check.py
> b/patchwork/tests/api/test_check.py
> index 6f4aa5de..4c6a934c 100644
> --- a/patchwork/tests/api/test_check.py
> +++ b/patchwork/tests/api/test_check.py
> @@ -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)
> @@ -76,6 +76,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.17.1
> 
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
> 


More information about the Patchwork mailing list