Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions odoo_project/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions odoo_project/tests/test_import_modules.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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}"
Expand All @@ -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
)
Expand All @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down
25 changes: 11 additions & 14 deletions odoo_repository/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions odoo_repository_migration/tests/common.py
Original file line number Diff line number Diff line change
@@ -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,
)
58 changes: 2 additions & 56 deletions odoo_repository_migration/tests/test_odoo_module_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading