[ADD] test for generate-module-analysis command
This commit is contained in:
parent
8963b3ec59
commit
c7bf8bffc3
|
|
@ -12,8 +12,13 @@ from odoo_openupgrade_wizard.configuration_version_dependant import (
|
||||||
get_installable_odoo_modules,
|
get_installable_odoo_modules,
|
||||||
get_upgrade_analysis_module,
|
get_upgrade_analysis_module,
|
||||||
)
|
)
|
||||||
from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo
|
from odoo_openupgrade_wizard.tools_odoo import (
|
||||||
|
get_odoo_env_path,
|
||||||
|
kill_odoo,
|
||||||
|
run_odoo,
|
||||||
|
)
|
||||||
from odoo_openupgrade_wizard.tools_odoo_instance import OdooInstance
|
from odoo_openupgrade_wizard.tools_odoo_instance import OdooInstance
|
||||||
|
from odoo_openupgrade_wizard.tools_system import ensure_folder_writable
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
|
@ -121,6 +126,13 @@ def generate_module_analysis(ctx, step, database, modules):
|
||||||
final_instance.install_modules(final_modules)
|
final_instance.install_modules(final_modules)
|
||||||
generate_records(final_instance, final_step)
|
generate_records(final_instance, final_step)
|
||||||
|
|
||||||
|
# Make writable files and directories for "other"
|
||||||
|
# group to make possible to write analysis files
|
||||||
|
# for docker container user
|
||||||
|
ensure_folder_writable(
|
||||||
|
get_odoo_env_path(ctx, {"release": final_step["release"]}) / "src"
|
||||||
|
)
|
||||||
|
|
||||||
generate_analysis_files(
|
generate_analysis_files(
|
||||||
final_instance,
|
final_instance,
|
||||||
final_step,
|
final_step,
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,6 @@ def generate_analysis_files(
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("> Create wizard ...")
|
logger.info("> Create wizard ...")
|
||||||
|
|
||||||
wizard = final_odoo_instance.browse_by_create(
|
wizard = final_odoo_instance.browse_by_create(
|
||||||
"openupgrade.analysis.wizard",
|
"openupgrade.analysis.wizard",
|
||||||
{
|
{
|
||||||
|
|
@ -216,6 +215,7 @@ def generate_analysis_files(
|
||||||
proxy = final_odoo_instance.browse_by_create(
|
proxy = final_odoo_instance.browse_by_create(
|
||||||
"upgrade.comparison.config", proxy_vals
|
"upgrade.comparison.config", proxy_vals
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("> Create wizard ...")
|
logger.info("> Create wizard ...")
|
||||||
analysis = final_odoo_instance.browse_by_create(
|
analysis = final_odoo_instance.browse_by_create(
|
||||||
"upgrade.analysis",
|
"upgrade.analysis",
|
||||||
|
|
@ -223,5 +223,6 @@ def generate_analysis_files(
|
||||||
"config_id": proxy.id,
|
"config_id": proxy.id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("> Launch analysis. This can take a while ...")
|
logger.info("> Launch analysis. This can take a while ...")
|
||||||
analysis.analyze()
|
analysis.analyze()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ from git_aggregator import main as gitaggregate_cmd
|
||||||
from git_aggregator.utils import working_directory_keeper
|
from git_aggregator.utils import working_directory_keeper
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from plumbum.cmd import mkdir
|
from plumbum.cmd import chmod, mkdir
|
||||||
|
from plumbum.commands.processes import ProcessExecutionError
|
||||||
|
|
||||||
from odoo_openupgrade_wizard import templates
|
from odoo_openupgrade_wizard import templates
|
||||||
|
|
||||||
|
|
@ -15,6 +16,14 @@ def get_script_folder(ctx, migration_step: dict) -> Path:
|
||||||
return ctx.obj["script_folder_path"] / migration_step["complete_name"]
|
return ctx.obj["script_folder_path"] / migration_step["complete_name"]
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_folder_writable(folder_path: Path):
|
||||||
|
logger.info("Make writable the folder '%s'" % folder_path)
|
||||||
|
try:
|
||||||
|
chmod(["--silent", "--recursive", "o+w", str(folder_path)])
|
||||||
|
except ProcessExecutionError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def ensure_folder_exists(
|
def ensure_folder_exists(
|
||||||
folder_path: Path, mode: str = "755", git_ignore_content: bool = False
|
folder_path: Path, mode: str = "755", git_ignore_content: bool = False
|
||||||
):
|
):
|
||||||
|
|
|
||||||
38
tests/cli_B_07_generate_module_analysis_test.py
Normal file
38
tests/cli_B_07_generate_module_analysis_test.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from odoo_openupgrade_wizard.tools_odoo import get_odoo_env_path
|
||||||
|
|
||||||
|
from . import build_ctx_from_config_file, cli_runner_invoke
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_generate_module_analysis():
|
||||||
|
output_folder_path = Path("./tests/output_B").absolute()
|
||||||
|
db_name = "database_test_cli_cli_generate_module_analysis"
|
||||||
|
|
||||||
|
ctx = build_ctx_from_config_file(output_folder_path)
|
||||||
|
# identify main analysis file of openupgrade
|
||||||
|
analysis_file_path = get_odoo_env_path(ctx, {"release": 14.0}) / Path(
|
||||||
|
"src/openupgrade/openupgrade_scripts/scripts"
|
||||||
|
"/base/14.0.1.3/upgrade_general_log.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
# This file should exist
|
||||||
|
assert analysis_file_path.exists()
|
||||||
|
|
||||||
|
# We remove this file and run the analysis
|
||||||
|
analysis_file_path.unlink()
|
||||||
|
|
||||||
|
analysis_file_path
|
||||||
|
cli_runner_invoke(
|
||||||
|
[
|
||||||
|
"--log-level=DEBUG",
|
||||||
|
"--env-folder=%s" % output_folder_path,
|
||||||
|
"generate-module-analysis",
|
||||||
|
"--step=2",
|
||||||
|
"--database=%s" % db_name,
|
||||||
|
"--modules=base",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# The file should has been recreated by the analysis command
|
||||||
|
assert analysis_file_path.exists()
|
||||||
Loading…
Reference in New Issue
Block a user