1
1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6
4
from storm.zope.interfaces import IZStorm
7
5
from zope.component import getUtility
9
from canonical.database.sqlbase import (
11
ZopelessTransactionManager,
13
from canonical.testing.layers import (
14
LaunchpadZopelessLayer,
15
ZopelessDatabaseLayer,
7
from canonical.database.sqlbase import ZopelessTransactionManager
8
from canonical.testing.layers import LaunchpadZopelessLayer
17
9
from lp.testing import TestCase
30
22
new_active_stores = [
31
23
item[0] for item in getUtility(IZStorm).iterstores()]
32
24
self.assertContentEqual(active_stores, new_active_stores)
35
class TestInitZopeless(TestCase):
37
layer = ZopelessDatabaseLayer
39
def test_initZopelessTwice(self):
40
# Hook the warnings module, so we can verify that we get the expected
41
# warning. The warnings module has two key functions, warn and
42
# warn_explicit, the first calling the second. You might, therefore,
43
# think that we should hook the second, to catch all warnings in one
44
# place. However, from Python 2.6, both of these are replaced with
45
# entries into a C extension if available, and the C implementation of
46
# the first will not call a monkeypatched Python implementation of the
47
# second. Therefore, we hook warn, as is the one actually called by
48
# the particular code we are interested in testing.
49
original_warn = warnings.warn
50
warnings.warn = self.warn_hooked
53
# Calling initZopeless with the same arguments twice should emit
56
ZopelessTransactionManager.initZopeless(
58
ZopelessTransactionManager.initZopeless(
60
self.failUnless(self.warned)
62
ZopelessTransactionManager.uninstall()
64
# Put the warnings module back the way we found it.
65
warnings.warn = original_warn
67
def warn_hooked(self, message, category=None, stacklevel=1):
68
self.failUnlessEqual(alreadyInstalledMsg, str(message))