This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from czpython/feature/search-tests
adds search tests
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.utils.timezone import now | ||
from django.utils.translation import activate | ||
|
||
from aldryn_newsblog.models import Article | ||
from aldryn_newsblog.search_indexes import ArticleIndex | ||
|
||
from . import NewsBlogTestCase | ||
|
||
|
||
class ArticleIndexingTests(NewsBlogTestCase): | ||
|
||
def get_index(self): | ||
from haystack.constants import DEFAULT_ALIAS | ||
|
||
index = ArticleIndex() | ||
index._backend_alias = DEFAULT_ALIAS | ||
return index | ||
|
||
def test_article_is_indexed_using_prepare(self): | ||
activate(self.language) | ||
|
||
lead_in = 'Hello! this text will be searchable.' | ||
|
||
article = self.create_article(lead_in=lead_in) | ||
|
||
index = self.get_index() | ||
|
||
data = index.prepare(article) | ||
|
||
count = data['text'].count(lead_in) | ||
|
||
self.assertTrue(count != 0, "Couldn't find %s in text" % lead_in) | ||
|
||
def test_translated_article_is_indexed_using_prepare(self): | ||
activate(self.language) | ||
|
||
lead_in = 'Hello! this text will be searchable.' | ||
|
||
# create english article | ||
article = self.create_article(lead_in=lead_in) | ||
|
||
# create german translation for article | ||
article.set_current_language('de') | ||
article.title = '%s [de]' % self.rand_str() | ||
article.save() | ||
|
||
index = self.get_index() | ||
|
||
data = index.prepare(article) | ||
|
||
self.assertEquals(data['language'], 'de') | ||
self.assertEquals(data['url'], article.get_absolute_url('de')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters