~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/config/tests/test_database_config.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-21 12:59:32 UTC
  • mfrom: (13993.1.7 overridable-dbconfig)
  • Revision ID: launchpad@pqm.canonical.com-20110921125932-vandcom75qi3zkib
[r=stevenk][no-qa] Allow DatabaseConfig's settings to be overridden
 without dealing with config overlay stacks and config sections.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
__metaclass__ = type
5
5
 
6
 
from canonical.config import config, dbconfig
 
6
from canonical.config import (
 
7
    config,
 
8
    DatabaseConfig,
 
9
    dbconfig,
 
10
    )
7
11
from canonical.launchpad.readonly import read_only_file_exists
8
12
from canonical.launchpad.tests.readonly import (
9
13
    remove_read_only_file,
37
41
        self.assertEquals(expected_db, dbconfig.rw_main_master)
38
42
        self.assertEquals('launchpad_main', dbconfig.dbuser)
39
43
 
 
44
    def test_override(self):
 
45
        # dbuser and isolation_level can be overridden at runtime, without
 
46
        # requiring a custom config overlay.
 
47
        dbc = DatabaseConfig()
 
48
        dbc.setConfigSection('launchpad')
 
49
        self.assertEqual('launchpad_main', dbc.dbuser)
 
50
        self.assertEqual('serializable', dbc.isolation_level)
 
51
 
 
52
        # dbuser and isolation_level overrides both work.
 
53
        dbc.override(dbuser='not_launchpad', isolation_level='autocommit')
 
54
        self.assertEqual('not_launchpad', dbc.dbuser)
 
55
        self.assertEqual('autocommit', dbc.isolation_level)
 
56
 
 
57
        # Overriding dbuser again preserves the isolation_level override.
 
58
        dbc.override(dbuser='also_not_launchpad')
 
59
        self.assertEqual('also_not_launchpad', dbc.dbuser)
 
60
        self.assertEqual('autocommit', dbc.isolation_level)
 
61
 
 
62
        # Overriding with None removes the override.
 
63
        dbc.override(dbuser=None, isolation_level=None)
 
64
        self.assertEqual('launchpad_main', dbc.dbuser)
 
65
        self.assertEqual('serializable', dbc.isolation_level)
 
66
 
 
67
    def test_reset(self):
 
68
        # reset() removes any overrides.
 
69
        dbc = DatabaseConfig()
 
70
        dbc.setConfigSection('launchpad')
 
71
        self.assertEqual('launchpad_main', dbc.dbuser)
 
72
        dbc.override(dbuser='not_launchpad')
 
73
        self.assertEqual('not_launchpad', dbc.dbuser)
 
74
        dbc.reset()
 
75
        self.assertEqual('launchpad_main', dbc.dbuser)
 
76
 
40
77
    def test_required_values(self):
41
78
        # Some variables are required to have a value, such as dbuser.  So we
42
79
        # get a ValueError if they are not set.