Add tests for custom admin display titles in search results

pull/3794/merge
Matt Westcott 2017-10-06 00:19:19 +01:00
rodzic 4063573f9c
commit 09591fcf98
2 zmienionych plików z 27 dodań i 0 usunięć

Wyświetl plik

@ -258,6 +258,19 @@ class TestChooserSearch(TestCase, WagtailTestUtils):
self.assertContains(response, "There is one match")
self.assertContains(response, "foobarbaz")
def test_result_uses_custom_admin_display_title(self):
single_event_page = SingleEventPage(
title="Lunar event",
location='the moon', audience='public',
cost='free', date_from='2001-01-01',
)
self.root_page.add_child(instance=single_event_page)
response = self.get({'q': "lunar"})
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/chooser/_search_results.html')
self.assertContains(response, "Lunar event (single event)")
def test_search_no_results(self):
response = self.get({'q': "quux"})
self.assertEqual(response.status_code, 200)

Wyświetl plik

@ -2082,6 +2082,20 @@ class TestPageSearch(TestCase, WagtailTestUtils):
results = response.context['pages']
self.assertTrue(any([r.slug == 'root' for r in results]))
def test_search_uses_admin_display_title_from_specific_class(self):
# SingleEventPage has a custom get_admin_display_title method; explorer should
# show the custom title rather than the basic database one
root_page = Page.objects.get(id=2)
new_event = SingleEventPage(
title="Lunar event",
location='the moon', audience='public',
cost='free', date_from='2001-01-01',
latest_revision_created_at=local_datetime(2016, 1, 1)
)
root_page.add_child(instance=new_event)
response = self.get({'q': "lunar"})
self.assertContains(response, "Lunar event (single event)")
def test_search_no_perms(self):
self.user.is_superuser = False
self.user.user_permissions.add(