mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 21:14:01 +03:00
Test for regex search filter
This commit is contained in:
parent
314daaedfa
commit
21d0e51831
|
@ -407,6 +407,23 @@ class SearchFilterTests(TestCase):
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_regexp_search(self):
|
||||||
|
class SearchListView(generics.ListAPIView):
|
||||||
|
queryset = SearchFilterModel.objects.all()
|
||||||
|
serializer_class = SearchFilterSerializer
|
||||||
|
filter_backends = (filters.SearchFilter,)
|
||||||
|
search_fields = ('$title', '$text')
|
||||||
|
|
||||||
|
view = SearchListView.as_view()
|
||||||
|
request = factory.get('/', {'search': 'z{2} ^b'})
|
||||||
|
response = view(request)
|
||||||
|
self.assertEqual(
|
||||||
|
response.data,
|
||||||
|
[
|
||||||
|
{'id': 2, 'title': 'zz', 'text': 'bcd'}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
def test_search_with_nonstandard_search_param(self):
|
def test_search_with_nonstandard_search_param(self):
|
||||||
with override_settings(REST_FRAMEWORK={'SEARCH_PARAM': 'query'}):
|
with override_settings(REST_FRAMEWORK={'SEARCH_PARAM': 'query'}):
|
||||||
reload_module(filters)
|
reload_module(filters)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user