1
from testtools import TestCase
7
class ConfigChangedTest(TestCase):
10
super(ConfigChangedTest, self).setUp()
11
self.get_service_ports = self.patch_hook("get_service_ports")
12
self.get_sitenames = self.patch_hook("get_sitenames")
13
self.construct_squid3_config = self.patch_hook(
14
"construct_squid3_config")
15
self.update_nrpe_checks = self.patch_hook(
17
self.update_service_ports = self.patch_hook(
18
"update_service_ports")
19
self.service_squid3 = self.patch_hook(
21
self.notify_cached_website = self.patch_hook("notify_cached_website")
22
self.log = self.patch_hook("log")
23
self.config_get = self.patch_hook("config_get")
25
def patch_hook(self, hook_name):
26
mock_controller = patch.object(hooks, hook_name)
27
mock = mock_controller.start()
28
self.addCleanup(mock_controller.stop)
31
def test_config_changed_notify_cached_website_changed_stanzas(self):
32
self.service_squid3.return_value = True
33
self.get_sitenames.side_effect = (
35
('foo.internal', 'bar.internal'))
37
hooks.config_changed()
39
self.notify_cached_website.assert_called_once_with()
41
def test_config_changed_no_notify_cached_website_not_changed(self):
42
self.service_squid3.return_value = True
43
self.get_sitenames.side_effect = (
47
hooks.config_changed()
49
self.assertFalse(self.notify_cached_website.called)
52
def test_config_changed_no_notify_cached_website_failed_check(self, exit):
53
self.service_squid3.return_value = False
54
self.get_sitenames.side_effect = (
56
('foo.internal', 'bar.internal'))
58
hooks.config_changed()
60
self.assertFalse(self.notify_cached_website.called)