changeset 9da9d1618bec in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=9da9d1618bec
description:
Test copy translation
issue9866
review353091002
diffstat:
trytond/tests/copy_.py | 7 +++++
trytond/tests/test_copy.py | 53 +++++++++++++++++++++++++++++++++++++++++-
trytond/tests/test_modelsql.py | 14 ++++++++--
3 files changed, 70 insertions(+), 4 deletions(-)
diffs (128 lines):
diff -r 162c79d3b45b -r 9da9d1618bec trytond/tests/copy_.py
--- a/trytond/tests/copy_.py Mon Jan 18 23:20:15 2021 +0100
+++ b/trytond/tests/copy_.py Mon Jan 18 23:20:40 2021 +0100
@@ -101,6 +101,12 @@
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 @@
CopyMany2ManyReferenceTarget,
CopyMany2ManyReferenceRelation,
CopyBinary,
+ CopyTranslate,
module=module, type_='model')
diff -r 162c79d3b45b -r 9da9d1618bec trytond/tests/test_copy.py
--- a/trytond/tests/test_copy.py Mon Jan 18 23:20:15 2021 +0100
+++ b/trytond/tests/test_copy.py Mon Jan 18 23:20:40 2021 +0100
@@ -5,8 +5,11 @@
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 @@
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_
diff -r 162c79d3b45b -r 9da9d1618bec trytond/tests/test_modelsql.py
--- a/trytond/tests/test_modelsql.py Mon Jan 18 23:20:15 2021 +0100
+++ b/trytond/tests/test_modelsql.py Mon Jan 18 23:20:40 2021 +0100
@@ -524,14 +524,13 @@
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 @@
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"