~free.ekanayaka/storm/any-expr

« back to all changes in this revision

Viewing changes to tests/django/backend.py

  • Committer: Gustavo Niemeyer
  • Date: 2008-11-04 16:52:14 UTC
  • mfrom: (280 trunk)
  • mto: This revision was merged to the branch mainline in revision 282.
  • Revision ID: gustavo@niemeyer.net-20081104165214-p2pn9lraefjiu91b
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
else:
30
30
    have_django_and_transaction = True
31
31
    from storm.django import stores
32
 
    from storm.zope.zstorm import global_zstorm
 
32
    from storm.zope.zstorm import global_zstorm, StoreDataManager
33
33
 
34
34
from tests.helper import TestHelper
35
35
 
81
81
        store = stores.get_store("django")
82
82
        self.assertEqual(store._connection._raw_connection, wrapper.connection)
83
83
 
 
84
    def _isInTransaction(self, store):
 
85
        """Check if a Store is part of the current transaction."""
 
86
        for dm in transaction.get()._resources:
 
87
            if isinstance(dm, StoreDataManager) and dm._store is store:
 
88
                return True
 
89
        return False
 
90
 
 
91
    def assertInTransaction(self, store):
 
92
        """Check that the given store is joined to the transaction."""
 
93
        self.assertTrue(self._isInTransaction(store),
 
94
                        "%r should be joined to the transaction" % store)
 
95
 
 
96
    def test_using_wrapper_joins_transaction(self):
 
97
        from storm.django.backend import base
 
98
        wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)
 
99
        cursor = wrapper.cursor()
 
100
        cursor.execute("SELECT 1")
 
101
        self.assertInTransaction(stores.get_store("django"))
 
102
 
84
103
    def test_commit(self):
85
104
        from storm.django.backend import base
86
105
        wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)