odoo-openupgrade-wizard/tests/cli_05_execute_script_python_test.py
2022-06-27 01:57:31 +02:00

59 lines
1.5 KiB
Python

from pathlib import Path
from plumbum.cmd import cp
from odoo_openupgrade_wizard.tools.tools_postgres import execute_sql_request
from . import (
build_ctx_from_config_file,
cli_runner_invoke,
move_to_test_folder,
)
def test_cli_execute_script_python():
move_to_test_folder()
extra_script_path = Path("../extra_script/click_odoo_test.py").absolute()
cp(
extra_script_path,
Path("click_odoo_test.py"),
)
db_name = "database_test_cli___execute_script_python"
# Install Odoo on V13 with base installed
cli_runner_invoke(
[
"--log-level=DEBUG",
"run",
"--step=1",
"--database=%s" % db_name,
"--init-modules=base",
"--stop-after-init",
]
)
# Compute partners quantity
ctx = build_ctx_from_config_file()
request = "SELECT count(*)" " FROM res_partner;"
partner_quantity_before = int(
execute_sql_request(ctx, request, database=db_name)[0][0]
)
# Execute Custom Python Script
cli_runner_invoke(
[
"--log-level=DEBUG",
"execute-script-python",
"--step=1",
"--database=%s" % db_name,
"--script-file-path=click_odoo_test.py",
]
)
partner_quantity_after = int(
execute_sql_request(ctx, request, database=db_name)[0][0]
)
# Ensure that partners have been created by click_odoo_test.py
assert partner_quantity_after == (partner_quantity_before + 10)