Пример #1
0
def test_comfirm_close_when_exception(mocker):
    with mocker.patch.object(
            Session, 'commit', mocker.MagicMock(
            side_effect=[gevent.Timeout(), ])):
        session = DBSession()
        session.execute("select 1")
        session.flush()
        with pytest.raises(gevent.Timeout):
            session.commit()
        for engine in session.engines.itervalues():
            for parent in session.transaction._iterate_parents():
                conn = parent._connections.get(engine)
                if conn:
                    assert conn[0].invalidated
        session.close()
Пример #2
0
def test_with_statement_on_exc():
    class ThisExc(Exception):
        pass

    trans_orig = DBSession().transaction

    with pytest.raises(ThisExc):
        with DBSession() as session:
            session.execute('select 1')
            _invalidate_connections(session)
            raise ThisExc('boom!')

    session = DBSession()
    assert session.transaction.is_active
    assert session.transaction is not trans_orig
    session.commit()
    session.close()
Пример #3
0
def test_session_stack():
    core_db.RAISE_CLOSING_EXCEPTION = True

    DBSession = make_session(engines, force_scope=True)

    session1 = DBSession()
    with session_stack():
        session2 = DBSession()
        session2.close()
        with session_stack():
            session3 = DBSession()
            session3.close()
    session1.close()

    assert not (session1 is session2 is session3)