~dpb/charms/trusty/haproxy/merge-services-fix

« back to all changes in this revision

Viewing changes to hooks/tests/test_install.py

  • Committer: Charles Butler
  • Date: 2014-06-13 16:57:03 UTC
  • mfrom: (79.1.1 haproxy)
  • Revision ID: chuck@dasroot.net-20140613165703-dck1d0z5n5ltjwbe
  James Westby 2014-05-29 Call install_hook() on upgrade-charm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import patch
 
2
import os
 
3
from testtools import TestCase
 
4
 
 
5
import hooks
 
6
 
 
7
 
 
8
class InstallTests(TestCase):
 
9
 
 
10
    def setUp(self):
 
11
        super(InstallTests, self).setUp()
 
12
        self.apt_install = self.patch_hook('apt_install')
 
13
        self.ensure_package_status = self.patch_hook('ensure_package_status')
 
14
        self.enable_haproxy = self.patch_hook('enable_haproxy')
 
15
        self.config_get = self.patch_hook('config_get')
 
16
        path_exists = patch.object(os.path, "exists")
 
17
        self.path_exists = path_exists.start()
 
18
        self.path_exists.return_value = True
 
19
        self.addCleanup(path_exists.stop)
 
20
 
 
21
    def patch_hook(self, hook_name):
 
22
        mock_controller = patch.object(hooks, hook_name)
 
23
        mock = mock_controller.start()
 
24
        self.addCleanup(mock_controller.stop)
 
25
        return mock
 
26
 
 
27
    @patch('os.mkdir')
 
28
    def test_makes_config_dir(self, mkdir):
 
29
        self.path_exists.return_value = False
 
30
        hooks.install_hook()
 
31
        self.path_exists.assert_called_once_with(
 
32
            hooks.default_haproxy_service_config_dir)
 
33
        mkdir.assert_called_once_with(
 
34
            hooks.default_haproxy_service_config_dir, 0600)
 
35
 
 
36
    @patch('os.mkdir')
 
37
    def test_config_dir_already_exists(self, mkdir):
 
38
        hooks.install_hook()
 
39
        self.path_exists.assert_called_once_with(
 
40
            hooks.default_haproxy_service_config_dir)
 
41
        self.assertFalse(mkdir.called)
 
42
 
 
43
    def test_install_packages(self):
 
44
        hooks.install_hook()
 
45
        self.apt_install.assert_called_once_with(
 
46
            ['haproxy', 'python-jinja2'], fatal=True)
 
47
 
 
48
    def test_ensures_package_status(self):
 
49
        hooks.install_hook()
 
50
        self.config_get.assert_called_once_with('package_status')
 
51
        self.ensure_package_status.assert_called_once_with(
 
52
            hooks.service_affecting_packages, self.config_get.return_value)
 
53
 
 
54
    def test_calls_enable_haproxy(self):
 
55
        hooks.install_hook()
 
56
        self.enable_haproxy.assert_called_once_with()