mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
Add tests for searching on the Page model
This commit is contained in:
parent
dd54f5bdca
commit
2e44dc3c8e
1 changed files with 46 additions and 0 deletions
46
wagtail/wagtailsearch/tests/test_page_search.py
Normal file
46
wagtail/wagtailsearch/tests/test_page_search.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from wagtail.wagtailcore.models import Page
|
||||
from wagtail.wagtailsearch.backends import get_search_backend
|
||||
|
||||
|
||||
class PageSearchTests(object):
|
||||
# A TestCase with this class mixed in will be dynamically created
|
||||
# for each search backend defined in WAGTAILSEARCH_BACKENDS, with the backend name available
|
||||
# as self.backend_name
|
||||
|
||||
fixtures = ['test.json']
|
||||
|
||||
def setUp(self):
|
||||
self.backend = get_search_backend(self.backend_name)
|
||||
self.reset_index()
|
||||
for page in Page.objects.all():
|
||||
self.backend.add(page)
|
||||
self.refresh_index()
|
||||
|
||||
def reset_index(self):
|
||||
if self.backend.rebuilder_class:
|
||||
index = self.backend.get_index_for_model(Page)
|
||||
rebuilder = self.backend.rebuilder_class(index)
|
||||
index = rebuilder.start()
|
||||
index.add_model(Page)
|
||||
rebuilder.finish()
|
||||
|
||||
def refresh_index(self):
|
||||
index = self.backend.get_index_for_model(Page)
|
||||
if index:
|
||||
index.refresh()
|
||||
|
||||
def test_search_specific_queryset(self):
|
||||
list(Page.objects.specific().search('bread', backend=self.backend_name))
|
||||
|
||||
def test_search_specific_queryset_with_fields(self):
|
||||
list(Page.objects.specific().search('bread', fields=['title'], backend=self.backend_name))
|
||||
|
||||
|
||||
for backend_name in settings.WAGTAILSEARCH_BACKENDS.keys():
|
||||
test_name = str("Test%sBackend" % backend_name.title())
|
||||
globals()[test_name] = type(test_name, (PageSearchTests, TestCase,), {'backend_name': backend_name})
|
||||
Loading…
Reference in a new issue