|
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
|
@@ -435,7 +454,7 @@ class SearchListView(generics.ListAPIView):
|
435 | 454 | search_fields = ('=name', 'entry__headline', '=entry__pub_date__year')
|
436 | 455 |
|
437 | 456 | view = SearchListView.as_view()
|
438 |
| - request = factory.get('/', {'search': 'Lennon 1979'}) |
| 457 | + request = factory.get('/', {'search': 'Lennon,1979'}) |
439 | 458 | response = view(request)
|
440 | 459 | assert len(response.data) == 1
|
441 | 460 |
|
|
0 commit comments