summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-05-02 14:57:45 +0000
committerGerrit Code Review <review@openstack.org>2012-05-02 14:57:45 +0000
commit78728744dbff05bb4034fe6017ab9954a033b798 (patch)
treecc0b2005a9218f3ceabdc50e508248f8a913cde3 /tests
parentc421e79d6b04f307e6dba3a9916fcf5e3c4630ff (diff)
parent3f4934226a3abfa55605a2766174c96c8926d795 (diff)
downloadoslo-78728744dbff05bb4034fe6017ab9954a033b798.tar.gz
oslo-78728744dbff05bb4034fe6017ab9954a033b798.tar.xz
oslo-78728744dbff05bb4034fe6017ab9954a033b798.zip
Merge "New ConfigOpts.find_file() for locating conf files"
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_cfg.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py
index 1d8bdca..785a324 100644
--- a/tests/unit/test_cfg.py
+++ b/tests/unit/test_cfg.py
@@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
-# Copyright 2011 Red Hat, Inc.
+# Copyright 2012 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -80,9 +80,13 @@ class BaseTestCase(unittest.TestCase):
self.remove_tempfiles()
self.stubs.UnsetAll()
- def create_tempfiles(self, files):
+ def create_tempfiles(self, files, ext='.conf'):
for (basename, contents) in files:
- (fd, path) = tempfile.mkstemp(prefix=basename, suffix='.conf')
+ if not os.path.isabs(basename):
+ (fd, path) = tempfile.mkstemp(prefix=basename, suffix=ext)
+ else:
+ path = basename + ext
+ fd = os.open(path, os.O_CREAT|os.O_WRONLY)
self.tempfiles.append(path)
try:
os.write(fd, contents)
@@ -1002,6 +1006,43 @@ class SadPathTestCase(BaseTestCase):
self.conf.set_override, 'foo', 'bar', group='blaa')
+class FindFileTestCase(BaseTestCase):
+
+ def test_find_policy_file(self):
+ policy_file = '/etc/policy.json'
+
+ self.stubs.Set(os.path, 'exists', lambda p: p == policy_file)
+
+ self.assertEquals(self.conf.find_file('foo.json'), None)
+ self.assertEquals(self.conf.find_file('policy.json'), policy_file)
+
+ def test_find_policy_file_with_config_file(self):
+ dir = tempfile.mkdtemp()
+ self.tempdirs.append(dir)
+
+ paths = self.create_tempfiles([(os.path.join(dir, 'test.conf'),
+ '[DEFAULT]'),
+ (os.path.join(dir, 'policy.json'),
+ '{}')],
+ ext='')
+
+ self.conf(['--config-file', paths[0]])
+
+ self.assertEquals(self.conf.find_file('policy.json'), paths[1])
+
+ def test_find_policy_file_with_config_dir(self):
+ dir = tempfile.mkdtemp()
+ self.tempdirs.append(dir)
+
+ path = self.create_tempfiles([(os.path.join(dir, 'policy.json'),
+ '{}')],
+ ext='')[0]
+
+ self.conf(['--config-dir', dir])
+
+ self.assertEquals(self.conf.find_file('policy.json'), path)
+
+
class OptDumpingTestCase(BaseTestCase):
class FakeLogger: