diff options
| author | Alix <alix@spacefoot.com> | 2020-05-26 17:53:18 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-18 20:17:20 +0200 |
| commit | 26a413507abb38f7eee4cf62f2ee9727fdc7bf8d (patch) | |
| tree | cda26a7382c5158bbad510ccc7b80612f921d0ad /tests/admin_views | |
| parent | 8a902b7ee622ada258d15fb122092c1f02b82698 (diff) | |
Fixed #6933 -- Added support for searching against quoted phrases in ModelAdmin.search_fields.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/tests.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 3094ad43a4..4d3fade3c9 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -3439,6 +3439,8 @@ class AdminSearchTest(TestCase): cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True) cls.per2 = Person.objects.create(name='Grace Hopper', gender=1, alive=False) cls.per3 = Person.objects.create(name='Guido van Rossum', gender=1, alive=True) + Person.objects.create(name='John Doe', gender=1) + Person.objects.create(name="John O'Hara", gender=1) cls.t1 = Recommender.objects.create() cls.t2 = Recommendation.objects.create(the_recommender=cls.t1) @@ -3513,7 +3515,7 @@ class AdminSearchTest(TestCase): response = self.client.get(reverse('admin:admin_views_person_changelist') + '?q=Gui') self.assertContains( response, - """<span class="small quiet">1 result (<a href="?">3 total</a>)</span>""", + """<span class="small quiet">1 result (<a href="?">5 total</a>)</span>""", html=True ) @@ -3533,6 +3535,24 @@ class AdminSearchTest(TestCase): ) self.assertTrue(response.context['cl'].show_admin_actions) + def test_search_with_spaces(self): + url = reverse('admin:admin_views_person_changelist') + '?q=%s' + tests = [ + ('"John Doe"', 1), + ("'John Doe'", 1), + ('John Doe', 0), + ('"John Doe" John', 1), + ("'John Doe' John", 1), + ("John Doe John", 0), + ('"John Do"', 1), + ("'John Do'", 1), + ("'John O\\'Hara'", 1), + ] + for search, hits in tests: + with self.subTest(search=search): + response = self.client.get(url % search) + self.assertContains(response, '\n%s person' % hits) + @override_settings(ROOT_URLCONF='admin_views.urls') class AdminInheritedInlinesTest(TestCase): |
