changeset c7a827a5f88b in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=c7a827a5f88b
description:
        Restore English language on tear down

        The translations tests change the default language on setup and commit 
the
        change. So we must restore the initial state of the database at the end 
of the
        test case.

        issue9702
        review312521002
diffstat:

 trytond/ir/configuration.py    |  16 ++++++++++++++++
 trytond/tests/test_modelsql.py |  26 ++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 0 deletions(-)

diffs (59 lines):

diff -r e5188f91d789 -r c7a827a5f88b trytond/ir/configuration.py
--- a/trytond/ir/configuration.py       Mon Oct 12 18:02:39 2020 +0200
+++ b/trytond/ir/configuration.py       Wed Oct 14 14:43:40 2020 +0200
@@ -31,3 +31,19 @@
     def check(self):
         "Check configuration coherence on pool initialisation"
         pass
+
+    @classmethod
+    def create(cls, vlist):
+        records = super().create(vlist)
+        cls._get_language_cache.clear()
+        return records
+
+    @classmethod
+    def write(cls, *args):
+        super().write(*args)
+        cls._get_language_cache.clear()
+
+    @classmethod
+    def delete(cls, records):
+        super().delete(records)
+        cls._get_language_cache.clear()
diff -r e5188f91d789 -r c7a827a5f88b trytond/tests/test_modelsql.py
--- a/trytond/tests/test_modelsql.py    Mon Oct 12 18:02:39 2020 +0200
+++ b/trytond/tests/test_modelsql.py    Wed Oct 14 14:43:40 2020 +0200
@@ -555,6 +555,32 @@
 
         Transaction().commit()
 
+    @classmethod
+    def tearDownClass(cls):
+        super().tearDownClass()
+        cls.restore_language()
+
+    @classmethod
+    @with_transaction()
+    def restore_language(cls):
+        pool = Pool()
+        Language = pool.get('ir.lang')
+        Configuration = pool.get('ir.configuration')
+
+        english, = Language.search([('code', '=', 'en')])
+        english.translatable = True
+        english.save()
+
+        config = Configuration(1)
+        config.language = 'en'
+        config.save()
+
+        Language.write(Language.search([('code', '!=', 'en')]), {
+                'translatable': False,
+                })
+
+        Transaction().commit()
+
     @with_transaction()
     def test_create_default_language(self):
         "Test create default language"

Reply via email to