def isolated_app(app): """ Flask application with demosite data and with database isolation: db transactions performed during the tests are not persisted into the db, because transactions are rolled back on tear down. Inspired by: https://goo.gl/31EKXq Note: creating an isolated app without the demosite is challenging, see: https://its.cern.ch/jira/browse/INSPIR-425 Note: the order of execution between the `app` fixture (session-scoped) and the `isolated_app` fixture should not matter. Some work to investigate that was done here: https://github.com/turtle321/inspire-next/commit/a3575c4f59890d274e7b5fcdfdaeac9685d0a755 """ original_session = db.session connection = db.engine.connect() transaction = connection.begin() db.session.begin_nested() # Custom attribute to mark the session as isolated. db.session._is_isolated = True @sqlalchemy.event.listens_for(db.session, 'after_transaction_end') def restart_savepoint(session, transaction): if transaction.nested and not transaction._parent.nested and \ getattr(db.session, '_is_isolated', False): session.expire_all() session.begin_nested() yield app db.session._is_isolated = False db.session.close() transaction.rollback() connection.close() db.session = original_session invenio_records_factory_cleanup()
def isolated_app(app): """ Flask application with demosite data and with database isolation: db transactions performed during the tests are not persisted into the db, because transactions are rolled back on tear down. Inspired by: https://goo.gl/31EKXq Note: creating an isolated app without the demosite is challenging, see: https://its.cern.ch/jira/browse/INSPIR-425 Note: the order of execution between the `app` fixtures (session-scoped) and the `isolated_app` fixtures should not matter. Some work to investigate that was done here: https://github.com/turtle321/inspire-next/commit/a3575c4f59890d274e7b5fcdfdaeac9685d0a755 """ original_session = db.session connection = db.engine.connect() transaction = connection.begin() db.session.begin_nested() # Custom attribute to mark the session as isolated. db.session._is_isolated = True @sqlalchemy.event.listens_for(db.session, 'after_transaction_end') def restart_savepoint(session, transaction): if transaction.nested and not transaction._parent.nested and \ getattr(db.session, '_is_isolated', False): session.expire_all() session.begin_nested() yield app db.session._is_isolated = False db.session.close() transaction.rollback() connection.close() db.session = original_session invenio_records_factory_cleanup()
def cleanup_workflows(workflow_app): db.session.close_all() drop_all(app=workflow_app) create_all(app=workflow_app) invenio_records_factory_cleanup()