6
from canonical.config import config, dbconfig
6
from canonical.config import (
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)
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)
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)
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)
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)
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)
75
self.assertEqual('launchpad_main', dbc.dbuser)
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.