cli_runner = <click.testing.CliRunner object at 0x7fb746b65908>
postgresql = <connection object at 0x7fb748b30a48; dsn: 'user=postgres password=xxx dbname=tests host=127.0.0.1 port=28141 options=''', closed: 0>
mock_package_sql = <function mock_package_sql.<locals>.get_sql_for_package_mock at 0x7fb746a4c048>
mocker = <pytest_mock.plugin.MockerFixture object at 0x7fb746b62320>
tmp_path = PosixPath('/tmp/pytest-of-jenkins/pytest-0/test_cli_swh_db_create_and_ini0')
def test_cli_swh_db_create_and_init_db_new_api(
cli_runner, postgresql, mock_package_sql, mocker, tmp_path
):
"""Create a db then initializing it should be ok for a "new style" datastore
"""
module_name = "test.cli_new"
from unittest.mock import MagicMock
from swh.core.db.db_utils import import_swhmodule
def import_swhmodule_mock(modname):
if modname.startswith("test."):
def get_datastore(cls, **kw):
# XXX probably not the best way of doing this...
return MagicMock(get_current_version=lambda: 42)
return MagicMock(name=modname, get_datastore=get_datastore)
return import_swhmodule(modname)
mocker.patch("swh.core.db.db_utils.import_swhmodule", import_swhmodule_mock)
conninfo = craft_conninfo(postgresql)
# This initializes the schema and data
cfgfile = tmp_path / "config.yml"
cfgfile.write_text(
f"""
{module_name}:
cls: postgresql
db: {conninfo}
"""
)
result = cli_runner.invoke(swhdb, ["init-admin", module_name, "--dbname", conninfo])
assert result.exit_code == 0, f"Unexpected output: {result.output}"
result = cli_runner.invoke(swhdb, ["-C", cfgfile, "init", module_name])
import traceback
assert (
result.exit_code == 0
), f"Unexpected output: {traceback.print_tb(result.exc_info[2])}"
# the origin value in the scripts uses a hash function (which implementation wise
# uses a function from the pgcrypt extension, installed during db creation step)
with BaseDb.connect(conninfo).cursor() as cur:
> cur.execute("select * from origin")
E psycopg2.errors.UndefinedTable: relation "origin" does not exist
E LINE 1: select * from origin
E ^
.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/test_cli.py:263: UndefinedTable
TEST RESULT
TEST RESULT
- Run At
- Feb 2 2022, 2:54 PM