From 10479760641cf5057b14c64998909f0faa1ebfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Fri, 10 Apr 2026 09:44:53 +0200 Subject: [PATCH 1/3] [FIX] odoo_repository: move setUp content to setUpClass --- odoo_repository/tests/common.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/odoo_repository/tests/common.py b/odoo_repository/tests/common.py index ccadbe49..3fcf1272 100644 --- a/odoo_repository/tests/common.py +++ b/odoo_repository/tests/common.py @@ -55,28 +55,25 @@ def setUpClass(cls): ) cls.branch.active = True cls._handle_cleanup() - - def setUp(self): - super().setUp() # branch2 - self.branch2_name = self.source2.split("/")[1] - self.branch2 = ( - self.env["odoo.branch"] + cls.branch2_name = cls.source2.split("/")[1] + cls.branch2 = ( + cls.env["odoo.branch"] .with_context(active_test=False) - .search([("name", "=", self.branch2_name)]) + .search([("name", "=", cls.branch2_name)]) ) - if not self.branch2: - self.branch2 = self.env["odoo.branch"].create( + if not cls.branch2: + cls.branch2 = cls.env["odoo.branch"].create( { - "name": self.branch2_name, + "name": cls.branch2_name, } ) - self.branch2.active = True + cls.branch2.active = True # branch3 - self.branch3_name = self.target2.split("/")[1] + cls.branch3_name = cls.target2.split("/")[1] # technical module - self.module_name = self.addon - self.module_branch_model = self.env["odoo.module.branch"] + cls.module_name = cls.addon + cls.module_branch_model = cls.env["odoo.module.branch"] def _patch_github_class(self): # Patch helper method part of 'odoo_repository' module From 139404991f84611dd2c0f90c9f0f94b5c41b130a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Fri, 10 Apr 2026 09:51:40 +0200 Subject: [PATCH 2/3] [IMP] odoo_repository_migration: tests, add a MigrationCommon class --- odoo_repository_migration/tests/common.py | 62 +++++++++++++++++++ .../tests/test_odoo_module_branch.py | 58 +---------------- 2 files changed, 64 insertions(+), 56 deletions(-) create mode 100644 odoo_repository_migration/tests/common.py diff --git a/odoo_repository_migration/tests/common.py b/odoo_repository_migration/tests/common.py new file mode 100644 index 00000000..493145d2 --- /dev/null +++ b/odoo_repository_migration/tests/common.py @@ -0,0 +1,62 @@ +# Copyright 2024 Camptocamp SA +# Copyright 2026 Sébastien Alix +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo.addons.odoo_repository.tests import common + + +class MigrationCommon(common.Common): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.module = cls._create_odoo_module("my_module") + cls.repo_branch = cls._create_odoo_repository_branch( + cls.odoo_repository, cls.branch + ) + cls.repo_branch2 = cls._create_odoo_repository_branch( + cls.odoo_repository, cls.branch2 + ) + cls.module_branch = cls._create_odoo_module_branch( + cls.module, + cls.branch, + specific=False, + repository_branch_id=cls.repo_branch.id, + last_scanned_commit="sha", + ) + cls.std_repository = cls.env.ref("odoo_repository.odoo_repository_odoo_odoo") + oca_org = cls.env.ref("odoo_repository.odoo_repository_org_oca") + cls.oca_repository = cls.env["odoo.repository"].create( + { + "org_id": oca_org.id, + "name": "test-repo", + "repo_url": "https://github.com/OCA/test-repo", + } + ) + cls.gen_repository = cls.env["odoo.repository"].create( + { + "name": "new_repo", + "org_id": cls.odoo_repository.org_id.id, + "repo_url": "http://example.net/new_repo", + "specific": False, + "to_scan": False, + } + ) + cls.gen_repository.addons_path_ids = cls.odoo_repository.addons_path_ids + + def _simulate_migration_scan(cls, target_commit, report=None): + """Helper method that pushes scanned migration data.""" + data = { + "module": cls.module_branch.module_name, + "source_version": cls.branch.name, + "source_branch": cls.branch.name, + "target_version": cls.branch2.name, + "target_branch": cls.branch2.name, + "source_commit": cls.module_branch.last_scanned_commit, + "target_commit": target_commit, + } + if report is not None: + data["report"] = report + return cls.env["odoo.module.branch.migration"].push_scanned_data( + cls.module_branch.id, + data, + ) diff --git a/odoo_repository_migration/tests/test_odoo_module_branch.py b/odoo_repository_migration/tests/test_odoo_module_branch.py index b62ca072..20db9569 100644 --- a/odoo_repository_migration/tests/test_odoo_module_branch.py +++ b/odoo_repository_migration/tests/test_odoo_module_branch.py @@ -2,64 +2,10 @@ # Copyright 2026 Sébastien Alix # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from odoo.addons.odoo_repository.tests import common +from .common import MigrationCommon -class TestOdooModuleBranch(common.Common): - def setUp(self): - super().setUp() - self.module = self._create_odoo_module("my_module") - self.repo_branch = self._create_odoo_repository_branch( - self.odoo_repository, self.branch - ) - self.repo_branch2 = self._create_odoo_repository_branch( - self.odoo_repository, self.branch2 - ) - self.module_branch = self._create_odoo_module_branch( - self.module, - self.branch, - specific=False, - repository_branch_id=self.repo_branch.id, - last_scanned_commit="sha", - ) - self.std_repository = self.env.ref("odoo_repository.odoo_repository_odoo_odoo") - oca_org = self.env.ref("odoo_repository.odoo_repository_org_oca") - self.oca_repository = self.env["odoo.repository"].create( - { - "org_id": oca_org.id, - "name": "test-repo", - "repo_url": "https://github.com/OCA/test-repo", - } - ) - self.gen_repository = self.env["odoo.repository"].create( - { - "name": "new_repo", - "org_id": self.odoo_repository.org_id.id, - "repo_url": "http://example.net/new_repo", - "specific": False, - "to_scan": False, - } - ) - self.gen_repository.addons_path_ids = self.odoo_repository.addons_path_ids - - def _simulate_migration_scan(self, target_commit, report=None): - """Helper method that pushes scanned migration data.""" - data = { - "module": self.module_branch.module_name, - "source_version": self.branch.name, - "source_branch": self.branch.name, - "target_version": self.branch2.name, - "target_branch": self.branch2.name, - "source_commit": self.module_branch.last_scanned_commit, - "target_commit": target_commit, - } - if report is not None: - data["report"] = report - return self.env["odoo.module.branch.migration"].push_scanned_data( - self.module_branch.id, - data, - ) - +class TestOdooModuleBranch(MigrationCommon): def test_migration_scan_removed(self): self.module_branch.removed = True self.assertFalse(self.module_branch.migration_scan) From ac3d93b5c19621f22e0fc2a3dd9c90dcfe30df48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Fri, 10 Apr 2026 10:00:35 +0200 Subject: [PATCH 3/3] [IMP] odoo_project: tests, rename common class and consolidate in setUpClass --- odoo_project/tests/common.py | 15 ++++++++------- odoo_project/tests/test_import_modules.py | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/odoo_project/tests/common.py b/odoo_project/tests/common.py index b387a9d5..15f00a30 100644 --- a/odoo_project/tests/common.py +++ b/odoo_project/tests/common.py @@ -6,20 +6,21 @@ from odoo.addons.odoo_repository.tests import common -class Common(common.Common): - def setUp(self): - super().setUp() - self.project = self.env["odoo.project"].create( +class ProjectCommon(common.Common): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.project = cls.env["odoo.project"].create( { "name": "TEST", - "odoo_version_id": self.branch.id, + "odoo_version_id": cls.branch.id, } ) - self.wiz_model = self.env["odoo.project.import.modules"] + cls.wiz_import_modules_model = cls.env["odoo.project.import.modules"] @classmethod def _run_import_modules(cls, project, modules_list_text, **kwargs): - wiz_model = cls.env["odoo.project.import.modules"].with_context( + wiz_model = cls.wiz_import_modules_model.with_context( default_odoo_project_id=project.id ) with Form(wiz_model) as form: diff --git a/odoo_project/tests/test_import_modules.py b/odoo_project/tests/test_import_modules.py index 361de268..2f3167bf 100644 --- a/odoo_project/tests/test_import_modules.py +++ b/odoo_project/tests/test_import_modules.py @@ -1,10 +1,10 @@ # Copyright 2024 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from .common import Common +from .common import ProjectCommon -class TestImportModules(Common): +class TestImportModules(ProjectCommon): def test_import_modules_names(self): mod1 = "test1" mod2 = "test2" @@ -62,7 +62,7 @@ def test_import_modules_names_versions(self): def test_match_blacklisted_module(self): mod1 = "test1" mod2 = "test2" - mod1_blacklisted = self.wiz_model._get_module(mod1) + mod1_blacklisted = self.wiz_import_modules_model._get_module(mod1) mod1_blacklisted.blacklisted = True # Import them through the wizard modules_list_text = f"{mod1}\n{mod2}" @@ -82,7 +82,7 @@ def test_match_blacklisted_module(self): def test_match_orphaned_module(self): mod1 = "test1" mod2 = "test2" - mod1_orphaned = self.wiz_model._get_module(mod1) + mod1_orphaned = self.wiz_import_modules_model._get_module(mod1) mod1_branch_orphaned = self.module_branch_model._create_orphaned_module_branch( self.branch, mod1_orphaned ) @@ -106,7 +106,7 @@ def test_match_orphaned_module(self): def test_match_generic_module(self): mod1 = "test1" mod2 = "test2" - mod1_generic = self.wiz_model._get_module(mod1) + mod1_generic = self.wiz_import_modules_model._get_module(mod1) repo_branch = self._create_odoo_repository_branch( self.odoo_repository, self.branch ) @@ -138,7 +138,7 @@ def test_match_project_repo_module(self): self.project.odoo_version_id = self.branch mod1 = "test1" mod2 = "test2" - mod1_in_repo = self.wiz_model._get_module(mod1) + mod1_in_repo = self.wiz_import_modules_model._get_module(mod1) repo_branch = self._create_odoo_repository_branch( self.odoo_repository, self.branch )