changeset 47039caac53e in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=47039caac53e
description:
Test translation in fields_get
issue8744
review254491002
diffstat:
trytond/tests/test_model.py | 62 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 61 insertions(+), 1 deletions(-)
diffs (77 lines):
diff -r 3723276aa94f -r 47039caac53e trytond/tests/test_model.py
--- a/trytond/tests/test_model.py Fri Oct 25 23:05:38 2019 +0200
+++ b/trytond/tests/test_model.py Fri Oct 25 23:06:19 2019 +0200
@@ -5,6 +5,7 @@
from trytond.pool import Pool
from trytond.tests.test_tryton import activate_module, with_transaction
+from trytond.transaction import Transaction
class ModelTestCase(unittest.TestCase):
@@ -163,5 +164,64 @@
self.assertTrue(definition['name']['readonly'])
+class ModelTranslationTestCase(unittest.TestCase):
+ "Test Model translation"
+ default_language = 'en'
+ other_language = 'fr'
+
+ @classmethod
+ def setUpClass(cls):
+ activate_module('tests')
+ cls.setup_language()
+
+ @classmethod
+ @with_transaction()
+ def setup_language(cls):
+ pool = Pool()
+ Language = pool.get('ir.lang')
+ Configuration = pool.get('ir.configuration')
+
+ default, = Language.search([('code', '=', cls.default_language)])
+ default.translatable = True
+ default.save()
+
+ other, = Language.search([('code', '=', cls.other_language)])
+ other.translatable = True
+ other.save()
+
+ config = Configuration(1)
+ config.language = cls.default_language
+ config.save()
+
+ Transaction().commit()
+
+ @with_transaction()
+ def test_fields_get(self):
+ "Test fields_get translated"
+ pool = Pool()
+ Model = pool.get('test.model')
+ Translation = pool.get('ir.translation')
+
+ Translation.create([{
+ 'lang': self.other_language,
+ 'src': "Name",
+ 'name': 'test.model,name',
+ 'res_id': -1,
+ 'value': "Nom",
+ 'type': 'field',
+ }])
+ with Transaction().set_context(language=self.default_language):
+ field = Model.fields_get(['name'])['name']
+ with Transaction().set_context(language=self.other_language):
+ other = Model.fields_get(['name'])['name']
+
+ self.assertEqual(field['string'], "Name")
+ self.assertEqual(other['string'], "Nom")
+
+
def suite():
- return unittest.TestLoader().loadTestsFromTestCase(ModelTestCase)
+ suite_ = unittest.TestSuite()
+ suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(ModelTestCase))
+ suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(
+ ModelTranslationTestCase))
+ return suite_