[IMP] iap, website: add IAP languages test
This commit adds a test to check that the IAP languages work as expected for the website configurator. The test checks that the industries are translated (different than other languages). task-3343616 closes odoo/odoo#123722 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user