From c6fc31eceeeb0f2c2d8e5aac12b47e2af4f47237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 18 Jan 2021 23:20:40 +0100 Subject: [PATCH] Test copy translation issue9866 review353091002 --- trytond/tests/copy_.py | 7 +++++ trytond/tests/test_copy.py | 53 +++++++++++++++++++++++++++++++++- trytond/tests/test_modelsql.py | 14 +++++++-- 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/trytond/tests/copy_.py b/trytond/tests/copy_.py index e902f0da10..6fb1627598 100644 --- a/trytond/tests/copy_.py +++ b/trytond/tests/copy_.py @@ -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') diff --git a/trytond/tests/test_copy.py b/trytond/tests/test_copy.py index 7f63931a1c..03a22d822d 100644 --- a/trytond/tests/test_copy.py +++ b/trytond/tests/test_copy.py @@ -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_ diff --git a/trytond/tests/test_modelsql.py b/trytond/tests/test_modelsql.py index cadda219aa..e8539e134f 100644 --- a/trytond/tests/test_modelsql.py +++ b/trytond/tests/test_modelsql.py @@ -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"