Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/tests/test_cli.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from click.testing import CliRunner | from click.testing import CliRunner | ||||
import psycopg2 | |||||
import pytest | import pytest | ||||
from swh.core.cli import swh as swhmain | from swh.core.cli import swh as swhmain | ||||
import swh.core.cli.db # noqa ; ensure cli is loaded | import swh.core.cli.db # noqa ; ensure cli is loaded | ||||
from swh.core.db import BaseDb | |||||
import swh.provenance.cli # noqa ; ensure cli is loaded | import swh.provenance.cli # noqa ; ensure cli is loaded | ||||
def test_cli_swh_db_help(): | def test_cli_swh_db_help(): | ||||
# swhmain.add_command(provenance_cli) | # swhmain.add_command(provenance_cli) | ||||
result = CliRunner().invoke(swhmain, ["provenance", "-h"]) | result = CliRunner().invoke(swhmain, ["provenance", "-h"]) | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
assert "Commands:" in result.output | assert "Commands:" in result.output | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | ): | ||||
# DB init using 'swh db init' | # DB init using 'swh db init' | ||||
result = CliRunner().invoke( | result = CliRunner().invoke( | ||||
swhmain, ["db", "init", "-d", dbname, "--flavor", flavor, "provenance"] | swhmain, ["db", "init", "-d", dbname, "--flavor", flavor, "provenance"] | ||||
) | ) | ||||
assert result.exit_code == 0, result.output | assert result.exit_code == 0, result.output | ||||
assert f"(flavor {flavor})" in result.output | assert f"(flavor {flavor})" in result.output | ||||
db_params["dbname"] = dbname | db_params["dbname"] = dbname | ||||
cnx = psycopg2.connect(**db_params) | cnx = BaseDb.connect(**db_params).conn | ||||
# check the DB looks OK (check for db_flavor and expected tables) | # check the DB looks OK (check for db_flavor and expected tables) | ||||
with cnx.cursor() as cur: | with cnx.cursor() as cur: | ||||
cur.execute("select swh_get_dbflavor()") | cur.execute("select swh_get_dbflavor()") | ||||
assert cur.fetchone() == (flavor,) | assert cur.fetchone() == (flavor,) | ||||
cur.execute( | cur.execute( | ||||
"select table_name from information_schema.tables " | "select table_name from information_schema.tables " | ||||
"where table_schema = 'public' " | "where table_schema = 'public' " | ||||
Show All 15 Lines |