From 498624f90273cd761143bb74a87f294a4fa0de73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Fri, 10 Apr 2026 09:43:16 +0200 Subject: [PATCH] [IMP] odoo_project_migration: add tests --- odoo_project_migration/tests/__init__.py | 2 + odoo_project_migration/tests/common.py | 42 ++++++++++ .../tests/test_export_migration_report.py | 79 +++++++++++++++++++ .../tests/test_generate_migration_data.py | 54 +++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 odoo_project_migration/tests/__init__.py create mode 100644 odoo_project_migration/tests/common.py create mode 100644 odoo_project_migration/tests/test_export_migration_report.py create mode 100644 odoo_project_migration/tests/test_generate_migration_data.py diff --git a/odoo_project_migration/tests/__init__.py b/odoo_project_migration/tests/__init__.py new file mode 100644 index 00000000..917bc32a --- /dev/null +++ b/odoo_project_migration/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_generate_migration_data +from . import test_export_migration_report diff --git a/odoo_project_migration/tests/common.py b/odoo_project_migration/tests/common.py new file mode 100644 index 00000000..9b3aada2 --- /dev/null +++ b/odoo_project_migration/tests/common.py @@ -0,0 +1,42 @@ +# Copyright 2026 Sébastien Alix +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.tests import Form + +from odoo.addons.odoo_project.tests.common import ProjectCommon +from odoo.addons.odoo_repository_migration.tests.common import MigrationCommon + + +class ProjectMigrationCommon(ProjectCommon, MigrationCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.mig_path_model = cls.env["odoo.migration.path"] + cls.wiz_generate_mig_data_model = cls.env[ + "odoo.project.generate.migration.data" + ] + cls.wiz_export_mig_report_model = cls.env[ + "odoo.project.export.migration.report" + ] + + @classmethod + def _generate_migration_data(cls, project, migration_path): + wiz_model = cls.wiz_generate_mig_data_model.with_context( + default_odoo_project_id=project.id + ) + with Form(wiz_model) as form: + form.migration_path_id = migration_path + wiz = form.save() + wiz.action_generate_data() + cls.env.flush_all() # Force fields computation + return wiz + + @classmethod + def _export_migration_report(cls, project, migration_path): + wiz_model = cls.wiz_export_mig_report_model.with_context( + default_odoo_project_id=project.id + ) + with Form(wiz_model) as form: + form.migration_path_id = migration_path + wiz = form.save() + return wiz.action_export_report() diff --git a/odoo_project_migration/tests/test_export_migration_report.py b/odoo_project_migration/tests/test_export_migration_report.py new file mode 100644 index 00000000..38940ee7 --- /dev/null +++ b/odoo_project_migration/tests/test_export_migration_report.py @@ -0,0 +1,79 @@ +# Copyright 2026 Sébastien Alix +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +import csv +import io + +from .common import ProjectMigrationCommon + + +class TestOdooProjectExportMigrationReport(ProjectMigrationCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.migration_path = cls.mig_path_model.create( + { + "source_branch_id": cls.branch.id, + "target_branch_id": cls.branch2.id, + } + ) + # Retrieve migration data for `cls.module_branch` + cls._simulate_migration_scan( + "target_commit1", report={"process": "migrate", "results": {}} + ) + # And import/install this module in our project + cls._run_import_modules(cls.project, cls.module_branch.module_name) + # Generate migration data + cls._generate_migration_data(cls.project, cls.migration_path) + + def test_export_migration_report(self): + """Test the export migration report wizard.""" + action = self._export_migration_report(self.project, self.migration_path) + # Check action export report + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertIn("web/content/?model=ir.attachment", action["url"]) + # Check attachment created + attachment = self.env["ir.attachment"].search( + [("res_model", "=", self.project._name), ("res_id", "=", self.project.id)] + ) + self.assertTrue(attachment) + self.assertIn(".csv", attachment.name) + self.assertEqual(attachment.type, "binary") + + def test_export_migration_report_csv_content(self): + """Test the CSV content of the export migration report.""" + project_mod = self.project.project_module_ids + # Get CSV content + wiz = self.wiz_export_mig_report_model.with_context( + default_odoo_project_id=self.project.id + ).create( + { + "migration_path_id": self.migration_path.id, + } + ) + content = wiz._get_csv_content() + file_ = io.StringIO(content) + reader = csv.DictReader(file_) + rows = list(reader) + repo_row, module_row = rows + # Repository row + self.assertEqual(repo_row["Repository"], project_mod.repository_id.display_name) + self.assertFalse(repo_row["Module"]) + # Module row + self.assertDictEqual( + module_row, + { + "Repository": "", + "Module": project_mod.module_name, + "Dependencies": "", + "Global Dep. Level": "1", + "Non-Std Dep. Level": "1", + "Info": "", + "Warning": "", + "Python": "0", + "JavaScript": "0", + "CSS": "0", + "XML": "0", + "Status": "migrate", + }, + ) diff --git a/odoo_project_migration/tests/test_generate_migration_data.py b/odoo_project_migration/tests/test_generate_migration_data.py new file mode 100644 index 00000000..26809fe0 --- /dev/null +++ b/odoo_project_migration/tests/test_generate_migration_data.py @@ -0,0 +1,54 @@ +# Copyright 2026 Sébastien Alix +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from .common import ProjectMigrationCommon + + +class TestOdooProjectGenerateMigrationData(ProjectMigrationCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.migration_path = cls.mig_path_model.create( + { + "source_branch_id": cls.branch.id, + "target_branch_id": cls.branch2.id, + } + ) + # Retrieve migration data for `cls.module_branch` + cls._simulate_migration_scan( + "target_commit1", report={"process": "migrate", "results": {}} + ) + # And import/install this module in our project + cls._run_import_modules(cls.project, cls.module_branch.module_name) + + def test_generate_migration_data(self): + self.assertFalse(self.project.module_migration_ids) + self._generate_migration_data(self.project, self.migration_path) + # Check project module migration records + module_migs = self.project.module_migration_ids + self.assertTrue(module_migs) + self.assertRecordValues( + module_migs, + [ + { + "migration_path_id": self.migration_path.id, + "source_module_branch_id": self.module_branch.id, + "target_module_branch_id": False, + "project_module_id": self.project.project_module_ids.id, + "module_migration_id": self.module_branch.migration_ids.id, + "state": "migrate", + } + ], + ) + + def test_generate_migration_data_existing_data_removed(self): + self.assertFalse(self.project.module_migration_ids) + self._generate_migration_data(self.project, self.migration_path) + # Check project module migration records + module_migs = self.project.module_migration_ids + self.assertTrue(module_migs) + # Re-generate migration data => new records are created + self._generate_migration_data(self.project, self.migration_path) + new_module_migs = self.project.module_migration_ids + self.assertTrue(new_module_migs.exists()) + self.assertFalse(module_migs.exists())