[REF] Add logger in test

This commit is contained in:
Sylvain LE GAL 2022-06-29 17:37:08 +02:00
parent 36db85e4b9
commit 1261dfaa2f
12 changed files with 81 additions and 27 deletions

View File

@ -51,6 +51,7 @@ def init(
"""Initialize OpenUpgrade Wizard Environment based on the initial and """Initialize OpenUpgrade Wizard Environment based on the initial and
the final version of Odoo you want to migrate. the final version of Odoo you want to migrate.
""" """
print(0 / 0)
# Handle arguments # Handle arguments
if extra_repository_list: if extra_repository_list:

View File

@ -28,7 +28,8 @@ def move_to_test_folder():
os.chdir(test_folder_path) os.chdir(test_folder_path)
def cli_runner_invoke(cmd): def cli_runner_invoke(ctx, cmd):
try:
result = CliRunner().invoke( result = CliRunner().invoke(
main, main,
cmd, cmd,
@ -38,6 +39,22 @@ def cli_runner_invoke(cmd):
_logger.error("exit_code: %s" % result.exit_code) _logger.error("exit_code: %s" % result.exit_code)
_logger.error("output: %s" % result.output) _logger.error("output: %s" % result.output)
assert result.exit_code == 0 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: 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["env_folder_path"] = env_folder_path
ctx.obj["src_folder_path"] = env_folder_path / Path("src") ctx.obj["src_folder_path"] = env_folder_path / Path("src")
ctx.obj["log_folder_path"] = env_folder_path / Path("log")
return ctx return ctx

View File

@ -1,14 +1,21 @@
import filecmp import filecmp
from pathlib import Path 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(): def test_cli_init():
move_to_test_folder() move_to_test_folder()
ctx = build_ctx_from_config_file()
expected_folder_path = Path("../output_expected").absolute() expected_folder_path = Path("../output_expected").absolute()
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"init", "init",
@ -17,7 +24,7 @@ def test_cli_init():
"--final-version=15.0", "--final-version=15.0",
"--extra-repository=" "--extra-repository="
"OCA/web,OCA/server-tools,OCA/bank-statement-import", "OCA/web,OCA/server-tools,OCA/bank-statement-import",
] ],
) )
assert filecmp.cmp( assert filecmp.cmp(

View File

@ -1,15 +1,22 @@
from pathlib import Path 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(): def test_cli_get_code():
move_to_test_folder() move_to_test_folder()
ctx = build_ctx_from_config_file()
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"get-code", "get-code",
] ],
) )
# Check V14 # Check V14

View File

@ -1,16 +1,23 @@
from odoo_openupgrade_wizard.tools.tools_docker import get_docker_client 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(): def test_cli_docker_build():
move_to_test_folder() move_to_test_folder()
ctx = build_ctx_from_config_file()
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"docker-build", "docker-build",
"--versions=14.0,15.0", "--versions=14.0,15.0",
] ],
) )
docker_client = get_docker_client() docker_client = get_docker_client()

View File

@ -21,6 +21,7 @@ def test_cli_run():
ensure_database(ctx, db_name, state="absent") ensure_database(ctx, db_name, state="absent")
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"run", "run",
@ -28,7 +29,7 @@ def test_cli_run():
"--database=%s" % db_name, "--database=%s" % db_name,
"--init-modules=base", "--init-modules=base",
"--stop-after-init", "--stop-after-init",
] ],
) )
# Ensure that a subfolder filestore/DB_NAME has been created # Ensure that a subfolder filestore/DB_NAME has been created

View File

