~bloodearnest/charms/precise/squid-reverseproxy/trunk

« back to all changes in this revision

Viewing changes to hooks/tests/test_config_changed_hooks.py

  • Committer: Marco Ceppi
  • Date: 2013-11-07 01:40:09 UTC
  • mfrom: (28.1.85 master)
  • Revision ID: marco@ceppi.net-20131107014009-lqqg63wkyt6ot2ou
[sidnei] Greatly improve test coverage
[sidnei] Allow the use of an X-Balancer-Name header to select which cache_peer backend will be used for a specific request.
[sidnei] Support 'all-services' being set in the relation, in the way that the haproxy sets it, in addition to the previously supported 'sitenames' setting. Makes it compatible with the haproxy charm.
[sidnei] When the list of supported 'sitenames' (computed from dstdomain acls) changes, notify services related via the 'cached-website' relation. This allows to add new services in the haproxy service (or really, any other service related), which notifies the squid service, which then bubbles up to services related via cached-website.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from testtools import TestCase
 
2
from mock import patch
 
3
 
 
4
import hooks
 
5
 
 
6
 
 
7
class ConfigChangedTest(TestCase):
 
8
 
 
9
    def setUp(self):
 
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(
 
16
            "update_nrpe_checks")
 
17
        self.update_service_ports = self.patch_hook(
 
18
            "update_service_ports")
 
19
        self.service_squid3 = self.patch_hook(
 
20
            "service_squid3")
 
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")
 
24
 
 
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)
 
29
        return mock
 
30
 
 
31
    def test_config_changed_notify_cached_website_changed_stanzas(self):
 
32
        self.service_squid3.return_value = True
 
33
        self.get_sitenames.side_effect = (
 
34
            ('foo.internal',),
 
35
            ('foo.internal', 'bar.internal'))
 
36
 
 
37
        hooks.config_changed()
 
38
 
 
39
        self.notify_cached_website.assert_called_once_with()
 
40
 
 
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 = (
 
44
            ('foo.internal',),
 
45
            ('foo.internal',))
 
46
 
 
47
        hooks.config_changed()
 
48
 
 
49
        self.assertFalse(self.notify_cached_website.called)
 
50
 
 
51
    @patch("sys.exit")
 
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 = (
 
55
            ('foo.internal',),
 
56
            ('foo.internal', 'bar.internal'))
 
57
 
 
58
        hooks.config_changed()
 
59
 
 
60
        self.assertFalse(self.notify_cached_website.called)