~landscape/charms/xenial/mongodb/trunk

« back to all changes in this revision

Viewing changes to tests/test_write_log_rotate_config.py

  • Committer: Tim Van Steenburgh
  • Date: 2014-11-20 14:55:49 UTC
  • mfrom: (53.5.5 mongodb)
  • Revision ID: tim.van.steenburgh@canonical.com-20141120145549-m287c75a35r7w8f2
Refactor tests

Show diffs side-by-side

added added

removed removed

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