Example #1
0
def test_init_without_user(connection_string_parts):
    from cnxdb.cli.main import main
    args = ['init'] + _translate_parts_to_args(connection_string_parts)[:6]

    with pytest.raises(SystemExit) as exc_info:
        main(args)
    assert exc_info.value.code == 2
Example #2
0
def test_init_without_dbname(connection_string_parts):
    from cnxdb.cli.main import main
    args = ['init']
    args.extend(_translate_parts_to_args(connection_string_parts)[:4])
    args.extend(_translate_parts_to_args(connection_string_parts)[6:])

    with pytest.raises(SystemExit) as exc_info:
        main(args)
    assert exc_info.value.code == 2
Example #3
0
def test_init_called_twice(capsys, db_env_vars):
    from cnxdb.cli.main import main
    args = ['init']

    return_code = main(args)
    assert return_code == 0

    return_code = main(args)
    assert return_code == 3
    out, err = capsys.readouterr()
    assert 'already initialized' in err
Example #4
0
def test_init_called_twice(capsys, connection_string_parts):
    from cnxdb.cli.main import main
    args = ['init'] + _translate_parts_to_args(connection_string_parts)

    return_code = main(args)
    assert return_code == 0

    return_code = main(args)
    assert return_code == 3
    out, err = capsys.readouterr()
    assert 'already initialized' in err
Example #5
0
def test_venv_called_twice(connection_string_parts):
    # Note, the initialization already setup the venv,
    # so this really calles 3 times.
    from cnxdb.cli.main import main
    args = ['venv'] + _translate_parts_to_args(connection_string_parts)

    return_code = main(args)
    assert return_code == 0

    return_code = main(args)
    assert return_code == 0

    assert_venv_is_active(connection_string_parts)
Example #6
0
def test_venv_called_twice(db_env_vars, db_engines):
    # Note, the initialization already setup the venv,
    # so this really calles 3 times.
    from cnxdb.cli.main import main
    args = ['venv']

    return_code = main(args)
    assert return_code == 0

    return_code = main(args)
    assert return_code == 0

    assert_venv_is_active(db_engines)
Example #7
0
def test_init_without_env_vars(capsys, mocker):
    mocker.patch.dict('os.environ', {}, clear=True)

    from cnxdb.cli.main import main
    args = ['init']

    return_code = main(args)
    assert return_code == 4

    expected_msg = ("'DB_URL' environment variable "
                    "OR the 'db.common.url' setting MUST be defined\n")
    assert expected_msg in capsys.readouterr()
Example #8
0
def test_init(db_env_vars, db_engines):
    from cnxdb.cli.main import main
    args = ['init']
    return_code = main(args)

    assert return_code == 0

    inspector = Inspector.from_engine(db_engines['common'])
    tables = inspector.get_table_names()

    assert 'modules' in tables
    assert 'pending_documents' in tables
Example #9
0
def test_venv(connection_string_parts):
    # Remove the venv schema before trying to initialize it.
    with psycopg2.connect(**connection_string_parts) as conn:
        with conn.cursor() as cursor:
            cursor.execute("DROP SCHEMA venv CASCADE")

    from cnxdb.cli.main import main
    args = ['venv'] + _translate_parts_to_args(connection_string_parts)

    return_code = main(args)
    assert return_code == 0

    assert_venv_is_active(connection_string_parts)
Example #10
0
def test_venv(db_env_vars, db_engines):
    # Remove the venv schema before trying to initialize it.
    conn = db_engines['super'].raw_connection()
    with conn.cursor() as cursor:
        cursor.execute("DROP SCHEMA venv CASCADE")
    conn.commit()
    conn.close()

    from cnxdb.cli.main import main
    args = ['venv']

    return_code = main(args)
    assert return_code == 0

    assert_venv_is_active(db_engines)
Example #11
0
def test_init(connection_string_parts):
    from cnxdb.cli.main import main
    args = ['init'] + _translate_parts_to_args(connection_string_parts)
    return_code = main(args)

    assert return_code == 0

    def table_name_filter(table_name):
        return (not table_name.startswith('pg_')
                and not table_name.startswith('_pg_'))

    with psycopg2.connect(**connection_string_parts) as conn:
        with conn.cursor() as cursor:
            cursor.execute("SELECT table_name "
                           "FROM information_schema.tables "
                           "ORDER BY table_name")
            tables = [
                table_name for (table_name, ) in cursor.fetchall()
                if table_name_filter(table_name)
            ]

    assert 'modules' in tables
    assert 'pending_documents' in tables
Example #12
0
def test_init_local(connection_string_parts):
    from cnxdb.cli.main import main
    args = ['init'] + _translate_parts_to_args(connection_string_parts)[4:]

    return_code = main(args)
    assert return_code == 0