Since we display the name of the state in the serialized patch, also
filter by name instead of primary key.
Also this will be consistent with the current documentation examples
(curl 'https://patchwork.example.com/api/patches?state=under-review')
Signed-off-by: Philippe Pepiot <philippe.pepiot@logilab.fr>
Reviewed-by: Stephen Finucane <stephen@that.guru>
from django_filters import FilterSet
from django_filters import IsoDateTimeFilter
+from django_filters import CharFilter
from patchwork.compat import LOOKUP_FIELD
from patchwork.models import Bundle
class PatchFilter(FilterSet):
+ # TODO(stephenfin): We should probably be using a ChoiceFilter here?
+ state = CharFilter(name='state__name')
+
class Meta:
model = Patch
fields = ('project', 'series', 'submitter', 'delegate', 'state',
self.assertNotIn('content', patch_rsp)
self.assertNotIn('diff', patch_rsp)
+ # test filtering by state
+ other_state = create_state()
+ resp = self.client.get(self.api_url(), {'state': patch_obj.state.name})
+ self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])
+ resp = self.client.get(self.api_url(), {'state': other_state.name})
+ self.assertEqual(0, len(resp.data))
+
# authenticated user
user = create_user()
self.client.force_authenticate(user=user)