diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-22 19:34:18 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-03-22 19:34:18 -0400 |
| commit | b00e15b50f83b4d939a15162fe53863bc15be4f0 (patch) | |
| tree | aacd2b265b9edd0883c3a265d424be05998123d8 /test/engine/test_execute.py | |
| parent | a7a6b436600c764704f39e177938008c6f6b315f (diff) | |
| download | sqlalchemy-b00e15b50f83b4d939a15162fe53863bc15be4f0.tar.gz | |
- An event listener can now be associated with a :class:`.Engine`,
after one or more :class:`.Connection` objects have been created
(such as by an orm :class:`.Session` or via explicit connect)
and the listener will pick up events from those connections.
Previously, performance concerns pushed the event transfer from
:class:`.Engine` to :class:`.Connection` at init-time only, but
we've inlined a bunch of conditional checks to make this possible
without any additional function calls. fixes #2978
Diffstat (limited to 'test/engine/test_execute.py')
| -rw-r--r-- | test/engine/test_execute.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index d3ae309c3..3bdf34176 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1248,6 +1248,39 @@ class EngineEventsTest(fixtures.TestBase): eq_(canary.be1.call_count, 2) eq_(canary.be2.call_count, 2) + def test_add_event_after_connect(self): + # new feature as of #2978 + canary = Mock() + e1 = create_engine(config.db_url) + assert not e1._has_events + + conn = e1.connect() + + event.listen(e1, "before_execute", canary.be1) + conn.execute(select([1])) + + eq_(canary.be1.call_count, 1) + + conn._branch().execute(select([1])) + eq_(canary.be1.call_count, 2) + + def test_force_conn_events_false(self): + canary = Mock() + e1 = create_engine(config.db_url) + assert not e1._has_events + + event.listen(e1, "before_execute", canary.be1) + + conn = e1._connection_cls(e1, connection=e1.raw_connection(), + _has_events=False) + + conn.execute(select([1])) + + eq_(canary.be1.call_count, 0) + + conn._branch().execute(select([1])) + eq_(canary.be1.call_count, 0) + def test_cursor_events_ctx_execute_scalar(self): canary = Mock() e1 = testing_engine(config.db_url) |
