From aa84ccfa6141f9444a74fed65de992c0fb7475a7 Mon Sep 17 00:00:00 2001 From: "Martin Trigaux (mat)" Date: Mon, 19 Feb 2024 13:48:24 +0000 Subject: [PATCH] [ADD] test_translation_import: export source terms Add a test for exporting the source terms of modules. This will allow automated scripts to fetch latest terms Backport save_test_file with a parameter on date_format to have predictable filenames closes odoo/odoo#159373 X-original-commit: e7246ea48828746471a2e3a485bee30687eeee80 Signed-off-by: Martin Trigaux (mat) --- .../test_translation_import/tests/__init__.py | 1 + .../tests/test_export_wizard.py | 24 +++++++++++++++++++ odoo/tests/common.py | 5 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 odoo/addons/test_translation_import/tests/test_export_wizard.py diff --git a/odoo/addons/test_translation_import/tests/__init__.py b/odoo/addons/test_translation_import/tests/__init__.py index e51db6a2527..d23a2fa0076 100644 --- a/odoo/addons/test_translation_import/tests/__init__.py +++ b/odoo/addons/test_translation_import/tests/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- +from . import test_export_wizard from . import test_term_count diff --git a/odoo/addons/test_translation_import/tests/test_export_wizard.py b/odoo/addons/test_translation_import/tests/test_export_wizard.py new file mode 100644 index 00000000000..c3f8a48dfbf --- /dev/null +++ b/odoo/addons/test_translation_import/tests/test_export_wizard.py @@ -0,0 +1,24 @@ +import base64 +from odoo.tests import common, tagged + + +@tagged("post_install", "-at_install", "-standard", "nightly_export") +class TestTranslationFlow(common.TransactionCase): + + @common.no_retry + def test_export_source(self): + """Export the source terms for every module and save it""" + + for module in self.env["ir.module.module"].search([("state", "=", "installed")]): + export = self.env["base.language.export"].create({ + "lang": "__new__", + "format": "po", + "modules": [(6, 0, [module.id])] + }) + export.act_getfile() + pot_file = base64.b64decode(export.data) + common.save_test_file( + module.name, pot_file, prefix="i18n_", extension="pot", + document_type="Source Terms for %s" % module.name, + date_format="", + ) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index f569cbca658..4a2c039cfa1 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -871,12 +871,11 @@ def fchain(future, next_callback): return new_future - -def save_test_file(test_name, content, prefix, extension='png', logger=_logger, document_type='Screenshot'): +def save_test_file(test_name, content, prefix, extension='png', logger=_logger, document_type='Screenshot', date_format="%Y%m%d_%H%M%S_%f"): assert re.fullmatch(r'\w*_', prefix) assert re.fullmatch(r'[a-z]+', extension) assert re.fullmatch(r'\w+', test_name) - now = datetime.now().strftime("%Y%m%d_%H%M%S_%f") + now = datetime.now().strftime(date_format) screenshots_dir = pathlib.Path(odoo.tools.config['screenshots']) / get_db_name() / 'screenshots' screenshots_dir.mkdir(parents=True, exist_ok=True) fname = f'{prefix}{now}_{test_name}.{extension}'