Update index and settings
This commit is contained in:
parent
2d1eb62964
commit
a02a3d1c3c
4 changed files with 68 additions and 4 deletions
|
|
@ -7,6 +7,8 @@ from cmsplugin_filer_image.models import ThumbnailOption
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.sites.models import Site
|
||||
from djangocms_helper.base_test import BaseTestCase
|
||||
from haystack import connections
|
||||
from haystack.constants import DEFAULT_ALIAS
|
||||
from parler.utils.context import smart_override
|
||||
|
||||
from djangocms_blog.cms_appconfig import BlogConfig
|
||||
|
|
@ -183,3 +185,9 @@ class BaseTest(BaseTestCase):
|
|||
post1.save()
|
||||
posts.append(post1)
|
||||
return posts
|
||||
|
||||
def get_post_index(self):
|
||||
search_conn = connections[DEFAULT_ALIAS]
|
||||
unified_index = search_conn.get_unified_index()
|
||||
index = unified_index.get_index(Post)
|
||||
return index
|
||||
|
|
|
|||
39
tests/test_search.py
Normal file
39
tests/test_search.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from djangocms_blog.search_indexes import PostIndex
|
||||
from . import BaseTest
|
||||
|
||||
from haystack.constants import DEFAULT_ALIAS
|
||||
|
||||
|
||||
class PluginIndexingTests(BaseTest):
|
||||
|
||||
def setUp(self):
|
||||
self.index = PostIndex()
|
||||
|
||||
def test_blog_post_is_indexed_using_prepare(self):
|
||||
"""This tests the indexing path way used by update_index mgmt command"""
|
||||
post = self._get_post(self._post_data[0]['en'])
|
||||
post = self._get_post(self._post_data[0]['it'], post, 'it')
|
||||
index = self.get_post_index()
|
||||
index.index_queryset(DEFAULT_ALIAS) # initialises index._backend_alias
|
||||
indexed = index.prepare(post)
|
||||
print(indexed)
|
||||
self.assertEqual('First post', indexed['title'])
|
||||
self.assertEqual('This is the description', indexed['description'])
|
||||
self.assertEqual('First post first line This is the description category 1', indexed['text'])
|
||||
self.assertEqual('/en/page-two/2015/10/15/first-post/', indexed['url'])
|
||||
|
||||
def test_blog_post_is_indexed_using_update_object(self):
|
||||
"""This tests the indexing path way used by the RealTimeSignalProcessor"""
|
||||
post = self._get_post(self._post_data[0]['en'])
|
||||
post = self._get_post(self._post_data[0]['it'], post, 'it')
|
||||
index = self.get_post_index()
|
||||
index.update_object(post, using=DEFAULT_ALIAS)
|
||||
indexed = index.prepared_data
|
||||
self.assertEqual('First post', indexed['title'])
|
||||
self.assertEqual('This is the description', indexed['description'])
|
||||
self.assertEqual('First post first line This is the description category 1', indexed['text'])
|
||||
self.assertEqual('/en/page-two/2015/10/15/first-post/', indexed['url'])
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue