13
from udd.paths import paths
16
class TestConfigPath(tests.TestCaseInTempDir):
19
super(TestConfigPath, self).setUp()
20
current_dir = paths.root_dir
21
self.addCleanup(paths.set_root_dir, current_dir)
22
paths.set_root_dir(self.test_dir)
24
def test_iconfig_file_name(self):
26
with open('config/pkgimport.conf', 'w'):
28
conf_path = iconfig.pkgimportconfig_file_name()
29
self.assertEquals(os.path.join(paths.root_dir, 'config'),
30
osutils.dirname(conf_path))
31
self.assertEndsWith(conf_path, 'pkgimport.conf')
33
def test_iconfig_file_name_old_path(self):
34
conf_path = iconfig.pkgimportconfig_file_name()
35
self.assertEquals(paths.root_dir, osutils.dirname(conf_path))
36
self.assertEndsWith(conf_path, 'pkgimport.conf')
39
class TestPkgimportconfig(tests.TestCaseInTempDir):
42
super(TestPkgimportconfig, self).setUp()
43
self.conf_file_name = osutils.pathjoin(self.test_dir, 'pkgimport.conf')
45
def test_simple_option(self):
46
conf = iconfig.PkgimportConfig.from_string(
47
'''pkgimport.base_dir=/foo/bar''',
48
file_name=self.conf_file_name, save=True)
49
self.assertEquals('/foo/bar', conf.get('pkgimport.base_dir'))
52
class TestDefaultPkgimportconfig(tests.TestCase):
55
super(TestDefaultPkgimportconfig, self).setUp()
56
self.conf = iconfig.PkgimportConfig()
58
def test_default_config(self):
59
self.assertEquals('pkgimport', self.conf.config_id())
60
self.assertEquals(iconfig.pkgimportconfig_file_name(),
63
def test_default_basedir(self):
64
self.assertEquals('/srv/package-import.canonical.com/new',
65
self.conf.get('pkgimport.base_dir'))
67
def assertOptiondIsDefined(self, name):
68
self.assertIsNot(None, self.conf.get(name))
70
def test_required_options(self):
71
self.assertOptiondIsDefined('pkgimport.base_dir')
72
self.assertOptiondIsDefined('pkgimport.log_dir')
73
self.assertOptiondIsDefined('pkgimport.driver.log_dir')
74
self.assertOptiondIsDefined('pkgimport.driver.log.debug')
75
self.assertOptiondIsDefined('pkgimport.driver.log.progress')
76
self.assertOptiondIsDefined('pkgimport.packages.log_dir')
79
class TestConfigStack(tests.TestCase):
81
def test_compatibility(self):
82
self.assertRaises(AssertionError, iconfig.ConfigStack, [object()])
84
def test_single_config_get(self):
85
conf = config.IniBasedConfig.from_string('foo=bar')
86
conf_stack = iconfig.ConfigStack([conf])
87
self.assertEquals('bar', conf_stack.get('foo'))
89
def test_get_first_definition(self):
90
conf1 = config.IniBasedConfig.from_string('foo=bar')
91
conf2 = config.IniBasedConfig.from_string('foo=baz')
92
conf_stack = iconfig.ConfigStack([conf1, conf2])
93
self.assertEquals('bar', conf_stack.get('foo'))
96
class TestIconfig(tests.TestCaseInTempDir):
98
def test_location_override_default(self):
99
lconf = config.LocationConfig('.')
100
lconf.set_user_option('pkgimport.base_dir', 'foo')
101
conf = iconfig.Iconfig('.')
102
self.assertEquals('foo', conf.get('pkgimport.base_dir'))
104
class TestPackageStack(tests.TestCaseWithTransport):
107
super(TestPackageStack, self).setUp()
108
# Since iconfig states that pkgimport.conf is part of the sources (or a
109
# directory below), we can't directly use this file for testing.
110
# Instead, we override _root_dir to be local to the test
111
self.overrideAttr(iconfig, '_root_dir', self.test_dir)
113
def _set_store_content(self, store, content=None):
114
# content may be unicode but the file content should be utf8
115
content = content.encode('utf-8')
116
store._load_from_string(content)
16
class TestPackageStack(tests.TestCaseWithConfig):
119
18
def test_package_option(self):
120
19
self._set_store_content(iconfig.PkgimportStore(self.get_transport()),
130
29
'[mypackage]\nfoo={bar}\nbar=baz')
131
30
stack = iconfig.PackageStack('mypackage')
132
31
self.assertEquals('baz', stack.get('foo'))
34
class TestImporterStack(tests.TestCaseWithConfig):
36
def test_subdir_takes_priority(self):
37
self._set_store_content(iconfig.PkgimportStore(self.get_transport()),
40
with open('config/pkgimport.conf', 'w') as f:
41
f.write('foo=subdir\n')
42
stack = iconfig.ImporterStack()
43
self.assertEquals('subdir', stack.get('foo'))
45
def test_common_option(self):
46
self._set_store_content(iconfig.PkgimportStore(self.get_transport()),
48
stack = iconfig.ImporterStack()
49
self.assertEquals('bar', stack.get('foo'))
51
def test_overridden_in_locations(self):
52
self._set_store_content(config.LocationStore(),
53
'''[%s]\nfoo = location\n''' % self.test_dir)
54
stack = iconfig.ImporterStack()
55
self.assertEquals('location', stack.get('foo'))
57
def test_expanded_option_for_importer(self):
58
self._set_store_content(iconfig.PkgimportStore(self.get_transport()),
60
stack = iconfig.ImporterStack()
61
self.assertEquals('baz', stack.get('foo'))
64
class TestDefaultConfigStack(bzr_tests.TestCaseWithTransport):
65
"""Test some significant options in the default configuration.
67
No need to test them all, most of them are built on the same model.
71
super(TestDefaultConfigStack, self).setUp()
72
self.conf = iconfig.ImporterStack()
74
# 'test_base_dir' is a TestCaseInTempDir attribute so it can't be used as a
75
# test method name :-)
76
def test_the_base_dir(self):
77
self.assertEquals('/srv/package-import.canonical.com/new',
78
self.conf.get('pi.base_dir'))
80
def test_log_dir(self):
81
self.assertEquals('/srv/package-import.canonical.com/new/logs',
82
self.conf.get('pi.log_dir'))