Esempio n. 1
0
File: conftest.py Progetto: em-2/em2
def pg_conn():
    settings = Settings(PG_DATABASE='test_prepare_database')
    conn = psycopg2.connect(**pg_connect_kwargs(settings))
    conn.autocommit = True
    cur = conn.cursor()
    cur.execute('DROP DATABASE IF EXISTS {}'.format(settings.PG_DATABASE))

    yield settings, cur

    cur.execute('DROP DATABASE IF EXISTS {}'.format(settings.PG_DATABASE))
    cur.close()
    conn.close()
Esempio n. 2
0
File: conftest.py Progetto: em-2/em2
def db(dsn):
    conn = psycopg2.connect(**pg_connect_kwargs(settings))
    conn.autocommit = True
    cur = conn.cursor()
    cur.execute('DROP DATABASE IF EXISTS {}'.format(settings.PG_DATABASE))
    cur.execute('CREATE DATABASE {}'.format(settings.PG_DATABASE))

    engine = sa_create_engine(dsn)
    Base.metadata.create_all(engine)

    yield engine

    engine.dispose()
    cur.execute('DROP DATABASE {}'.format(settings.PG_DATABASE))
    cur.close()
    conn.close()