[IMP] add new assert_database test function and harmonize tests for restoredb, copydb, dropdb
This commit is contained in:
parent
8016b35624
commit
c345d831bc
|
|
@ -7,6 +7,7 @@ from click.testing import CliRunner
|
|||
from plumbum.cmd import mkdir
|
||||
|
||||
from odoo_openupgrade_wizard.cli.cli import main
|
||||
from odoo_openupgrade_wizard.tools.tools_postgres import execute_sql_request
|
||||
|
||||
_logger = logging.getLogger()
|
||||
|
||||
|
|
@ -91,3 +92,12 @@ def mock_odoo_rpc_url(mocker):
|
|||
"odoo_openupgrade_wizard.tools.tools_odoo_instance._ODOO_RPC_URL",
|
||||
odoo_rpc_url,
|
||||
)
|
||||
|
||||
|
||||
def assert_database(ctx, db_name, state):
|
||||
request = "select datname FROM pg_database WHERE datistemplate = false;"
|
||||
results = execute_sql_request(ctx, request)
|
||||
if state == "present":
|
||||
assert [db_name] in results
|
||||
else:
|
||||
assert [db_name] not in results
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import shutil
|
|||
from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database
|
||||
|
||||
from . import (
|
||||
assert_database,
|
||||
build_ctx_from_config_file,
|
||||
cli_runner_invoke,
|
||||
mock_odoo_rpc_url,
|
||||
|
|
@ -45,5 +46,9 @@ def test_cli_restoredb(mocker):
|
|||
# check filestore exists
|
||||
assert dest_filestore_path.exists()
|
||||
|
||||
# Delete filestore
|
||||
# Check database exists
|
||||
assert_database(ctx, db_name, "present")
|
||||
|
||||
# Delete filestore and database
|
||||
shutil.rmtree(dest_filestore_path)
|
||||
ensure_database(ctx, db_name, state="absent")
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import shutil
|
|||
from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database
|
||||
|
||||
from . import (
|
||||
assert_database,
|
||||
build_ctx_from_config_file,
|
||||
cli_runner_invoke,
|
||||
mock_odoo_rpc_url,
|
||||
|
|
@ -46,5 +47,9 @@ def test_cli_copydb(mocker):
|
|||
# check filestore exists
|
||||
assert dest_filestore_path.exists()
|
||||
|
||||
# Delete filestore
|
||||
# Check database exists
|
||||
assert_database(ctx, db_dest_name, "present")
|
||||
|
||||
# Delete filestore and database
|
||||
shutil.rmtree(dest_filestore_path)
|
||||
ensure_database(ctx, db_dest_name, state="absent")
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import pathlib
|
||||
import shutil
|
||||
|
||||
from odoo_openupgrade_wizard.tools.tools_postgres import (
|
||||
ensure_database,
|
||||
execute_sql_request,
|
||||
)
|
||||
from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database
|
||||
|
||||
from . import (
|
||||
assert_database,
|
||||
build_ctx_from_config_file,
|
||||
cli_runner_invoke,
|
||||
mock_odoo_rpc_url,
|
||||
|
|
@ -45,9 +43,7 @@ def test_cli_dropdb(mocker):
|
|||
)
|
||||
|
||||
# Check database does not exists
|
||||
request = "select datname FROM pg_database WHERE datistemplate = false;"
|
||||
results = execute_sql_request(ctx, request)
|
||||
assert [db_name] not in results
|
||||
assert_database(ctx, db_name, "absent")
|
||||
|
||||
# Check filestore does not exists
|
||||
assert not filestore_path.exists()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user