@ -31,6 +31,7 @@ def test_cli_execute_script_python():
# Install Odoo on V14 with base installed # Install Odoo on V14 with base installed
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"run", "run",
@ -38,7 +39,7 @@ def test_cli_execute_script_python():
"--database=%s" % db_name, "--database=%s" % db_name,
"--init-modules=base", "--init-modules=base",
"--stop-after-init", "--stop-after-init",
] ],
) )
# Compute partners quantity # Compute partners quantity
@ -49,13 +50,14 @@ def test_cli_execute_script_python():
# Execute Custom Python Script # Execute Custom Python Script
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"execute-script-python", "execute-script-python",
"--step=1", "--step=1",
"--database=%s" % db_name, "--database=%s" % db_name,
"--script-file-path=post-migration-custom_test.py", "--script-file-path=post-migration-custom_test.py",
] ],
) )
partner_quantity_after = int( partner_quantity_after = int(
execute_sql_request(ctx, request, database=db_name)[0][0] execute_sql_request(ctx, request, database=db_name)[0][0]

View File

@ -33,12 +33,13 @@ def test_cli_execute_script_sql():
# TODO call with script-file-path # TODO call with script-file-path
# to avoid to copy file in scripts/step_xxx folder # to avoid to copy file in scripts/step_xxx folder
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"execute-script-sql", "execute-script-sql",
"--step=1", "--step=1",
"--database=%s" % db_name, "--database=%s" % db_name,
] ],
) )
# Ensure that the request has been done correctly # Ensure that the request has been done correctly

View File

@ -12,13 +12,14 @@ from . import (
def test_cli_upgrade(): def test_cli_upgrade():
move_to_test_folder() move_to_test_folder()
ctx = build_ctx_from_config_file()
# Initialize database # Initialize database
db_name = "database_test_cli___upgrade" db_name = "database_test_cli___upgrade"
ctx = build_ctx_from_config_file()
ensure_database(ctx, db_name, state="absent") ensure_database(ctx, db_name, state="absent")
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"run", "run",
@ -26,7 +27,7 @@ def test_cli_upgrade():
"--database=%s" % db_name, "--database=%s" % db_name,
"--init-modules=base", "--init-modules=base",
"--stop-after-init", "--stop-after-init",
] ],
) )
# Ensure that 'base' module is installed at 14.0 # Ensure that 'base' module is installed at 14.0
@ -41,13 +42,14 @@ def test_cli_upgrade():
assert latest_version[0][0].startswith("14.") assert latest_version[0][0].startswith("14.")
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"upgrade", "upgrade",
"--database=%s" % db_name, "--database=%s" % db_name,
"--first-step=1", "--first-step=1",
"--last-step=3", "--last-step=3",
] ],
) )
# Ensure that 'base' module is installed at 15.0 # Ensure that 'base' module is installed at 15.0

View File

@ -1,14 +1,20 @@
import unittest import unittest
from pathlib import Path 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): class TestCliEstimateWorkload(unittest.TestCase):
def test_cli_estimate_workload(self): def test_cli_estimate_workload(self):
move_to_test_folder() move_to_test_folder()
ctx = build_ctx_from_config_file()
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"estimate-workload", "estimate-workload",
@ -32,7 +38,7 @@ class TestCliEstimateWorkload(unittest.TestCase):
",web_widget_one2many_tree_line_duplicate" ",web_widget_one2many_tree_line_duplicate"
",web_widget_dropdown_dynamic_example" ",web_widget_dropdown_dynamic_example"
",my_module_that_doesnt_exist", ",my_module_that_doesnt_exist",
] ],
) )
# We check file has been created # We check file has been created

View File

@ -19,11 +19,12 @@ def test_cli_install_from_csv():
ensure_database(ctx, db_name, state="absent") ensure_database(ctx, db_name, state="absent")
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"install-from-csv", "install-from-csv",
"--database=%s" % db_name, "--database=%s" % db_name,
] ],
) )
# Ensure that 'base' is installed # Ensure that 'base' is installed

View File

@ -28,13 +28,14 @@ def test_cli_generate_module_analysis():
analysis_file_path analysis_file_path
cli_runner_invoke( cli_runner_invoke(
ctx,
[ [
"--log-level=DEBUG", "--log-level=DEBUG",
"generate-module-analysis", "generate-module-analysis",
"--step=2", "--step=2",
"--database=%s" % db_name, "--database=%s" % db_name,
"--modules=base", "--modules=base",
] ],
) )
# The file should has been recreated by the analysis command # The file should has been recreated by the analysis command