def empty_session(): engine = create_engine(TEST_DATABASE_URI_IN_MEMORY) metadata.create_all(engine) for table in reversed(metadata.sorted_tables): engine.execute(table.delete()) map_model_to_tables() session_factory = sessionmaker(bind=engine) yield session_factory() metadata.drop_all(engine) clear_mappers()
def database_engine(): engine = create_engine(TEST_DATABASE_URI_FILE) clear_mappers() metadata.create_all(engine) # Conditionally create database tables. for table in reversed(metadata.sorted_tables): # Remove any data from the tables. engine.execute(table.delete()) map_model_to_tables() database_repository.populate(engine, TEST_DATA_PATH_DATABASE_REPO) yield engine metadata.drop_all(engine) clear_mappers()
def session_factory(): clear_mappers() engine = create_engine(TEST_DATABASE_URI_IN_MEMORY) metadata.create_all(engine) for table in reversed(metadata.sorted_tables): engine.execute(table.delete()) map_model_to_tables() session_factory = sessionmaker(bind=engine) database_repository.populate(engine, TEST_DATA_PATH_DATABASE_REPO) yield session_factory metadata.drop_all(engine) clear_mappers()
def database_engine(): session_factory = sessionmaker(autocommit=False, autoflush=True, bind=database_engine) engine = create_engine(TEST_DATABASE_URI_FILE) clear_mappers() metadata.create_all(engine) # Conditionally create database tables. for table in reversed(metadata.sorted_tables): # Remove any data from the tables. engine.execute(table.delete()) map_model_to_tables() database_repository.populate(session_factory, TEST_DATA_PATH_DATABASE) yield engine metadata.drop_all(engine) clear_mappers()