Test translation in fields_get
issue8744 review254491002
This commit is contained in:
1 parent
7e291e13e1
commit
43dc061406
1 file changed
+61
-1
@@ -5,6 +5,7 @@ import unittest
|
||||
|
||||
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 @@ class ModelTestCase(unittest.TestCase):
|
||||
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_
|
||||
Reference in new issue
Block a user