コード例 #1
0
ファイル: fixtures.py プロジェクト: cgnkev/inyoka-legacy
def create_db(connection):
    """Creates the test database tables."""
    driver = connection.engine.name
    if driver == 'sqlite':
        return create_sqlite_db(connection)

    # Create the test database and connect to it. We need to autocommit
    # if the database supports it because PostgreSQL doesn't allow
    # CREATE/DROP DATABASE statements within transactions.
    def _execute(sql, *args, **kwargs):
        engine = _get_admin_connection(connection)
        engine.execute(
            text(sql).execution_options(autocommit=True), *args, **kwargs)

    test_database_name = connection.engine.url.database

    try:
        _execute('CREATE DATABASE %s' % test_database_name)
    except Exception as exc:
        logger.warning('Got an error creating the test database: %s\n' % exc)
        logger.info('Destroying old test database "%s"...' %
                    unicode(connection.engine.url))
        try:
            _execute('DROP DATABASE %s' % test_database_name)
            _execute('CREATE DATABASE %s' % test_database_name)
        except Exception as exc:
            logger.warning('Got an error recreating the test database: %s\n' %
                           exc)

    return test_database_name
コード例 #2
0
ファイル: fixtures.py プロジェクト: EnTeQuAk/inyoka-legacy
def create_db(connection):
    """Creates the test database tables."""
    driver = connection.engine.name
    if driver == 'sqlite':
        return create_sqlite_db(connection)

    # Create the test database and connect to it. We need to autocommit
    # if the database supports it because PostgreSQL doesn't allow
    # CREATE/DROP DATABASE statements within transactions.
    def _execute(sql, *args, **kwargs):
        engine = _get_admin_connection(connection)
        engine.execute(text(sql).execution_options(autocommit=True), *args, **kwargs)

    test_database_name = connection.engine.url.database

    try:
        _execute('CREATE DATABASE %s' % test_database_name)
    except Exception as exc:
        logger.warning('Got an error creating the test database: %s\n' % exc)
        logger.info('Destroying old test database "%s"...' % unicode(connection.engine.url))
        try:
            _execute('DROP DATABASE %s' % test_database_name)
            _execute('CREATE DATABASE %s' % test_database_name)
        except Exception as exc:
            logger.warning('Got an error recreating the test database: %s\n' % exc)

    return test_database_name
コード例 #3
0
ファイル: fixtures.py プロジェクト: EnTeQuAk/inyoka-legacy
def destroy_sqlite_db(connection):
    test_database_name = connection.engine.url.database
    if test_database_name and test_database_name != ":memory:":
        # Remove the SQLite database file
        if os.access(test_database_name, os.F_OK):
            try:
                os.remove(test_database_name)
            except Exception as exc:
                logger.warning('Got an error deleting the test database: %s\n' % exc)
    return test_database_name
コード例 #4
0
ファイル: fixtures.py プロジェクト: cgnkev/inyoka-legacy
def destroy_sqlite_db(connection):
    test_database_name = connection.engine.url.database
    if test_database_name and test_database_name != ":memory:":
        # Remove the SQLite database file
        if os.access(test_database_name, os.F_OK):
            try:
                os.remove(test_database_name)
            except Exception as exc:
                logger.warning(
                    'Got an error deleting the test database: %s\n' % exc)
    return test_database_name
コード例 #5
0
ファイル: fixtures.py プロジェクト: EnTeQuAk/inyoka-legacy
def create_sqlite_db(connection):
    test_database_name = connection.engine.url.database
    if not test_database_name:
        test_database_name = ':memory:'

    if test_database_name != ':memory:':
        # Erase the old test database
        logger.info('Destroying old test database "%s"...' % unicode(connection.engine.url))
        if os.access(test_database_name, os.F_OK):
            try:
                os.remove(test_database_name)
            except Exception as exc:
                logger.warning('Got an error deleting the old test database: %s\n' % exc)
    return test_database_name
コード例 #6
0
ファイル: fixtures.py プロジェクト: cgnkev/inyoka-legacy
def create_sqlite_db(connection):
    test_database_name = connection.engine.url.database
    if not test_database_name:
        test_database_name = ':memory:'

    if test_database_name != ':memory:':
        # Erase the old test database
        logger.info('Destroying old test database "%s"...' %
                    unicode(connection.engine.url))
        if os.access(test_database_name, os.F_OK):
            try:
                os.remove(test_database_name)
            except Exception as exc:
                logger.warning(
                    'Got an error deleting the old test database: %s\n' % exc)
    return test_database_name