Merge lp:~therve/storm/earlier-register-transaction into lp:storm

Proposed by Thomas Herve
Status: Merged
Approved by: Stuart Bishop
Approved revision: 396
Merged at revision: 396
Proposed branch: lp:~therve/storm/earlier-register-transaction
Merge into: lp:storm
Diff against target: 57 lines (+17/-3)
2 files modified
storm/database.py (+1/-1)
tests/store/base.py (+16/-2)
To merge this branch: bzr merge lp:~therve/storm/earlier-register-transaction
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Jamu Kakar (community) Approve
Review via email: mp+69999@code.launchpad.net

Description of the change

The branch moves the event, and add a whitebox test.

To post a comment you must log in.
Revision history for this message
Jamu Kakar (jkakar) wrote :

Nice one, +1!

review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storm/database.py'
2--- storm/database.py 2010-04-16 07:14:25 +0000
3+++ storm/database.py 2011-08-01 12:57:52 +0000
4@@ -224,9 +224,9 @@
5 raise ClosedError("Connection is closed")
6 if self._blocked:
7 raise ConnectionBlockedError("Access to connection is blocked")
8- self._ensure_connected()
9 if self._event:
10 self._event.emit("register-transaction")
11+ self._ensure_connected()
12 if isinstance(statement, Expr):
13 if params is not None:
14 raise ValueError("Can't pass parameters with expressions")
15
16=== modified file 'tests/store/base.py'
17--- tests/store/base.py 2011-07-14 11:15:30 +0000
18+++ tests/store/base.py 2011-08-01 12:57:52 +0000
19@@ -28,7 +28,7 @@
20 import weakref
21
22 from storm.references import Reference, ReferenceSet, Proxy
23-from storm.database import Result
24+from storm.database import Result, STATE_DISCONNECTED
25 from storm.properties import (
26 Int, Float, RawStr, Unicode, Property, Pickle, UUID)
27 from storm.properties import PropertyPublisherMeta, Decimal
28@@ -40,7 +40,7 @@
29 from storm.exceptions import (
30 ClosedError, ConnectionBlockedError, FeatureError, LostObjectError,
31 NoStoreError, NotFlushedError, NotOneError, OrderLoopError, UnorderedError,
32- WrongStoreError)
33+ WrongStoreError, DisconnectionError)
34 from storm.cache import Cache
35 from storm.store import AutoReload, EmptyResultSet, Store, ResultSet
36 from storm.tracer import debug
37@@ -5959,6 +5959,20 @@
38 self.assertEqual(len(calls), 1)
39 self.assertEqual(calls[0], self.store)
40
41+ def test_wb_event_before_check_connection(self):
42+ """
43+ The register-transaction event is emitted before checking the state of
44+ the connection.
45+ """
46+ calls = []
47+ def register_transaction(owner):
48+ calls.append(owner)
49+ self.store._event.hook("register-transaction", register_transaction)
50+ self.store._connection._state = STATE_DISCONNECTED
51+ self.assertRaises(DisconnectionError, self.store.execute, "SELECT 1")
52+ self.assertEqual(len(calls), 1)
53+ self.assertEqual(calls[0], self.store)
54+
55 def test_add_sends_event(self):
56 """Adding an object emits the register-transaction event."""
57 calls = []

Subscribers

People subscribed via source and target branches

to status/vote changes: