switch the digest default to SHA2
[stack/cam.git] / cam / tests / test_config.py
1 import mox
2 import os
3 import tempfile
4 import unittest
5 from cam import config
6
7
8 class ConfigTest(unittest.TestCase):
9
10     def setUp(self):
11         self.tmpdir = tempfile.mkdtemp()
12         self.mox = mox.Mox()
13
14     def tearDown(self):
15         self.mox.VerifyAll()
16         self.mox.UnsetStubs()
17         os.system("rm -fr '%s'" % self.tmpdir)
18
19     def test_read_config(self):
20         test_cfg = '''
21 [global]
22 root_dir = root
23
24 [ca]
25 something = else
26
27 [cert1]
28 cn = test.com
29 '''
30         cf_file = os.path.join(self.tmpdir, 'config')
31         cf_fd = open(cf_file, 'w')
32         cf_fd.write(test_cfg)
33         cf_fd.close()
34         self.mox.StubOutWithMock(config.ca, 'CA', use_mock_anything=True)
35         config.ca.CA('root', {'something': 'else'}).AndReturn('ca')
36         self.mox.StubOutWithMock(config.cert, 'Cert', use_mock_anything=True)
37         config.cert.Cert('ca', 'cert1', {'cn': 'test.com'}).AndReturn('cert1')
38         self.mox.ReplayAll()
39
40         global_config, ca_obj, certs = config.read_config(cf_file)
41         self.assertEquals('ca', ca_obj)
42         self.assertEquals(['cert1'], certs)
43
44     def test_read_config_nonexist(self):
45         def f():
46             config.read_config('nonexist.conf')
47         self.assertRaises(config.ConfigError, f)
48
49
50 if __name__ == '__main__':
51     unittest.main()