~cjwatson/storm/no-string-exceptions

« back to all changes in this revision

Viewing changes to tests/django/stores.py

  • Committer: Benji York
  • Date: 2016-03-01 14:19:44 UTC
  • mfrom: (478.2.2 kill-django-storm)
  • Revision ID: benji.york@canonical.com-20160301141944-rk34atio78h7n1h3
Merge lp:~adam-collard/storm/kill-django-storm [r=benji]

Remove Django support in Storm.

The Django support has long since bit-rotted in Storm, and searching
on http://searchcode.com/ shows it isn't being used. Rather than try
to keep it alive this branch does the honourable thing and shoots it
in the head.

With this branch merged, tests should pass on Xenial.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (c) 2008 Canonical
3
 
#
4
 
# Written by James Henstridge <jamesh@canonical.com>
5
 
#
6
 
# This file is part of Storm Object Relational Mapper.
7
 
#
8
 
# Storm is free software; you can redistribute it and/or modify
9
 
# it under the terms of the GNU Lesser General Public License as
10
 
# published by the Free Software Foundation; either version 2.1 of
11
 
# the License, or (at your option) any later version.
12
 
#
13
 
# Storm is distributed in the hope that it will be useful,
14
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU Lesser General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU Lesser General Public License
19
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
#
21
 
 
22
 
import threading
23
 
 
24
 
try:
25
 
    import django
26
 
    import transaction
27
 
except ImportError:
28
 
    have_django_and_transaction = False
29
 
else:
30
 
    have_django_and_transaction = True
31
 
    from django import conf
32
 
    from storm.django import stores
33
 
    from storm.zope.zstorm import global_zstorm
34
 
 
35
 
from storm.store import Store
36
 
from tests.helper import TestHelper
37
 
 
38
 
 
39
 
class DjangoStoreTests(TestHelper):
40
 
 
41
 
    def is_supported(self):
42
 
        return have_django_and_transaction
43
 
 
44
 
    def setUp(self):
45
 
        super(DjangoStoreTests, self).setUp()
46
 
        conf.settings.configure(STORM_STORES={})
47
 
 
48
 
    def tearDown(self):
49
 
        if django.VERSION >= (1, 1):
50
 
            if django.VERSION >= (1, 6):
51
 
                from django.utils.functional import empty
52
 
            else:
53
 
                empty = None
54
 
            conf.settings._wrapped = empty
55
 
        else:
56
 
            conf.settings._target = None
57
 
        # Reset the utility to cleanup the StoreSynchronizer's from the
58
 
        # transaction.
59
 
        global_zstorm._reset()
60
 
        stores.have_configured_stores = False
61
 
        # Free the transaction to avoid having errors that cross
62
 
        # test cases.
63
 
        transaction.manager.free(transaction.get())
64
 
        super(DjangoStoreTests, self).tearDown()
65
 
 
66
 
    def test_configure_stores_configures_store_uris(self):
67
 
        conf.settings.MIDDLEWARE_CLASSES += (
68
 
            "storm.django.middleware.ZopeTransactionMiddleware",)
69
 
        conf.settings.STORM_STORES = {"name1": "sqlite:1",
70
 
                                      "name2": "sqlite:2",
71
 
                                      "name3": "sqlite:3"}
72
 
        stores.configure_stores(conf.settings)
73
 
        default_uris = global_zstorm.get_default_uris()
74
 
        self.assertEquals(default_uris, {"name1": "sqlite:1",
75
 
                                         "name2": "sqlite:2",
76
 
                                         "name3": "sqlite:3"})
77
 
 
78
 
    def test_get_store(self):
79
 
        conf.settings.MIDDLEWARE_CLASSES += (
80
 
            "storm.django.middleware.ZopeTransactionMiddleware",)
81
 
        conf.settings.STORM_STORES = {"name": "sqlite:"}
82
 
        store = stores.get_store("name")
83
 
        self.assertTrue(isinstance(store, Store))
84
 
        # Calling get_store() twice returns the same store.
85
 
        store2 = stores.get_store("name")
86
 
        self.assertTrue(store is store2)
87
 
 
88
 
    def test_get_store_returns_per_thread_stores(self):
89
 
        conf.settings.MIDDLEWARE_CLASSES += (
90
 
            "storm.django.middleware.ZopeTransactionMiddleware",)
91
 
        conf.settings.STORM_STORES = {"name": "sqlite:"}
92
 
 
93
 
        store = stores.get_store("name")
94
 
        other_stores = []
95
 
        def f():
96
 
            other_stores.append(stores.get_store("name"))
97
 
 
98
 
        thread = threading.Thread(target=f)
99
 
        thread.start()
100
 
        thread.join()
101
 
        self.assertEqual(len(other_stores), 1)
102
 
        self.assertNotEqual(other_stores[0], store)
103
 
 
104
 
    def test_get_store_uri(self):
105
 
        conf.settings.MIDDLEWARE_CLASSES += (
106
 
            "storm.django.middleware.ZopeTransactionMiddleware",)
107
 
        conf.settings.STORM_STORES = {"name": "sqlite:"}
108
 
 
109
 
        self.assertEqual(stores.get_store_uri("name"), "sqlite:")