diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-16 19:04:39 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-16 19:04:39 +0000 |
commit | 16ca025657714f5a031bb068effdf3c5dc15e458 (patch) | |
tree | 4ea0c986dca611a2aaf1f320c53213dface90bd3 /test | |
parent | 8c660d461189a6611b855cf115990b1f08a67220 (diff) | |
download | sqlalchemy-16ca025657714f5a031bb068effdf3c5dc15e458.tar.gz |
- ConnectionProxy now has wrapper methods for all transaction
lifecycle events, including begin(), rollback(), commit()
begin_nested(), begin_prepared(), prepare(), release_savepoint(),
etc.
Diffstat (limited to 'test')
-rw-r--r-- | test/engine/test_execute.py | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 4a1342bd5..45d7763f0 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -106,7 +106,6 @@ class ProxyConnectionTest(TestBase): return execute(clauseelement, *multiparams, **params) def cursor_execute(self, execute, cursor, statement, parameters, context, executemany): - print "CE", statement, parameters cursor_stmts.append( (str(statement), parameters, None) ) @@ -173,4 +172,61 @@ class ProxyConnectionTest(TestBase): assert_stmts(compiled, stmts) assert_stmts(cursor, cursor_stmts) + def test_transactional(self): + track = [] + class TrackProxy(ConnectionProxy): + def __getattribute__(self, key): + fn = object.__getattribute__(self, key) + def go(*arg, **kw): + track.append(fn.__name__) + return fn(*arg, **kw) + return go + + engine = engines.testing_engine(options={'proxy':TrackProxy()}) + conn = engine.connect() + trans = conn.begin() + conn.execute("select 1") + trans.rollback() + trans = conn.begin() + conn.execute("select 1") + trans.commit() + + eq_(track, ['begin', 'execute', 'cursor_execute', + 'rollback', 'begin', 'execute', 'cursor_execute', 'commit']) + + @testing.requires.savepoints + @testing.requires.two_phase_transactions + def test_transactional_advanced(self): + track = [] + class TrackProxy(ConnectionProxy): + def __getattribute__(self, key): + fn = object.__getattribute__(self, key) + def go(*arg, **kw): + track.append(fn.__name__) + return fn(*arg, **kw) + return go + + engine = engines.testing_engine(options={'proxy':TrackProxy()}) + conn = engine.connect() + + trans = conn.begin() + trans2 = conn.begin_nested() + conn.execute("select 1") + trans2.rollback() + trans2 = conn.begin_nested() + conn.execute("select 1") + trans2.commit() + trans.rollback() + + trans = conn.begin_twophase() + conn.execute("select 1") + trans.prepare() + trans.commit() + + eq_(track, ['begin', 'savepoint', 'execute', 'cursor_execute', 'execute', 'cursor_execute', + 'rollback_savepoint', 'execute', 'cursor_execute', 'savepoint', 'execute', + 'cursor_execute', 'execute', 'cursor_execute', 'release_savepoint', 'execute', + 'cursor_execute', 'rollback', 'begin_twophase', 'execute', 'cursor_execute', + 'prepare_twophase', 'execute', 'cursor_execute', 'commit_twophase', + 'execute', 'cursor_execute', 'execute', 'cursor_execute']) |