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
2 changes: 2 additions & 0 deletions odoo_project_migration/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import test_generate_migration_data
from . import test_export_migration_report
42 changes: 42 additions & 0 deletions odoo_project_migration/tests/common.py
Original file line number Diff line number Diff line change
@@ -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()
79 changes: 79 additions & 0 deletions odoo_project_migration/tests/test_export_migration_report.py
Original file line number Diff line number Diff line change
@@ -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",
},
)
54 changes: 54 additions & 0 deletions odoo_project_migration/tests/test_generate_migration_data.py
Original file line number Diff line number Diff line change
@@ -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())
Loading