|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# This file is part of Invenio. |
| 4 | +# Copyright (C) 2008, 2010, 2011, 2013, 2015 CERN. |
| 5 | +# |
| 6 | +# Invenio is free software; you can redistribute it and/or |
| 7 | +# modify it under the terms of the GNU General Public License as |
| 8 | +# published by the Free Software Foundation; either version 2 of the |
| 9 | +# License, or (at your option) any later version. |
| 10 | +# |
| 11 | +# Invenio is distributed in the hope that it will be useful, but |
| 12 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | +# General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with Invenio; if not, write to the Free Software Foundation, Inc., |
| 18 | +# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 19 | + |
| 20 | +"""Unit tests for messages library.""" |
| 21 | + |
| 22 | +__revision__ = "$Id$" |
| 23 | + |
| 24 | +from invenio_base import i18n as messages |
| 25 | +from invenio_base.globals import cfg |
| 26 | +from invenio.testsuite import make_test_suite, run_test_suite, InvenioTestCase |
| 27 | + |
| 28 | + |
| 29 | +class MessagesLanguageTest(InvenioTestCase): |
| 30 | + """ |
| 31 | + Testing language-related functions |
| 32 | + """ |
| 33 | + |
| 34 | + def test_lang_list_long_ordering(self): |
| 35 | + """messages - preserving language order""" |
| 36 | + lang_list_long = messages.language_list_long() |
| 37 | + |
| 38 | + # Preliminary test: same number of languages in both lists |
| 39 | + self.assertEqual(len(lang_list_long), |
| 40 | + len(cfg['CFG_SITE_LANGS'])) |
| 41 | + |
| 42 | + |
| 43 | + for lang, cfg_lang in zip(lang_list_long, |
| 44 | + cfg['CFG_SITE_LANGS']): |
| 45 | + self.assertEqual(lang[0], |
| 46 | + cfg_lang) |
| 47 | + |
| 48 | + def test_wash_invalid_language(self): |
| 49 | + """messages - washing invalid language code""" |
| 50 | + self.assertEqual(messages.wash_language('python'), |
| 51 | + cfg['CFG_SITE_LANG']) |
| 52 | + |
| 53 | + def test_wash_dashed_language(self): |
| 54 | + """messages - washing dashed language code (fr-ca)""" |
| 55 | + if 'fr' not in cfg['CFG_SITE_LANGS']: |
| 56 | + self.assertEqual(messages.wash_language('fr-ca'), |
| 57 | + cfg['CFG_SITE_LANG']) |
| 58 | + else: |
| 59 | + self.assertEqual(messages.wash_language('fr-ca'), |
| 60 | + 'fr') |
| 61 | + |
| 62 | + def test_wash_languages(self): |
| 63 | + """messages - washing multiple languages""" |
| 64 | + if 'de' not in cfg['CFG_SITE_LANGS']: |
| 65 | + self.assertEqual(messages.wash_languages(['00', |
| 66 | + '11', |
| 67 | + '22', |
| 68 | + 'de']), |
| 69 | + cfg['CFG_SITE_LANG']) |
| 70 | + else: |
| 71 | + self.assertEqual(messages.wash_languages(['00', |
| 72 | + '11', |
| 73 | + '22', |
| 74 | + 'de']), |
| 75 | + 'de') |
| 76 | + self.assertEqual(messages.wash_languages(['00', |
| 77 | + '11', |
| 78 | + '22']), |
| 79 | + cfg['CFG_SITE_LANG']) |
| 80 | + |
| 81 | + def test_rtl_direction(self): |
| 82 | + """messages - right-to-left language detection""" |
| 83 | + # Arabic is right-to-left: |
| 84 | + self.assertEqual(messages.is_language_rtl('ar'), True) |
| 85 | + # English is not right-to-left: |
| 86 | + self.assertEqual(messages.is_language_rtl('en'), False) |
| 87 | + |
| 88 | + |
| 89 | +TEST_SUITE = make_test_suite(MessagesLanguageTest,) |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + run_test_suite(TEST_SUITE) |
0 commit comments