[PATCH v4 4/4] /api/events: Allow filtering by 'actor' field

Stephen Finucane stephen at that.guru
Sun Dec 1 23:14:51 AEDT 2019


On Sun, 2019-12-01 at 02:49 +0100, Johan Herland wrote:
> Cc: Mauro Carvalho Chehab <mchehab+samsung at kernel.org>
> Suggested-by: Stephen Finucane <stephen at that.guru>
> Signed-off-by: Johan Herland <johan at herland.net>

Squashed with patch 3, but...

Reviewed-by: Stephen Finucane <stephen at that.guru>

> ---
>  patchwork/api/filters.py          |  5 ++++-
>  patchwork/tests/api/test_event.py | 22 ++++++++++++++++++++++
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py
> index 6b4d84c..60f1a36 100644
> --- a/patchwork/api/filters.py
> +++ b/patchwork/api/filters.py
> @@ -236,7 +236,10 @@ class EventFilterSet(TimestampMixin, BaseFilterSet):
>  
>      class Meta:
>          model = Event
> -        fields = ('project', 'category', 'series', 'patch', 'cover')
> +        fields = ('project', 'category', 'series', 'patch', 'cover', 'actor')
> +        versioned_fields = {
> +            '1.2': ('actor', ),
> +        }
>  
>  
>  class BundleFilterSet(BaseFilterSet):
> diff --git a/patchwork/tests/api/test_event.py b/patchwork/tests/api/test_event.py
> index 456f2f5..e86e170 100644
> --- a/patchwork/tests/api/test_event.py
> +++ b/patchwork/tests/api/test_event.py
> @@ -156,6 +156,28 @@ class TestEventAPI(utils.APITestCase):
>          resp = self.client.get(self.api_url(), {'series': 999999})
>          self.assertEqual(0, len(resp.data))
>  
> +    def test_list_filter_actor(self):
> +        """Filter events by actor."""
> +        events = self._create_events()
> +
> +        # The final two events (patch-delegated, patch-state-changed)
> +        # have an actor set
> +        actor = events[0].actor
> +        resp = self.client.get(self.api_url(), {'actor': actor.pk})
> +        self.assertEqual(2, len(resp.data))
> +
> +        resp = self.client.get(self.api_url(), {'actor': 'foo-bar'})
> +        self.assertEqual(0, len(resp.data))
> +
> +    def test_list_filter_actor_version_1_1(self):
> +        """Filter events by actor using API v1.1."""
> +        events = self._create_events()
> +
> +        # we still see all the events since the actor field is ignored
> +        resp = self.client.get(self.api_url(version='1.1'),
> +                               {'actor': 'foo-bar'})
> +        self.assertEqual(len(events), len(resp.data))
> +
>      def test_order_by_date_default(self):
>          """Assert the default ordering is by date descending."""
>          self._create_events()



More information about the Patchwork mailing list