Changeset View
Changeset View
Standalone View
Standalone View
swh/core/db/tests/test_cli.py
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | def test_cli_swh_db_upgrade_new_api(cli_runner, postgresql, datadir, mocker, tmp_path): | ||||
result = cli_runner.invoke(swhdb, ["-C", cfgfile, "upgrade", module_name]) | result = cli_runner.invoke(swhdb, ["-C", cfgfile, "upgrade", module_name]) | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
assert "Warning: the database does not have a dbmodule table." in result.output | assert "Warning: the database does not have a dbmodule table." in result.output | ||||
assert ( | assert ( | ||||
"Write the module information (test.cli_new) in the database? [Y/n]" | "Write the module information (test.cli_new) in the database? [Y/n]" | ||||
in result.output | in result.output | ||||
) | ) | ||||
assert swh_db_module(conninfo) == module_name | assert swh_db_module(conninfo) == module_name | ||||
def test_cli_swh_db_version(swh_db_cli, mock_import_swhmodule, postgresql): | |||||
module_name = "test.cli" | |||||
cli_runner, db_params = swh_db_cli | |||||
conninfo = craft_conninfo(postgresql, "test-db-version") | |||||
# This creates the db and installs the necessary admin extensions | |||||
result = cli_runner.invoke(swhdb, ["create", module_name, "--dbname", conninfo]) | |||||
assert result.exit_code == 0, f"Unexpected output: {result.output}" | |||||
# This initializes the schema and data | |||||
result = cli_runner.invoke(swhdb, ["init", module_name, "--dbname", conninfo]) | |||||
db = BaseDb.connect(conninfo) | |||||
with db.cursor() as cur: | |||||
cur.execute("select version from dbversion order by dbversion desc limit 1") | |||||
expected_version = cur.fetchone()[0] | |||||
assert db.get_current_version() == expected_version | |||||
assert result.exit_code == 0, f"Unexpected output: {result.output}" | |||||
assert f"initialized at version {expected_version}" in result.output |