~teknico/charms/precise/juju-gui/encrypt-api-env-connection

« back to all changes in this revision

Viewing changes to tests/test_utils.py

  • Committer: Brad Crittenden
  • Date: 2012-12-10 19:11:50 UTC
  • mfrom: (7.2.4 1086790)
  • Revision ID: bac@canonical.com-20121210191150-sxpyjw493kewe2q5
[r=gary, benji] Add command-level logging and real-time output for 'make' command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import os
4
4
import tempfile
5
5
import unittest
 
6
import charmhelpers
 
7
from simplejson import dumps
6
8
 
7
9
from utils import (
 
10
    cmd_log,
8
11
    get_zookeeper_address,
9
12
    render_to_file,
10
13
)
44
47
        expected = self.template_contents % context
45
48
        self.assertEqual(expected, self.destination_file.read())
46
49
 
 
50
class CmdLogTest(unittest.TestCase):
 
51
    def setUp(self):
 
52
        # Patch the charmhelpers 'command', which powers get_config.  The
 
53
        # result of this is the mock_config dictionary will be returned.
 
54
        # The monkey patch is undone in the tearDown.
 
55
        self.command = charmhelpers.command
 
56
        fd, self.log_file_name = tempfile.mkstemp()
 
57
        os.close(fd)
 
58
        mock_config = {'command-log-file': self.log_file_name}
 
59
        charmhelpers.command = lambda *args: lambda: dumps(mock_config)
 
60
 
 
61
    def tearDown(self):
 
62
        charmhelpers.command = self.command
 
63
 
 
64
    def test_contents_logged(self):
 
65
        cmd_log('foo')
 
66
        line = open(self.log_file_name, 'r').read()
 
67
        self.assertTrue(line.endswith(': juju-gui@INFO \nfoo\n'))
 
68
 
47
69
 
48
70
if __name__ == '__main__':
49
71
    unittest.main(verbosity=2)