Skip to content

Commit

Permalink
[#2199] Add tests for translation of dataset search pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Mar 7, 2012
1 parent fa53aa2 commit 5623959
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
18 changes: 0 additions & 18 deletions ckan/lib/create_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,6 @@ def create_translations_test_data(cls):
ckan.logic.action.update.term_translation_update(context,
data_dict)

# Add translation terms that match a couple of group names and package
# names. Group names and package names should _not_ get translated even
# if there are terms matching them, because they are used to form URLs.
for term in ('roger', 'david', 'annakarenina', 'warandpeace'):
for lang_code in ('en', 'de', 'fr'):
data_dict = {
'term': term,
'term_translation': 'this should not be rendered',
'lang_code': lang_code,
}
context = {
'model': ckan.model,
'session': ckan.model.Session,
'user': 'testsysadmin',
}
ckan.logic.action.update.term_translation_update(context,
data_dict)

ckan.model.Session.commit()

@classmethod
Expand Down
6 changes: 5 additions & 1 deletion ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ def package_search(context, data_dict):
for key_, value_ in value.items():
new_facet_dict = {}
new_facet_dict['name'] = key_
new_facet_dict['display_name'] = key_
if key == 'groups':
new_facet_dict['display_name'] = (
model.Group.get(key_).display_name)
else:
new_facet_dict['display_name'] = key_
new_facet_dict['count'] = value_
restructured_facets[key]['items'].append(new_facet_dict)
search_results['facets'] = restructured_facets
Expand Down
51 changes: 49 additions & 2 deletions ckanext/multilingual/tests/test_multilingual_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ckan.lib.helpers
import ckan.lib.create_test_data
import ckan.logic.action.update
import ckan.tests
import ckan.tests.html_check
import routes
import paste.fixture
Expand All @@ -16,11 +17,30 @@ class TestDatasetTermTranslation(ckan.tests.html_check.HtmlCheckMethods):
def setup(cls):
cls.app = paste.fixture.TestApp(pylons.test.pylonsapp)
ckan.plugins.load('multilingual_dataset')
ckan.tests.setup_test_search_index()
ckan.lib.create_test_data.CreateTestData.create_translations_test_data()
# Add translation terms that match a couple of group names and package
# names. Group names and package names should _not_ get translated even
# if there are terms matching them, because they are used to form URLs.
for term in ('roger', 'david', 'annakarenina', 'warandpeace'):
for lang_code in ('en', 'de', 'fr'):
data_dict = {
'term': term,
'term_translation': 'this should not be rendered',
'lang_code': lang_code,
}
context = {
'model': ckan.model,
'session': ckan.model.Session,
'user': 'testsysadmin',
}
ckan.logic.action.update.term_translation_update(context,
data_dict)

@classmethod
def teardown(cls):
ckan.model.repo.rebuild_db()
ckan.lib.search.clear()

def test_dataset_view_translation(self):
'''Test the translation of dataset view pages by the
Expand All @@ -33,7 +53,9 @@ def test_dataset_view_translation(self):
id='annakarenina')
for (lang_code, translations) in (
('de', ckan.lib.create_test_data.german_translations),
('fr', ckan.lib.create_test_data.french_translations), ('pl', {})):
('fr', ckan.lib.create_test_data.french_translations),
('en', ckan.lib.create_test_data.english_translations),
('pl', {})):
response = self.app.get(offset, status=200,
extra_environ={'CKAN_LANG': lang_code,
'CKAN_CURRENT_URL': offset})
Expand All @@ -42,7 +64,7 @@ def test_dataset_view_translation(self):
response.mustcontain(translations[term])
elif term in ckan.lib.create_test_data.english_translations:
response.mustcontain(
ckan.lib.create_test_data.english_translations[term])
ckan.lib.create_test_data.english_translations[term])
else:
response.mustcontain(term)
for tag_name in ('123', '456', '789', 'russian', 'tolstoy'):
Expand All @@ -51,3 +73,28 @@ def test_dataset_view_translation(self):
response.mustcontain('<a href="/group/%s">' % group_name)
nose.tools.assert_raises(IndexError, response.mustcontain,
'this should not be rendered')

@ckan.tests.search_related
def test_dataset_search_results_translation(self):
for (lang_code, translations) in (
('de', ckan.lib.create_test_data.german_translations),
('fr', ckan.lib.create_test_data.french_translations),
('en', ckan.lib.create_test_data.english_translations),
('pl', {})):
offset = '/%s/dataset' % lang_code
response = self.app.get(offset, status=200)
for term in ('Index of the novel', 'russian', 'tolstoy',
"Dave's books", "Roger's books", 'plain text'):
if term in translations:
response.mustcontain(translations[term])
elif term in ckan.lib.create_test_data.english_translations:
response.mustcontain(
ckan.lib.create_test_data.english_translations[term])
else:
response.mustcontain(term)
for tag_name in ('123', '456', '789', 'russian', 'tolstoy'):
response.mustcontain('/%s/dataset?tags=%s' % (lang_code, tag_name))
for group_name in ('david', 'roger'):
response.mustcontain('/%s/dataset?groups=%s' % (lang_code, group_name))
nose.tools.assert_raises(IndexError, response.mustcontain,
'this should not be rendered')

0 comments on commit 5623959

Please sign in to comment.