|
10 | 10 | from django.test.utils import override_settings
|
11 | 11 |
|
12 | 12 | from rest_framework import filters, generics, serializers
|
13 |
| -from rest_framework.compat import coreschema |
| 13 | +from rest_framework.compat import coreschema, postgres_fields |
14 | 14 | from rest_framework.exceptions import ValidationError
|
15 | 15 | from rest_framework.test import APIRequestFactory
|
16 | 16 |
|
@@ -305,6 +305,25 @@ class SearchListView(generics.ListAPIView):
|
305 | 305 | ]
|
306 | 306 |
|
307 | 307 |
|
| 308 | +@pytest.mark.skipif(not postgres_fields, reason='psycopg2 is not installed') |
| 309 | +class SearchPostgreSQLFilterTests(TestCase): |
| 310 | + |
| 311 | + def test_unaccent_search(self): |
| 312 | + class SearchListView(generics.ListAPIView): |
| 313 | + queryset = SearchFilterModel.objects.all() |
| 314 | + serializer_class = SearchFilterSerializer |
| 315 | + filter_backends = (filters.SearchFilter,) |
| 316 | + search_fields = ('title', '&text') |
| 317 | + |
| 318 | + obj = SearchFilterModel.objects.create(title='Accent títle', text='Accent téxt') |
| 319 | + view = SearchListView.as_view() |
| 320 | + request = factory.get('/', {'search': 'accent text'}) |
| 321 | + response = view(request) |
| 322 | + assert response.data == [ |
| 323 | + {'id': obj.id, 'title': 'Accent títle', 'text': 'Accent téxt'} |
| 324 | + ] |
| 325 | + |
| 326 | + |
308 | 327 | class AttributeModel(models.Model):
|
309 | 328 | label = models.CharField(max_length=32)
|
310 | 329 |
|
|
0 commit comments