예제 #1
0
def _db_dsn(request):
    name = "test_{}".format(uuid.uuid4().hex)
    pg_dsn = "postgresql://*****:*****@postgres:5432/postgres"
    db_dsn = "postgresql://*****:*****@postgres:5432/{}".format(name)

    pg_engine = sqlalchemy.create_engine(pg_dsn)
    pg_engine.raw_connection().set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
    pg_engine.execute("CREATE DATABASE {0}".format(name))
    pg_engine.dispose()

    db_engine = sqlalchemy.create_engine(db_dsn)
    setup_db(db_engine)
    db_engine.dispose()

    def fin():
        pg_engine = sqlalchemy.create_engine(pg_dsn)
        pg_engine.raw_connection().set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
        pg_engine.execute("DROP DATABASE {0}".format(name))
        pg_engine.dispose()

    request.addfinalizer(fin)
    return db_dsn
예제 #2
0
def db_dsn_fixture(request):
    name = 'test_{}'.format(uuid.uuid4().hex)
    pg_dsn = 'postgresql://*****:*****@postgres:5432/postgres'
    db_dsn = 'postgresql://*****:*****@postgres:5432/{}'.format(name)

    pg_engine = sqlalchemy.create_engine(pg_dsn)
    pg_engine.raw_connection()\
        .set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
    pg_engine.execute('CREATE DATABASE {0}'.format(name))
    pg_engine.dispose()

    db_engine = sqlalchemy.create_engine(db_dsn)
    setup_db(db_engine)
    db_engine.dispose()

    def fin():
        pg_engine = sqlalchemy.create_engine(pg_dsn)
        pg_engine.raw_connection() \
            .set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
        pg_engine.execute('DROP DATABASE {0}'.format(name))
        pg_engine.dispose()

    request.addfinalizer(fin)
    return db_dsn
예제 #3
0
파일: console.py 프로젝트: vmagamedov/hiku
from wsgiref.simple_server import make_server

from sqlalchemy import create_engine
from sqlalchemy.pool import StaticPool

from hiku.engine import Engine
from hiku.sources import sqlalchemy as sa
from hiku.console.ui import ConsoleApplication
from hiku.executors.sync import SyncExecutor

from tests.test_source_sqlalchemy import SA_ENGINE_KEY, SyncQueries, setup_db
from tests.test_source_sqlalchemy import get_queries, get_graph


if __name__ == '__main__':
    engine = Engine(SyncExecutor())

    sa_engine = create_engine(
        'sqlite://',
        connect_args={'check_same_thread': False},
        poolclass=StaticPool,
    )
    setup_db(sa_engine)

    graph = get_graph(sa, get_queries(sa, SA_ENGINE_KEY, SyncQueries))

    app = ConsoleApplication(graph, engine, {SA_ENGINE_KEY: sa_engine},
                             debug=True)
    http_server = make_server('localhost', 5000, app)
    http_server.serve_forever()
예제 #4
0
    try:
        query = read(data['query'], data.get('variables'))
        errors = validate(app.config['GRAPH'], query)
        if errors:
            result = {'errors': [{'message': e} for e in errors]}
        else:
            result = hiku_engine.execute(app.config['GRAPH'],
                                         query,
                                         ctx=app.config['HIKU_CTX'])
            result = {'data': denormalize(app.config['GRAPH'], result, query)}
    except Exception as err:
        result = {'errors': [{'message': repr(err)}]}
    return jsonify(result)


if __name__ == "__main__":
    sa_engine = create_engine('sqlite://',
                              connect_args={'check_same_thread': False},
                              poolclass=StaticPool)
    setup_db(sa_engine)

    app.config['HIKU_ENGINE'] = Engine(SyncExecutor())
    app.config['HIKU_CTX'] = {SA_ENGINE_KEY: sa_engine}

    graph = get_graph(get_queries(hiku.sources.sqlalchemy, SA_ENGINE_KEY,
                                  SyncQueries))
    graph = apply(graph, [GraphQLIntrospection()])
    app.config['GRAPH'] = graph

    app.run()