Skip to content

Commit

Permalink
[IMP] add tests for end migration scripts for newly installed modules
Browse files Browse the repository at this point in the history
  • Loading branch information
metaminux committed Aug 29, 2023
1 parent 9f09f7b commit a38ad4e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_base_migration
from . import test_newly_installed_end_migration
27 changes: 27 additions & 0 deletions openupgrade_scripts/scripts/base/16.0.1.3/tests/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
import shutil
import os

# create an end-migration script for a newly installed module
openupgrade_script_dir = os.path.join(
os.getenv("github.workspace"),
"openupgrade",
"openupgrade_scripts",
)
src_script = os.path.join(
openupgrade_script_dir,
"base",
"16.0.1.3",
"tests",
"end-migration_test.py",
)
dest_script_dir = os.path.join(
openupgrade_script_dir,
"spreadsheet",
"16.0.1.0",
)
dest_script = os.path.join(
dest_script_dir,
"end-migration.py",
)
os.mkdir(dest_script_dir)
shutil.copy(src_script, dest_script)
env = locals().get("env")
# set company_registry in v15 to be sure we migrate it correctly to v16
env.ref("base.main_company").company_registry = "424242"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Odoo Community Association (OCA)
# Copyright 2023 Guillaume Masson <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from openupgradelib import openupgrade

_logger = logging.getLogger(__name__)


@openupgrade.migrate(no_version=True)
def migrate(env, version):
params = env["ir.config_parameter"].sudo()
params.set_param("openupgrade.test_end_migration", "Executed")

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo.tests import TransactionCase, tagged


@tagged('-at_install', 'post_install')
class TestNewlyInstalledEndMigration(TransactionCase):
def test_newly_installed_end_migration(self):
"""Make sure the code of the end-migration script has been executed"""
params = self.env["ir.config_parameter"].sudo()
res = params.get_param("openupgrade.test_end_migration", default="Not executed")
self.assertEqual(res, "Executed")

0 comments on commit a38ad4e

Please sign in to comment.