Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Making sure the author API is properly filtered
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sinchok committed Sep 23, 2014
1 parent 2a53bda commit 7415633
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bulbs/api/views.py
Expand Up @@ -270,6 +270,8 @@ class AuthorViewSet(UncachedResponse, viewsets.ReadOnlyModelViewSet):

serializer_class = UserSerializer
model = User
filter_backends = (filters.SearchFilter, filters.OrderingFilter)
search_fields = ("first_name", "last_name", "username")

def get_queryset(self):
author_filter = getattr(settings, "BULBS_AUTHOR_FILTER", Q(is_staff=True))
Expand Down
6 changes: 6 additions & 0 deletions tests/api/test_author_api.py
Expand Up @@ -45,3 +45,9 @@ def test_author_search(self):
author_endpoint = reverse("author-list")
response = client.get(author_endpoint, content_type="application/json")
self.assertEqual(len(response.data), 5)

response = client.get(author_endpoint, {"search": "chris"}, content_type="application/json")
self.assertEqual(len(response.data), 1)

response = client.get(author_endpoint, {"search": "ok"}, content_type="application/json")
self.assertEqual(len(response.data), 2)

0 comments on commit 7415633

Please sign in to comment.