2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# -*- coding: utf-8 -*-
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from __future__ import absolute_import, print_function, unicode_literals
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-25 21:34:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from cms.api import add_plugin
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-20 19:27:48 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from haystack.constants import DEFAULT_ALIAS
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from haystack.query import SearchQuerySet
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-20 19:52:42 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from djangocms_blog.models import Post
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-19 23:26:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-20 19:34:53 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								from .base import BaseTest
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-19 22:27:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class BlogIndexingTests(BaseTest):
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-17 10:22:26 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sample_text = ('First post first line This is the description keyword1  '
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-25 21:34:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                   'keyword2 category 1 a tag test body')
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    def setUp(self):
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-20 19:52:42 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.get_pages()
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    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')
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-25 21:34:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        post.tags.add('a tag')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        add_plugin(post.content, 'TextPlugin', language='en', body='test body')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        index = self.get_post_index()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        index.index_queryset(DEFAULT_ALIAS)  # initialises index._backend_alias
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        indexed = index.prepare(post)
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-19 09:50:39 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-16 12:54:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(post.get_title(), indexed['title'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(post.get_description(), indexed['description'])
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-15 18:06:04 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(post.get_tags(), indexed['tags'])
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-25 21:34:38 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(self.sample_text, indexed['text'])
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-16 12:54:55 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(post.get_absolute_url(), indexed['url'])
							 | 
						
					
						
							
								
									
										
										
										
											2016-02-15 18:06:04 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(post.date_published, indexed['pub_date'])
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-15 22:29:32 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-19 23:26:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    def test_searchqueryset(self):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        posts = self.get_posts()
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-20 19:52:42 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        all_results = SearchQuerySet().models(Post)
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-19 23:26:05 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        self.assertEqual(len(posts), len(all_results))
							 |