Test copy translation
issue9866 review353091002
This commit is contained in:
@@ -101,6 +101,12 @@ class CopyBinary(ModelSQL):
|
||||
file_id = fields.Char("Binary ID")
|
||||
|
||||
|
||||
class CopyTranslate(ModelSQL):
|
||||
"Copy Translate"
|
||||
__name__ = 'test.copy.translate'
|
||||
name = fields.Char("Name", translate=True)
|
||||
|
||||
|
||||
def register(module):
|
||||
Pool.register(
|
||||
Copy,
|
||||
@@ -115,4 +121,5 @@ def register(module):
|
||||
CopyMany2ManyReferenceTarget,
|
||||
CopyMany2ManyReferenceRelation,
|
||||
CopyBinary,
|
||||
CopyTranslate,
|
||||
module=module, type_='model')
|
||||
|
||||
@@ -5,8 +5,11 @@ import unittest
|
||||
|
||||
from trytond.model import fields
|
||||
from trytond.tests.test_tryton import activate_module, with_transaction
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
|
||||
from .test_modelsql import TranslationTestCase
|
||||
|
||||
|
||||
class CopyTestCase(unittest.TestCase):
|
||||
'Test copy'
|
||||
@@ -196,5 +199,53 @@ class CopyTestCase(unittest.TestCase):
|
||||
self.assertEqual(record_copy.binary_id, record.binary_id)
|
||||
|
||||
|
||||
class CopyTranslationTestCase(TranslationTestCase):
|
||||
"Test copy translation"
|
||||
|
||||
@with_transaction()
|
||||
def test_copy(self):
|
||||
"Test copy"
|
||||
pool = Pool()
|
||||
Translate = pool.get('test.copy.translate')
|
||||
|
||||
with Transaction().set_context(language=self.default_language):
|
||||
record, = Translate.create([{'name': "Foo"}])
|
||||
with Transaction().set_context(language=self.other_language):
|
||||
Translate.write([record], {'name': "Bar"})
|
||||
|
||||
record_copy, = Translate.copy([record])
|
||||
|
||||
with Transaction().set_context(language=self.default_language):
|
||||
record_copy = Translate(record_copy.id)
|
||||
self.assertEqual(record_copy.name, "Foo")
|
||||
with Transaction().set_context(language=self.other_language):
|
||||
record_copy = Translate(record_copy.id)
|
||||
self.assertEqual(record_copy.name, "Bar")
|
||||
|
||||
@with_transaction()
|
||||
def test_copy_multiple(self):
|
||||
"Test copy multiple"
|
||||
pool = Pool()
|
||||
Translate = pool.get('test.copy.translate')
|
||||
|
||||
with Transaction().set_context(language=self.default_language):
|
||||
record, = Translate.create([{'name': "Foo"}])
|
||||
with Transaction().set_context(language=self.other_language):
|
||||
Translate.write([record], {'name': "Bar"})
|
||||
|
||||
record_copies = Translate.copy([record, record])
|
||||
|
||||
with Transaction().set_context(language=self.default_language):
|
||||
record_copies = Translate.browse(record_copies)
|
||||
self.assertEqual({r.name for r in record_copies}, {"Foo"})
|
||||
with Transaction().set_context(language=self.other_language):
|
||||
record_copies = Translate.browse(record_copies)
|
||||
self.assertEqual({r.name for r in record_copies}, {"Bar"})
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(CopyTestCase)
|
||||
suite_ = unittest.TestSuite()
|
||||
suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(CopyTestCase))
|
||||
suite_.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||
CopyTranslationTestCase))
|
||||
return suite_
|
||||
|
||||
@@ -524,14 +524,13 @@ class ModelSQLTestCase(unittest.TestCase):
|
||||
record.lock()
|
||||
|
||||
|
||||
class ModelSQLTranslationTestCase(unittest.TestCase):
|
||||
"Test ModelSQL translation"
|
||||
class TranslationTestCase(unittest.TestCase):
|
||||
default_language = 'fr'
|
||||
other_language = 'en'
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
activate_module('tests')
|
||||
super().setUpClass()
|
||||
cls.setup_language()
|
||||
|
||||
@classmethod
|
||||
@@ -581,6 +580,15 @@ class ModelSQLTranslationTestCase(unittest.TestCase):
|
||||
|
||||
Transaction().commit()
|
||||
|
||||
|
||||
class ModelSQLTranslationTestCase(TranslationTestCase):
|
||||
"Test ModelSQL translation"
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
activate_module('tests')
|
||||
|
||||
@with_transaction()
|
||||
def test_create_default_language(self):
|
||||
"Test create default language"
|
||||
|
||||
Reference in New Issue
Block a user