[IMP] Improve tests around custom migration scripts
This commit is contained in:
parent
39f70d1012
commit
23cc76f7f0
|
|
@ -19,11 +19,11 @@ def test_cli_execute_script_python():
|
|||
ctx = build_ctx_from_config_file()
|
||||
|
||||
extra_script_path = Path(
|
||||
"../extra_script/post-migration-custom_test.py"
|
||||
"../extra_script/01-post-migration-custom_test.py"
|
||||
).absolute()
|
||||
cp(
|
||||
extra_script_path,
|
||||
Path("post-migration-custom_test.py"),
|
||||
Path("01-post-migration-custom_test.py"),
|
||||
)
|
||||
|
||||
db_name = "database_test_cli___execute_script_python"
|
||||
|
|
@ -52,7 +52,7 @@ def test_cli_execute_script_python():
|
|||
"execute-script-python",
|
||||
"--step=1",
|
||||
f"--database={db_name}",
|
||||
"--script-file-path=post-migration-custom_test.py",
|
||||
"--script-file-path=01-post-migration-custom_test.py",
|
||||
],
|
||||
)
|
||||
partner_quantity_after = int(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
from pathlib import Path
|
||||
from shutil import copy
|
||||
|
||||
from odoo_openupgrade_wizard.tools.tools_postgres import (
|
||||
ensure_database,
|
||||
execute_sql_request,
|
||||
|
|
@ -14,6 +17,17 @@ def test_cli_upgrade():
|
|||
move_to_test_folder()
|
||||
ctx = build_ctx_from_config_file()
|
||||
|
||||
for n in ["01", "02"]:
|
||||
copy(
|
||||
Path(
|
||||
f"../extra_script/{n}-post-migration-custom_test.py"
|
||||
).absolute(),
|
||||
Path(
|
||||
"scripts/step_01__regular__14.0/"
|
||||
f"{n}-post-migration-custom_test.py"
|
||||
),
|
||||
)
|
||||
|
||||
# Initialize database
|
||||
db_name = "database_test_cli___upgrade"
|
||||
ensure_database(ctx, db_name, state="absent")
|
||||
|
|
@ -58,3 +72,23 @@ def test_cli_upgrade():
|
|||
latest_version = execute_sql_request(ctx, request, database=db_name)
|
||||
|
||||
assert latest_version[0][0].startswith("15.")
|
||||
|
||||
# ensure the first post-migration-custom scripts have been executed
|
||||
request = (
|
||||
"SELECT name"
|
||||
" FROM res_partner"
|
||||
" WHERE name like 'Post Script 1 - Partner #%';"
|
||||
)
|
||||
|
||||
result = execute_sql_request(ctx, request, database=db_name)
|
||||
assert len(result) == 10
|
||||
|
||||
# ensure the second post-migration-custom scripts have been executed
|
||||
request = (
|
||||
"SELECT name"
|
||||
" FROM res_partner"
|
||||
" WHERE name = 'Post Script 2 - Partner #1';"
|
||||
)
|
||||
|
||||
result = execute_sql_request(ctx, request, database=db_name)
|
||||
assert len(result) == 1
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.info("post-migration-custom_test.py : Begin of script ...")
|
||||
_logger.info("01-post-migration-custom_test.py : Begin of script ...")
|
||||
|
||||
env = env # noqa: F821
|
||||
|
||||
for i in range(0, 10):
|
||||
partner_name = "Partner #%d" % (i)
|
||||
partner_name = "Post Script 1 - Partner #%d" % (i)
|
||||
_logger.info("Create Partner %s" % partner_name)
|
||||
env["res.partner"].create({"name": partner_name})
|
||||
|
||||
_logger.info("post-migration-custom_test.py : End of script.")
|
||||
_logger.info("01-post-migration-custom_test.py : End of script.")
|
||||
|
||||
env.cr.commit()
|
||||
12
tests/data/extra_script/02-post-migration-custom_test.py
Normal file
12
tests/data/extra_script/02-post-migration-custom_test.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.info("02-post-migration-custom_test.py : Begin of script ...")
|
||||
|
||||
env = env # noqa: F821
|
||||
|
||||
env["res.partner"].create({"name": "Post Script 2 - Partner #1"})
|
||||
|
||||
_logger.info("02-post-migration-custom_test.py : End of script.")
|
||||
|
||||
env.cr.commit()
|
||||
Loading…
Reference in New Issue
Block a user