-
Notifications
You must be signed in to change notification settings - Fork 192
/
test_search.py
52 lines (40 loc) · 2.24 KB
/
test_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- 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
from djangocms_blog.models import Post
from .base import BaseTest
class BlogIndexingTests(BaseTest):
def setUp(self):
self.get_pages()
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')
post.tags.add('a tag')
add_plugin(post.content, 'Text', 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(post.get_absolute_url(), indexed['url'])
#self.assertEqual(post.date_published.strftime("%Y-%m-%d %H:%M:%S"), indexed['pub_date'])
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(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(post.get_absolute_url(), indexed['url'])
#self.assertEqual(post.date_published.strftime("%Y-%m-%d %H:%M:%S"), indexed['pub_date'])
def test_searchqueryset(self):
posts = self.get_posts()
all_results = SearchQuerySet().models(Post)
self.assertEqual(len(posts), len(all_results))