~storm/storm/trunk

« back to all changes in this revision

Viewing changes to tests/store/base.py

Merge earlier-register-transaction [r=jkakar,stub] [f=819282]

Move the firing of the register-transaction event in Connection.execute
before the connection checking, to make sure that the store gets registered properly
for future rollbacks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import weakref
29
29
 
30
30
from storm.references import Reference, ReferenceSet, Proxy
31
 
from storm.database import Result
 
31
from storm.database import Result, STATE_DISCONNECTED
32
32
from storm.properties import (
33
33
    Int, Float, RawStr, Unicode, Property, Pickle, UUID)
34
34
from storm.properties import PropertyPublisherMeta, Decimal
40
40
from storm.exceptions import (
41
41
    ClosedError, ConnectionBlockedError, FeatureError, LostObjectError,
42
42
    NoStoreError, NotFlushedError, NotOneError, OrderLoopError, UnorderedError,
43
 
    WrongStoreError)
 
43
    WrongStoreError, DisconnectionError)
44
44
from storm.cache import Cache
45
45
from storm.store import AutoReload, EmptyResultSet, Store, ResultSet
46
46
from storm.tracer import debug
5959
5959
        self.assertEqual(len(calls), 1)
5960
5960
        self.assertEqual(calls[0], self.store)
5961
5961
 
 
5962
    def test_wb_event_before_check_connection(self):
 
5963
        """
 
5964
        The register-transaction event is emitted before checking the state of
 
5965
        the connection.
 
5966
        """
 
5967
        calls = []
 
5968
        def register_transaction(owner):
 
5969
            calls.append(owner)
 
5970
        self.store._event.hook("register-transaction", register_transaction)
 
5971
        self.store._connection._state = STATE_DISCONNECTED
 
5972
        self.assertRaises(DisconnectionError, self.store.execute, "SELECT 1")
 
5973
        self.assertEqual(len(calls), 1)
 
5974
        self.assertEqual(calls[0], self.store)
 
5975
 
5962
5976
    def test_add_sends_event(self):
5963
5977
        """Adding an object emits the register-transaction event."""
5964
5978
        calls = []