diff --git a/addons/iap/tools/iap_tools.py b/addons/iap/tools/iap_tools.py index 8ef951da082..98e1f23231f 100644 --- a/addons/iap/tools/iap_tools.py +++ b/addons/iap/tools/iap_tools.py @@ -24,6 +24,17 @@ def iap_jsonrpc_mocked(*args, **kwargs): iap_patch = patch('odoo.addons.iap.tools.iap_tools.iap_jsonrpc', iap_jsonrpc_mocked) +@contextlib.contextmanager +def enable_iap_test(): + """Enables real calls to be made to IAP during a test. Note that this should + only be done if the purpose of the test is to test the return from IAP. + Otherwise, you have to mock IAP. Use this function with care and use it only + in tests tagged as external.""" + try: + iap_patch.stop() + yield + finally: + iap_patch.start() def setUp(self): old_setup_func(self) diff --git a/addons/website/tests/__init__.py b/addons/website/tests/__init__.py index 57dedb452ab..501ceec993d 100644 --- a/addons/website/tests/__init__.py +++ b/addons/website/tests/__init__.py @@ -15,6 +15,7 @@ from . import test_fuzzy from . import test_get_current_website from . import test_grid_layout from . import test_http_endpoint +from . import test_iap from . import test_ir_asset from . import test_lang_url from . import test_menu diff --git a/addons/website/tests/test_iap.py b/addons/website/tests/test_iap.py new file mode 100644 index 00000000000..d65d6b82c68 --- /dev/null +++ b/addons/website/tests/test_iap.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import odoo +import odoo.tests +from odoo.addons.iap.tools import iap_tools + +@odoo.tests.tagged('external') +class TestIap(odoo.tests.HttpCase): + + def test_01_industries_lang(self): + """Ensure that the industries are translated in all the languages + supported by the configurator.""" + def _get_industries(lang): + industries = self.env['website']._website_api_rpc('/api/website/1/configurator/industries', {'lang': lang})['industries'] + return {industry['id']: industry['label'] for industry in industries} + + with iap_tools.enable_iap_test(): + english_terms = _get_industries('en') + # Check that every languages are different from english. + for lang in ['de', 'es', 'fr', 'hr', 'hu', 'id', 'it', 'mk', 'nl', 'pt', 'ru', 'zh']: + translated_terms = _get_industries(lang) + has_diff = False + self.assertEqual(len(english_terms), len(translated_terms), "Different number of industries between 'en' and %s" % lang) + for industry_id, english_label in english_terms.items(): + translated_label = translated_terms.get(industry_id, False) + self.assertTrue(translated_label, "Industry %s is not in %s" % (english_label, lang)) + if english_label != translated_label: + # One difference is enough to consider the translation + # as valid. + has_diff = True + break + self.assertTrue(has_diff, "No difference found between 'en' and %s" % lang)