Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0f4947
commit 2a69ced
Showing
3 changed files
with
78 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
import ckan.model as model | ||
import ckan.tests.factories as factories | ||
import ckan.tests.helpers as helpers | ||
from ckan.cli.cli import ckan | ||
|
||
|
||
@pytest.mark.usefixtures(u"clean_db", u"clean_index") | ||
class TestSearchIndex(object): | ||
def test_search_index_rebuild(self, cli): | ||
"""Direct update on package won't be reflected in search results till | ||
re-index. | ||
""" | ||
dataset = factories.Dataset(title=u"Before rebuild") | ||
model.Session.query(model.Package).filter_by(id=dataset[u'id']).update( | ||
{u'title': u'After update'}) | ||
model.Session.commit() | ||
|
||
search_result = helpers.call_action(u'package_search', q=u"After") | ||
assert search_result[u'count'] == 0 | ||
|
||
result = cli.invoke(ckan, [u'search-index', u'rebuild']) | ||
assert not result.exit_code | ||
search_result = helpers.call_action(u'package_search', q=u"After") | ||
assert search_result[u'count'] == 1 | ||
|
||
def test_test_main_operations(self, cli): | ||
"""Create few datasets, clear index, rebuild it - make sure search results | ||
are always reflect correct state of index. | ||
""" | ||
# Create two datasets and check if they are available in search results | ||
dataset = factories.Dataset(title=u"First package") | ||
another_dataset = factories.Dataset(title=u"Second package") | ||
search_result = helpers.call_action(u'package_search', q=u"package") | ||
assert search_result[u'count'] == 2 | ||
|
||
# Remove one dataset | ||
result = cli.invoke(ckan, [u'search-index', u'clear', dataset[u'id']]) | ||
assert not result.exit_code | ||
search_result = helpers.call_action(u'package_search', q=u"package") | ||
assert search_result[u'count'] == 1 | ||
|
||
# Rebuild index and make sure all dataset are there | ||
result = cli.invoke(ckan, | ||
[u'search-index', u'rebuild']) | ||
assert not result.exit_code | ||
search_result = helpers.call_action(u'package_search', q=u"package") | ||
assert search_result[u'count'] == 2 | ||
|
||
# Remove one package from index and test `check` tool | ||
result = cli.invoke(ckan, [u'search-index', u'clear', another_dataset[u'id']]) | ||
result = cli.invoke(ckan, [u'search-index', u'check']) | ||
assert not result.exit_code | ||
assert u'1 out of 2' in result.output | ||
search_result = helpers.call_action(u'package_search', q=u"package") | ||
assert search_result[u'count'] == 1 | ||
|
||
# One can view data from index using CLI | ||
result = cli.invoke(ckan, [u'search-index', u'show', dataset[u'id']]) | ||
assert not result.exit_code | ||
assert u'First package' in result.output | ||
assert u'Second package' not in result.output | ||
|
||
# Only search index is checked, not actual data in DB | ||
result = cli.invoke(ckan, | ||
[u'search-index', u'show', another_dataset[u'id']]) | ||
assert result.exit_code | ||
|
||
result = cli.invoke(ckan, [u'search-index', u'rebuild', u'-o']) | ||
assert not result.exit_code | ||
search_result = helpers.call_action(u'package_search', q=u"package") | ||
assert search_result[u'count'] == 2 |
This file was deleted.
Oops, something went wrong.