~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/database/tests/test_zopeless_transaction_manager.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-21 13:00:42 UTC
  • mfrom: (13993.2.4 overlayless-ztm)
  • Revision ID: launchpad@pqm.canonical.com-20110921130042-oiuotq9rkoss3n95
[r=sinzui][bug=272323] ZopelessTransactionManager now uses
 DatabaseConfig.override instead of lazr.config overlays.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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).
3
3
 
4
 
import warnings
5
 
 
6
4
from storm.zope.interfaces import IZStorm
7
5
from zope.component import getUtility
8
6
 
9
 
from canonical.database.sqlbase import (
10
 
    alreadyInstalledMsg,
11
 
    ZopelessTransactionManager,
12
 
    )
13
 
from canonical.testing.layers import (
14
 
    LaunchpadZopelessLayer,
15
 
    ZopelessDatabaseLayer,
16
 
    )
 
7
from canonical.database.sqlbase import ZopelessTransactionManager
 
8
from canonical.testing.layers import LaunchpadZopelessLayer
17
9
from lp.testing import TestCase
18
10
 
19
11
 
30
22
        new_active_stores = [
31
23
            item[0] for item in getUtility(IZStorm).iterstores()]
32
24
        self.assertContentEqual(active_stores, new_active_stores)
33
 
 
34
 
 
35
 
class TestInitZopeless(TestCase):
36
 
 
37
 
    layer = ZopelessDatabaseLayer
38
 
 
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
51
 
        self.warned = False
52
 
        try:
53
 
            # Calling initZopeless with the same arguments twice should emit
54
 
            # a warning.
55
 
            try:
56
 
                ZopelessTransactionManager.initZopeless(
57
 
                    dbuser='launchpad')
58
 
                ZopelessTransactionManager.initZopeless(
59
 
                    dbuser='launchpad')
60
 
                self.failUnless(self.warned)
61
 
            finally:
62
 
                ZopelessTransactionManager.uninstall()
63
 
        finally:
64
 
            # Put the warnings module back the way we found it.
65
 
            warnings.warn = original_warn
66
 
 
67
 
    def warn_hooked(self, message, category=None, stacklevel=1):
68
 
        self.failUnlessEqual(alreadyInstalledMsg, str(message))
69
 
        self.warned = True