Example #1
0
def connection(request):
    from encoded import configure_engine
    from encoded.storage import Base, DBSession
    from sqlalchemy.orm.scoping import ScopedRegistry

    # ``server`` thread must be in same scope
    if type(DBSession.registry) is not ScopedRegistry:
        DBSession.registry = ScopedRegistry(DBSession.session_factory, lambda: 0)

    engine_settings = {
        'sqlalchemy.url': request.session.config.option.engine_url,
    }

    engine = configure_engine(engine_settings, test_setup=True)
    connection = engine.connect()
    tx = connection.begin()
    try:
        Base.metadata.create_all(bind=connection)
        session = DBSession(scope=None, bind=connection)
        DBSession.registry.set(session)
        yield connection
    finally:
        tx.rollback()
        connection.close()
        engine.dispose()
Example #2
0
def connection(request, engine_url):
    from encoded import configure_engine
    from encoded.storage import Base, DBSession
    from sqlalchemy.orm.scoping import ScopedRegistry

    # ``server`` thread must be in same scope
    if type(DBSession.registry) is not ScopedRegistry:
        DBSession.registry = ScopedRegistry(DBSession.session_factory,
                                            lambda: 0)

    engine_settings = {
        'sqlalchemy.url': engine_url,
    }

    engine = configure_engine(engine_settings, test_setup=True)
    connection = engine.connect()
    tx = connection.begin()
    try:
        Base.metadata.create_all(bind=connection)
        session = DBSession(scope=None, bind=connection)
        DBSession.registry.set(session)
        yield connection
    finally:
        tx.rollback()
        connection.close()
        engine.dispose()
Example #3
0
def connection_factory(config, name):
    from encoded import configure_engine
    from encoded.storage import Base, DBSession
    from sqlalchemy.orm.scoping import ScopedRegistry

    scopefunc = config.pluginmanager.getplugin('data').scopefunc

    if type(DBSession.registry) is not ScopedRegistry:
        DBSession.registry = ScopedRegistry(DBSession.session_factory, scopefunc)

    engine_settings = {
        'sqlalchemy.url': config.option.engine_url,
    }

    engine = configure_engine(engine_settings, test_setup=True)
    connection = engine.connect()
    tx = connection.begin()
    try:
        if engine.url.drivername == 'postgresql':
            # Create the different test sets in different schemas
            if name is None:
                schema_name = 'tests'
            else:
                schema_name = 'tests_%s' % name
            connection.execute('CREATE SCHEMA %s' % schema_name)
            connection.execute('SET search_path TO %s,public' % schema_name)
        Base.metadata.create_all(bind=connection)
        session = DBSession(scope=None, bind=connection)
        DBSession.registry.set(session)
        yield connection
    finally:
        tx.rollback()
        connection.close()
        engine.dispose()
Example #4
0
def connection_factory(config, name):
    from encoded import configure_engine
    from encoded.storage import Base, DBSession
    from sqlalchemy.orm.scoping import ScopedRegistry

    scopefunc = config.pluginmanager.getplugin('data').scopefunc

    if type(DBSession.registry) is not ScopedRegistry:
        DBSession.registry = ScopedRegistry(DBSession.session_factory,
                                            scopefunc)

    engine_settings = {
        'sqlalchemy.url': config.option.engine_url,
    }

    engine = configure_engine(engine_settings, test_setup=True)
    connection = engine.connect()
    tx = connection.begin()
    try:
        if engine.url.drivername == 'postgresql':
            # Create the different test sets in different schemas
            if name is None:
                schema_name = 'tests'
            else:
                schema_name = 'tests_%s' % name
            connection.execute('CREATE SCHEMA %s' % schema_name)
            connection.execute('SET search_path TO %s,public' % schema_name)
        Base.metadata.create_all(bind=connection)
        session = DBSession(scope=None, bind=connection)
        DBSession.registry.set(session)
        yield connection
    finally:
        tx.rollback()
        connection.close()
        engine.dispose()
Example #5
0
def connection(engine_url):
    from encoded import configure_engine
    from contentbase.storage import Base

    engine_settings = {
        'sqlalchemy.url': engine_url,
    }

    engine = configure_engine(engine_settings)
    connection = engine.connect()
    tx = connection.begin()
    try:
        Base.metadata.create_all(bind=connection)
        yield connection
    finally:
        tx.rollback()
        connection.close()
        engine.dispose()
Example #6
0
def connection(engine_url):
    from encoded import configure_engine
    from snovault.storage import Base

    engine_settings = {
        'sqlalchemy.url': engine_url,
    }

    engine = configure_engine(engine_settings)
    connection = engine.connect()
    tx = connection.begin()
    try:
        Base.metadata.create_all(bind=connection)
        yield connection
    finally:
        tx.rollback()
        connection.close()
        engine.dispose()