add ca.verify tests
[stack/cam.git] / cam / tests / test_utils.py
1 import os
2 import unittest
3 import tempfile
4 from cam import utils
5
6
7 class UtilsTest(unittest.TestCase):
8
9     def setUp(self):
10         self.old_template_dir = utils._template_dir
11         self.tmpdir = tempfile.mkdtemp()
12         utils._template_dir = self.tmpdir
13
14     def tearDown(self):
15         os.system('rm -fr "%s"' % self.tmpdir)
16         utils._template_dir = self.old_template_dir
17
18     def test_render(self):
19         tf = os.path.join(utils._template_dir, 'test')
20         tfd = open(tf, 'w')
21         tfd.write('this is a %(sub)s\n')
22         tfd.close()
23         of = os.path.join(self.tmpdir, 'test.out')
24         utils.render(of, 'test', {'sub':'TEST'})
25         self.assert_(os.path.exists(of))
26         output = open(of, 'r').read()
27         self.assertEquals('this is a TEST\n', output)
28
29     def test_parse_bool(self):
30         self.assertTrue(utils.parse_bool('y'))
31         self.assertTrue(utils.parse_bool('1'))
32         self.assertTrue(utils.parse_bool('true'))
33         self.assertFalse(utils.parse_bool('false'))
34         self.assertFalse(utils.parse_bool('no'))
35
36
37 if __name__ == '__main__':
38     unittest.main()