mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 01:03:11 +00:00
Added tests for indexed class
This commit is contained in:
parent
f02a6937d2
commit
04c507e37b
2 changed files with 77 additions and 0 deletions
|
|
@ -346,3 +346,31 @@ class SearchTestChild(SearchTest):
|
|||
indexed.SearchField('subtitle', partial_match=True),
|
||||
indexed.SearchField('extra_content'),
|
||||
]
|
||||
|
||||
|
||||
class SearchTestOldConfig(models.Model, indexed.Indexed):
|
||||
"""
|
||||
This tests that the Indexed class can correctly handle models that
|
||||
use the old "indexed_fields" configuration format.
|
||||
"""
|
||||
indexed_fields = {
|
||||
# A search field with predictive search and boosting
|
||||
'title': {
|
||||
'type': 'string',
|
||||
'analyzer': 'edgengram_analyzer',
|
||||
'boost': 100,
|
||||
},
|
||||
|
||||
# A filter field
|
||||
'live': {
|
||||
'type': 'boolean',
|
||||
'index': 'not_analyzed',
|
||||
},
|
||||
}
|
||||
|
||||
class SearchTestOldConfigList(models.Model, indexed.Indexed):
|
||||
"""
|
||||
This tests that the Indexed class can correctly handle models that
|
||||
use the old "indexed_fields" configuration format using a list.
|
||||
"""
|
||||
indexed_fields = ['title', 'content']
|
||||
|
|
|
|||
49
wagtail/wagtailsearch/tests/test_indexed_class.py
Normal file
49
wagtail/wagtailsearch/tests/test_indexed_class.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
from django.test import TestCase
|
||||
from wagtail.tests import models
|
||||
import json
|
||||
|
||||
from wagtail.wagtailsearch import indexed
|
||||
|
||||
|
||||
class TestContentTypeNames(TestCase):
|
||||
def test_base_content_type_name(self):
|
||||
name = models.SearchTestChild.indexed_get_toplevel_content_type()
|
||||
self.assertEqual(name, 'tests_searchtest')
|
||||
|
||||
def test_qualified_content_type_name(self):
|
||||
name = models.SearchTestChild.indexed_get_content_type()
|
||||
self.assertEqual(name, 'tests_searchtest_tests_searchtestchild')
|
||||
|
||||
|
||||
class TestIndexedFieldsBackwardsCompatibility(TestCase):
|
||||
def test_indexed_fields_backwards_compatibility(self):
|
||||
# Get search fields
|
||||
search_fields = models.SearchTestOldConfig.get_search_fields()
|
||||
|
||||
search_fields_dict = dict(
|
||||
((field.field_name, type(field)), field)
|
||||
for field in search_fields
|
||||
)
|
||||
|
||||
# Check that the fields were found
|
||||
self.assertEqual(len(search_fields_dict), 2)
|
||||
self.assertIn(('title', indexed.SearchField), search_fields_dict.keys())
|
||||
self.assertIn(('live', indexed.FilterField), search_fields_dict.keys())
|
||||
|
||||
# Check that the title field has the correct settings
|
||||
self.assertTrue(search_fields_dict[('title', indexed.SearchField)].partial_match)
|
||||
self.assertEqual(search_fields_dict[('title', indexed.SearchField)].boost, 100)
|
||||
|
||||
def test_indexed_fields_backwards_compatibility_list(self):
|
||||
# Get search fields
|
||||
search_fields = models.SearchTestOldConfigList.get_search_fields()
|
||||
|
||||
search_fields_dict = dict(
|
||||
((field.field_name, type(field)), field)
|
||||
for field in search_fields
|
||||
)
|
||||
|
||||
# Check that the fields were found
|
||||
self.assertEqual(len(search_fields_dict), 2)
|
||||
self.assertIn(('title', indexed.SearchField), search_fields_dict.keys())
|
||||
self.assertIn(('content', indexed.SearchField), search_fields_dict.keys())
|
||||
Loading…
Reference in a new issue