3
from testtools import TestCase
8
class InstallTests(TestCase):
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)
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)
28
def test_makes_config_dir(self, mkdir):
29
self.path_exists.return_value = False
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)
37
def test_config_dir_already_exists(self, mkdir):
39
self.path_exists.assert_called_once_with(
40
hooks.default_haproxy_service_config_dir)
41
self.assertFalse(mkdir.called)
43
def test_install_packages(self):
45
self.apt_install.assert_called_once_with(
46
['haproxy', 'python-jinja2'], fatal=True)
48
def test_ensures_package_status(self):
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)
54
def test_calls_enable_haproxy(self):
56
self.enable_haproxy.assert_called_once_with()