示例#1
0
文件: pytest.py 项目: pumazi/cnx-db
def _db_init(db_engines):
    """Initializes the database"""
    from cnxdb.init.main import init_db
    init_db(db_engines['super'], is_venv_importable())
    if is_venv_importable():
        # We need to recreate the connection pool after initializing venv
        # because all the existing connections wouldn't have venv set up
        for engine in db_engines.values():
            engine.dispose()
示例#2
0
文件: pytest.py 项目: openstax/cnx-db
def _db_init(db_engines):
    """Initializes the database"""
    from cnxdb.init.main import init_db
    init_db(db_engines['super'], is_venv_importable())
    if is_venv_importable():
        # We need to recreate the connection pool after initializing venv
        # because all the existing connections wouldn't have venv set up
        for engine in db_engines.values():
            engine.dispose()
示例#3
0
def test_db_init_called_twice(connection_string):
    from cnxdb.init.main import init_db
    init_db(connection_string)

    from cnxdb.init.exceptions import DBSchemaInitialized
    try:
        init_db(connection_string)
    except DBSchemaInitialized as exc:
        pass
    else:
        assert False, "the initialization check failed"
示例#4
0
def test_db_init_called_twice(db_engines):
    from cnxdb.init.main import init_db
    init_db(db_engines['super'])

    from cnxdb.init.exceptions import DBSchemaInitialized
    try:
        init_db(db_engines['super'])
    except DBSchemaInitialized:
        pass
    else:
        assert False, "the initialization check failed"
示例#5
0
def test_db_init_with_venv(connection_string):
    from cnxdb.init.main import init_db
    init_db(connection_string, True)

    with psycopg2.connect(connection_string) as conn:
        with conn.cursor() as cursor:
            cursor.execute("CREATE FUNCTION pyprefix() RETURNS text LANGUAGE "
                           "plpythonu AS $$import sys;return sys.prefix$$")
            cursor.execute("SELECT pyprefix()")
            db_pyprefix = cursor.fetchone()[0]

    assert os.path.samefile(db_pyprefix, sys.prefix)
示例#6
0
def test_db_init(db_engines):
    from cnxdb.init.main import init_db
    init_db(db_engines['super'])

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

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

    assert 'modules' in tables
    assert 'pending_documents' in tables
示例#7
0
def test_db_init_with_venv(db_engines):
    from cnxdb.init.main import init_db
    init_db(db_engines['super'], True)

    db_engines['common'].dispose()  # dispose of any previous connections
    conn = db_engines['common'].raw_connection()
    with conn.cursor() as cursor:
        cursor.execute("CREATE FUNCTION pyprefix() RETURNS text LANGUAGE "
                       "plpythonu AS $$import sys;return sys.prefix$$")
        cursor.execute("SELECT pyprefix()")
        db_pyprefix = cursor.fetchone()[0]
    conn.close()

    assert os.path.samefile(db_pyprefix, sys.prefix)
示例#8
0
def test_db_init(connection_string):
    from cnxdb.init.main import init_db
    init_db(connection_string)

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

    with psycopg2.connect(connection_string) 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
示例#9
0
def db_init(connection_string):
    """Initializes the database"""
    from cnxdb.init.main import init_db
    init_db(connection_string, True)