|
6 | 6 | from django.db import models
|
7 | 7 | from django.db.models import CharField, Transform
|
8 | 8 | from django.db.models.functions import Concat, Upper
|
9 |
| -from django.test import TestCase |
| 9 | +from django.test import SimpleTestCase, TestCase |
10 | 10 | from django.test.utils import override_settings
|
11 | 11 |
|
12 | 12 | from rest_framework import filters, generics, serializers
|
|
17 | 17 | factory = APIRequestFactory()
|
18 | 18 |
|
19 | 19 |
|
| 20 | +class SearchSplitTests(SimpleTestCase): |
| 21 | + |
| 22 | + def test_keep_quoted_togheter_regardless_of_commas(self): |
| 23 | + assert ['hello, world'] == list(filters.search_smart_split('"hello, world"')) |
| 24 | + |
| 25 | + def test_strips_commas_around_quoted(self): |
| 26 | + assert ['hello, world'] == list(filters.search_smart_split(',,"hello, world"')) |
| 27 | + assert ['hello, world'] == list(filters.search_smart_split(',,"hello, world",,')) |
| 28 | + assert ['hello, world'] == list(filters.search_smart_split('"hello, world",,')) |
| 29 | + |
| 30 | + def test_splits_by_comma(self): |
| 31 | + assert ['hello', 'world'] == list(filters.search_smart_split(',,hello, world')) |
| 32 | + assert ['hello', 'world'] == list(filters.search_smart_split(',,hello, world,,')) |
| 33 | + assert ['hello', 'world'] == list(filters.search_smart_split('hello, world,,')) |
| 34 | + |
| 35 | + def test_splits_quotes_followed_by_comma_and_sentence(self): |
| 36 | + assert ['"hello', 'world"', 'found'] == list(filters.search_smart_split('"hello, world",found')) |
| 37 | + |
| 38 | + |
20 | 39 | class BaseFilterTests(TestCase):
|
21 | 40 | def setUp(self):
|
22 | 41 | self.original_coreapi = filters.coreapi
|
@@ -418,7 +437,7 @@ class SearchListView(generics.ListAPIView):
|
418 | 437 | search_fields = ('=name', 'entry__headline', '=entry__pub_date__year')
|
419 | 438 |
|
420 | 439 | view = SearchListView.as_view()
|
421 |
| - request = factory.get('/', {'search': 'Lennon 1979'}) |
| 440 | + request = factory.get('/', {'search': 'Lennon,1979'}) |
422 | 441 | response = view(request)
|
423 | 442 | assert len(response.data) == 1
|
424 | 443 |
|
|
0 commit comments