Improve coverage
This commit is contained in:
parent
e43b15c0b7
commit
b6d0d82f00
2 changed files with 14 additions and 6 deletions
|
@ -17,8 +17,6 @@ class PostIndex(get_index_base()):
|
|||
keywords = indexes.CharField(null=True)
|
||||
tags = indexes.CharField(null=True)
|
||||
post_text = indexes.CharField(null=True)
|
||||
# category_ids = indexes.MultiValueField(null=True)
|
||||
# category_titles = indexes.MultiValueField(null=True)
|
||||
|
||||
def get_keywords(self, post):
|
||||
return ','.join(post.get_keywords())
|
||||
|
@ -54,7 +52,7 @@ class PostIndex(get_index_base()):
|
|||
text_bits = [post.get_title()]
|
||||
text_bits.append(strip_tags(abstract))
|
||||
text_bits.append(post.get_description())
|
||||
# text_bits.append(' '.join(post.get_keywords()))
|
||||
text_bits.append(' '.join(post.get_keywords()))
|
||||
for category in post.categories.all():
|
||||
text_bits.append(
|
||||
force_text(category.safe_translation_getter('name')))
|
||||
|
@ -64,7 +62,7 @@ class PostIndex(get_index_base()):
|
|||
plugins = post.content.cmsplugin_set.filter(language=language)
|
||||
for base_plugin in plugins:
|
||||
content = get_plugin_index_data(base_plugin, request)
|
||||
text_bits.append(content)
|
||||
text_bits.append(' '.join(content))
|
||||
for attribute in optional_attributes:
|
||||
value = force_text(getattr(post, attribute))
|
||||
if value and value not in text_bits:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
from cms.api import add_plugin
|
||||
from haystack.constants import DEFAULT_ALIAS
|
||||
from haystack.query import SearchQuerySet
|
||||
|
||||
|
@ -10,6 +11,8 @@ from .base import BaseTest
|
|||
|
||||
|
||||
class BlogIndexingTests(BaseTest):
|
||||
sample_text = ('First post First post first line This is the description keyword1 '
|
||||
'keyword2 category 1 a tag test body')
|
||||
|
||||
def setUp(self):
|
||||
self.get_pages()
|
||||
|
@ -18,13 +21,17 @@ class BlogIndexingTests(BaseTest):
|
|||
"""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')
|
||||
post.tags.add('a tag')
|
||||
add_plugin(post.content, 'TextPlugin', language='en', body='test body')
|
||||
|
||||
index = self.get_post_index()
|
||||
index.index_queryset(DEFAULT_ALIAS) # initialises index._backend_alias
|
||||
indexed = index.prepare(post)
|
||||
|
||||
|
||||
self.assertEqual(post.get_title(), indexed['title'])
|
||||
self.assertEqual(post.get_description(), indexed['description'])
|
||||
self.assertEqual('First post First post first line This is the description category 1', indexed['text'])
|
||||
self.assertEqual(self.sample_text, indexed['text'])
|
||||
self.assertEqual(post.get_absolute_url(), indexed['url'])
|
||||
#self.assertEqual(post.date_published.strftime("%Y-%m-%d %H:%M:%S"), indexed['pub_date'])
|
||||
|
||||
|
@ -32,13 +39,16 @@ class BlogIndexingTests(BaseTest):
|
|||
"""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')
|
||||
post.tags.add('a tag')
|
||||
add_plugin(post.content, 'TextPlugin', language='en', body='test body')
|
||||
|
||||
index = self.get_post_index()
|
||||
index.update_object(post, using=DEFAULT_ALIAS)
|
||||
indexed = index.prepared_data
|
||||
|
||||
self.assertEqual(post.get_title(), indexed['title'])
|
||||
self.assertEqual(post.get_description(), indexed['description'])
|
||||
self.assertEqual('First post First post first line This is the description category 1', indexed['text'])
|
||||
self.assertEqual(self.sample_text, indexed['text'])
|
||||
self.assertEqual(post.get_absolute_url(), indexed['url'])
|
||||
#self.assertEqual(post.date_published.strftime("%Y-%m-%d %H:%M:%S"), indexed['pub_date'])
|
||||
|
||||
|
|
Loading…
Reference in a new issue