def main(): database_url = os.environ.get("DATABASE_URL", None) engine = create_engine(database_url) DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: for post in get_posts(): populate_db(post)
def main(): database_url = os.environ.get('DATABASE_URL', None) engine = create_engine(database_url) DBSession.configure(bind=engine) Base.metadata.create_all(engine) with transaction.manager: for entry in import_entries(): populate_db(entry)
def sqlengine(request): engine = create_engine(TEST_DATABASE_URL) DBSession.configure(bind=engine) Base.metadata.create_all(engine) def teardown(): Base.metadata.drop_all(engine) request.addfinalizer(teardown) return engine
def dbtransaction(request, sqlengine): connection = sqlengine.connect() transaction = connection.begin() DBSession.configure(bind=connection, expire_on_commit=False) def teardown(): transaction.rollback() connection.close() DBSession.remove() request.addfinalizer(teardown) return connection
def sqlengine(request): """Takes care of connection to DB.""" engine = create_engine(TESTDB_URL) Base.metadata.create_all(engine) connection = engine.connect() DBSession.configure(bind=connection) def teardown(): Base.metadata.drop_all(engine) request.addfinalizer(teardown) return connection
def sqlengine(request): """Takes care of connection to DB.""" engine = create_engine(TESTDB_URL) Base.metadata.create_all(engine) connection = engine.connect() DBSession.configure(bind=connection) def teardown(): Base.metadata.drop_all(engine) request.addfinalizer(teardown) return connection
def dbtransaction(request, sqlengine): connection = sqlengine.connect() transaction = connection.begin() DBSession.configure(bind=connection) entry = Entry(title="testing 1", text="this is a test") DBSession.add(entry) DBSession.flush() def teardown(): transaction.rollback() connection.close() DBSession.remove() request.addfinalizer(teardown) return connection
def create_session(): from sqlalchemy import create_engine database_url = os.environ.get('DATABASE_URL', None) engine = create_engine(database_url) DBSession.configure(bind=engine) Base.metadata.create_all(engine)