diff --git a/odoo_openupgrade_wizard/cli/cli_init.py b/odoo_openupgrade_wizard/cli/cli_init.py index 382aba8..c630b72 100644 --- a/odoo_openupgrade_wizard/cli/cli_init.py +++ b/odoo_openupgrade_wizard/cli/cli_init.py @@ -51,6 +51,7 @@ def init( """Initialize OpenUpgrade Wizard Environment based on the initial and the final version of Odoo you want to migrate. """ + print(0 / 0) # Handle arguments if extra_repository_list: diff --git a/tests/__init__.py b/tests/__init__.py index 632b9cd..be5e39b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -28,16 +28,33 @@ def move_to_test_folder(): os.chdir(test_folder_path) -def cli_runner_invoke(cmd): - result = CliRunner().invoke( - main, - cmd, - catch_exceptions=False, - ) - if not result.exit_code == 0: - _logger.error("exit_code: %s" % result.exit_code) - _logger.error("output: %s" % result.output) - assert result.exit_code == 0 +def cli_runner_invoke(ctx, cmd): + try: + result = CliRunner().invoke( + main, + cmd, + catch_exceptions=False, + ) + if not result.exit_code == 0: + _logger.error("exit_code: %s" % result.exit_code) + _logger.error("output: %s" % result.output) + assert result.exit_code == 0 + except Exception as exception: + + log_files = [ + ctx.obj["log_folder_path"] / Path(f) + for f in os.listdir(ctx.obj["log_folder_path"]) + if f[-4:] == ".log" + ] + for log_file in log_files: + print("============================") + print(log_file) + print("============================") + _f = open(log_file) + print(_f.read()) + _f.close() + print("============================") + raise exception def build_ctx_from_config_file() -> dict: @@ -58,4 +75,5 @@ def build_ctx_from_config_file() -> dict: ctx.obj["env_folder_path"] = env_folder_path ctx.obj["src_folder_path"] = env_folder_path / Path("src") + ctx.obj["log_folder_path"] = env_folder_path / Path("log") return ctx diff --git a/tests/cli_01_init_test.py b/tests/cli_01_init_test.py index 490e071..eb20d9e 100644 --- a/tests/cli_01_init_test.py +++ b/tests/cli_01_init_test.py @@ -1,14 +1,21 @@ import filecmp from pathlib import Path -from . import cli_runner_invoke, move_to_test_folder +from . import ( + build_ctx_from_config_file, + cli_runner_invoke, + move_to_test_folder, +) def test_cli_init(): move_to_test_folder() + ctx = build_ctx_from_config_file() + expected_folder_path = Path("../output_expected").absolute() cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "init", @@ -17,7 +24,7 @@ def test_cli_init(): "--final-version=15.0", "--extra-repository=" "OCA/web,OCA/server-tools,OCA/bank-statement-import", - ] + ], ) assert filecmp.cmp( diff --git a/tests/cli_02_get_code_test.py b/tests/cli_02_get_code_test.py index ffef04b..ef7d9b5 100644 --- a/tests/cli_02_get_code_test.py +++ b/tests/cli_02_get_code_test.py @@ -1,15 +1,22 @@ from pathlib import Path -from . import cli_runner_invoke, move_to_test_folder +from . import ( + build_ctx_from_config_file, + cli_runner_invoke, + move_to_test_folder, +) def test_cli_get_code(): move_to_test_folder() + ctx = build_ctx_from_config_file() + cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "get-code", - ] + ], ) # Check V14 diff --git a/tests/cli_03_docker_build_test.py b/tests/cli_03_docker_build_test.py index 6bbca10..649ab7a 100644 --- a/tests/cli_03_docker_build_test.py +++ b/tests/cli_03_docker_build_test.py @@ -1,16 +1,23 @@ from odoo_openupgrade_wizard.tools.tools_docker import get_docker_client -from . import cli_runner_invoke, move_to_test_folder +from . import ( + build_ctx_from_config_file, + cli_runner_invoke, + move_to_test_folder, +) def test_cli_docker_build(): move_to_test_folder() + ctx = build_ctx_from_config_file() + cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "docker-build", "--versions=14.0,15.0", - ] + ], ) docker_client = get_docker_client() diff --git a/tests/cli_04_run_test.py b/tests/cli_04_run_test.py index 968ed08..834256f 100644 --- a/tests/cli_04_run_test.py +++ b/tests/cli_04_run_test.py @@ -21,6 +21,7 @@ def test_cli_run(): ensure_database(ctx, db_name, state="absent") cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "run", @@ -28,7 +29,7 @@ def test_cli_run(): "--database=%s" % db_name, "--init-modules=base", "--stop-after-init", - ] + ], ) # Ensure that a subfolder filestore/DB_NAME has been created diff --git a/tests/cli_05_execute_script_python_test.py b/tests/cli_05_execute_script_python_test.py index ccf7ba2..a151b8c 100644 --- a/tests/cli_05_execute_script_python_test.py +++ b/tests/cli_05_execute_script_python_test.py @@ -31,6 +31,7 @@ def test_cli_execute_script_python(): # Install Odoo on V14 with base installed cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "run", @@ -38,7 +39,7 @@ def test_cli_execute_script_python(): "--database=%s" % db_name, "--init-modules=base", "--stop-after-init", - ] + ], ) # Compute partners quantity @@ -49,13 +50,14 @@ def test_cli_execute_script_python(): # Execute Custom Python Script cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "execute-script-python", "--step=1", "--database=%s" % db_name, "--script-file-path=post-migration-custom_test.py", - ] + ], ) partner_quantity_after = int( execute_sql_request(ctx, request, database=db_name)[0][0] diff --git a/tests/cli_06_execute_script_sql_test.py b/tests/cli_06_execute_script_sql_test.py index b94cef0..fa71486 100644 --- a/tests/cli_06_execute_script_sql_test.py +++ b/tests/cli_06_execute_script_sql_test.py @@ -33,12 +33,13 @@ def test_cli_execute_script_sql(): # TODO call with script-file-path # to avoid to copy file in scripts/step_xxx folder cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "execute-script-sql", "--step=1", "--database=%s" % db_name, - ] + ], ) # Ensure that the request has been done correctly diff --git a/tests/cli_07_upgrade_test.py b/tests/cli_07_upgrade_test.py index fc5ce82..e1b0c63 100644 --- a/tests/cli_07_upgrade_test.py +++ b/tests/cli_07_upgrade_test.py @@ -12,13 +12,14 @@ from . import ( def test_cli_upgrade(): move_to_test_folder() + ctx = build_ctx_from_config_file() # Initialize database db_name = "database_test_cli___upgrade" - ctx = build_ctx_from_config_file() ensure_database(ctx, db_name, state="absent") cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "run", @@ -26,7 +27,7 @@ def test_cli_upgrade(): "--database=%s" % db_name, "--init-modules=base", "--stop-after-init", - ] + ], ) # Ensure that 'base' module is installed at 14.0 @@ -41,13 +42,14 @@ def test_cli_upgrade(): assert latest_version[0][0].startswith("14.") cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "upgrade", "--database=%s" % db_name, "--first-step=1", "--last-step=3", - ] + ], ) # Ensure that 'base' module is installed at 15.0 diff --git a/tests/cli_08_estimate_workload_test.py b/tests/cli_08_estimate_workload_test.py index 23ce71f..3a88555 100644 --- a/tests/cli_08_estimate_workload_test.py +++ b/tests/cli_08_estimate_workload_test.py @@ -1,14 +1,20 @@ import unittest from pathlib import Path -from . import cli_runner_invoke, move_to_test_folder +from . import ( + build_ctx_from_config_file, + cli_runner_invoke, + move_to_test_folder, +) class TestCliEstimateWorkload(unittest.TestCase): def test_cli_estimate_workload(self): move_to_test_folder() + ctx = build_ctx_from_config_file() cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "estimate-workload", @@ -32,7 +38,7 @@ class TestCliEstimateWorkload(unittest.TestCase): ",web_widget_one2many_tree_line_duplicate" ",web_widget_dropdown_dynamic_example" ",my_module_that_doesnt_exist", - ] + ], ) # We check file has been created diff --git a/tests/cli_20_install_from_csv_test.py b/tests/cli_20_install_from_csv_test.py index 222860c..c539a4f 100644 --- a/tests/cli_20_install_from_csv_test.py +++ b/tests/cli_20_install_from_csv_test.py @@ -19,11 +19,12 @@ def test_cli_install_from_csv(): ensure_database(ctx, db_name, state="absent") cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "install-from-csv", "--database=%s" % db_name, - ] + ], ) # Ensure that 'base' is installed diff --git a/tests/cli_21_generate_module_analysis_test.py b/tests/cli_21_generate_module_analysis_test.py index eaf5ae5..f640aeb 100644 --- a/tests/cli_21_generate_module_analysis_test.py +++ b/tests/cli_21_generate_module_analysis_test.py @@ -28,13 +28,14 @@ def test_cli_generate_module_analysis(): analysis_file_path cli_runner_invoke( + ctx, [ "--log-level=DEBUG", "generate-module-analysis", "--step=2", "--database=%s" % db_name, "--modules=base", - ] + ], ) # The file should has been recreated by the analysis command