~matsubara/charms/trusty/mongodb/bug-1410847

« back to all changes in this revision

Viewing changes to tests/01_test_write_log_rotate_config.py

  • Committer: Jorge Niedbalski
  • Date: 2014-12-09 15:07:49 UTC
  • mto: This revision was merged to the branch mainline in revision 60.
  • Revision ID: jorge.niedbalski@canonical.com-20141209150749-d9k2rjv52vu1zzj5
tidy and cleanup of makefile and test targets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
import mock
4
 
import os
5
 
import unittest
6
 
import tempfile
7
 
import sys
8
 
sys.path.append('hooks')
9
 
import hooks
10
 
 
11
 
 
12
 
class TestWriteLogrotateConfigFile(unittest.TestCase):
13
 
 
14
 
    def test_success(self):
15
 
        logpath = '/tmp/foo/foo.log'
16
 
        config_data = {
17
 
            'logpath': logpath,
18
 
            'logrotate-frequency': 'daily',
19
 
            'logrotate-maxsize': '5G',
20
 
            'logrotate-rotate': 5,
21
 
        }
22
 
        fd, temp_fn = tempfile.mkstemp()
23
 
        os.close(fd)
24
 
        with mock.patch('hooks.juju_log') as mock_juju_log:
25
 
            with mock.patch('hooks.open', create=True) as mock_open:
26
 
                mock_open.return_value = mock.MagicMock(spec=file)
27
 
                hooks.write_logrotate_config(config_data, temp_fn)
28
 
                os.unlink(temp_fn)
29
 
        mock_juju_log.assert_called_once_with('Writing {}.'.format(temp_fn))
30
 
        mock_open.assert_called_once_with(temp_fn, 'w')
31
 
        mock_file = mock_open().__enter__()
32
 
        call_args = mock_file.write.call_args[0][0]
33
 
        self.assertTrue(mock_file.write.called)
34
 
        self.assertIn(logpath, call_args)
35
 
        self.assertIn('daily', call_args)
36
 
        self.assertIn('maxsize 5G', call_args)
37
 
        self.assertIn('rotate 5', call_args)
38
 
 
39
 
 
40
 
if __name__ == '__main__':
41
 
    unittest.main()