~free.ekanayaka/storm/any-expr

« back to all changes in this revision

Viewing changes to tests/django/backend.py

  • Committer: Jamu Kakar
  • Date: 2009-11-24 18:34:34 UTC
  • mfrom: (340 storm.trunk)
  • mto: This revision was merged to the branch mainline in revision 341.
  • Revision ID: jkakar@kakar.ca-20091124183434-ambkvw9tp2byvjnc
- Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
 
24
24
try:
25
 
    from django.conf import settings
 
25
    import django
26
26
    import transaction
27
27
except ImportError:
28
28
    have_django_and_transaction = False
29
29
else:
30
30
    have_django_and_transaction = True
 
31
    from django.conf import settings
31
32
    from storm.django import stores
32
33
    from storm.zope.zstorm import global_zstorm, StoreDataManager
33
34
 
54
55
    def tearDown(self):
55
56
        transaction.abort()
56
57
        self.drop_tables()
57
 
        settings._target = None
 
58
        if django.VERSION >= (1, 1):
 
59
            settings._wrapped = None
 
60
        else:
 
61
            settings._target = None
58
62
        global_zstorm._reset()
59
63
        stores.have_configured_stores = False
60
64
        transaction.manager.free(transaction.get())
72
76
    def drop_tables(self):
73
77
        raise NotImplementedError
74
78
 
 
79
    def make_wrapper(self):
 
80
        from storm.django.backend import base
 
81
        if django.VERSION >= (1, 1):
 
82
            wrapper = base.DatabaseWrapper({
 
83
                    'DATABASE_HOST': settings.DATABASE_HOST,
 
84
                    'DATABASE_NAME': settings.DATABASE_NAME,
 
85
                    'DATABASE_OPTIONS': settings.DATABASE_OPTIONS,
 
86
                    'DATABASE_PASSWORD': settings.DATABASE_PASSWORD,
 
87
                    'DATABASE_PORT': settings.DATABASE_PORT,
 
88
                    'DATABASE_USER': settings.DATABASE_USER,
 
89
                    'TIME_ZONE': settings.TIME_ZONE,
 
90
                    })
 
91
        else:
 
92
            wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)
 
93
        return wrapper
 
94
 
75
95
    def test_create_wrapper(self):
76
 
        from storm.django.backend import base
77
 
        wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)
 
96
        wrapper = self.make_wrapper()
78
97
        self.assertTrue(isinstance(wrapper, self.get_wrapper_class()))
79
98
 
80
99
        # The wrapper uses the same database connection as the store.
94
113
                        "%r should be joined to the transaction" % store)
95
114
 
96
115
    def test_using_wrapper_joins_transaction(self):
97
 
        from storm.django.backend import base
98
 
        wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)
 
116
        wrapper = self.make_wrapper()
99
117
        cursor = wrapper.cursor()
100
118
        cursor.execute("SELECT 1")
101
119
        self.assertInTransaction(stores.get_store("django"))
102
120
 
103
121
    def test_commit(self):
104
 
        from storm.django.backend import base
105
 
        wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)
 
122
        wrapper = self.make_wrapper()
106
123
        cursor = wrapper.cursor()
107
124
        cursor.execute("INSERT INTO django_test (title) VALUES ('foo')")
108
125
        wrapper._commit()
114
131
        self.assertEqual(result[0][0], "foo")
115
132
 
116
133
    def test_rollback(self):
117
 
        from storm.django.backend import base
118
 
        wrapper = base.DatabaseWrapper(**settings.DATABASE_OPTIONS)
 
134
        wrapper = self.make_wrapper()
119
135
        cursor = wrapper.cursor()
120
136
        cursor.execute("INSERT INTO django_test (title) VALUES ('foo')")
121
137
        wrapper._rollback()