本文整理汇总了Python中autonomie_base.models.base.DBSESSION.configure方法的典型用法代码示例。如果您正苦于以下问题:Python DBSESSION.configure方法的具体用法?Python DBSESSION.configure怎么用?Python DBSESSION.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autonomie_base.models.base.DBSESSION
的用法示例。
在下文中一共展示了DBSESSION.configure方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connection
# 需要导入模块: from autonomie_base.models.base import DBSESSION [as 别名]
# 或者: from autonomie_base.models.base.DBSESSION import configure [as 别名]
def connection(request, settings):
""" sets up a SQLAlchemy engine and returns a connection
to the database.
:param settings: the settings of the test (given by the testing fixture)
:returns: a sqlalchemy connection object
"""
# the following setup is based on `kotti.resources.initialize_sql`,
# except that it explicitly binds the session to a specific connection
# enabling us to use savepoints independent from the orm, thus allowing
# to `rollback` after using `transaction.commit`...
initialize_test_database(settings)
from autonomie_base.models.base import DBSESSION, DBBASE
engine = engine_from_config(settings, prefix='sqlalchemy.')
_connection = engine.connect()
DBSESSION.registry.clear()
DBSESSION.configure(bind=_connection)
DBBASE.metadata.bind = engine
def drop_db():
"""
drop the test database
"""
print("DROPPING DB")
if __current_test_ini_file().endswith('travis.ini'):
return
db_settings = get_test_options_from_settings(settings)
launch_cmd(db_settings['drop'])
request.addfinalizer(drop_db)
return _connection