~gnuoy/charms/trusty/ceilometer-agent/stable-charm-sync

« back to all changes in this revision

Viewing changes to unit_tests/test_ceilometer_hooks.py

  • Committer: James Page
  • Date: 2013-10-20 22:28:18 UTC
  • Revision ID: james.page@canonical.com-20131020222818-cyt325a21a0vr5c0
Add unit tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mock import patch, MagicMock
 
2
 
 
3
import ceilometer_utils
 
4
# Patch out register_configs for import of hooks
 
5
_register_configs = ceilometer_utils.register_configs
 
6
ceilometer_utils.register_configs = MagicMock()
 
7
 
 
8
import ceilometer_hooks as hooks
 
9
 
 
10
# Renable old function
 
11
ceilometer_utils.register_configs = _register_configs
 
12
 
 
13
from test_utils import CharmTestCase
 
14
 
 
15
TO_PATCH = [
 
16
    'configure_installation_source',
 
17
    'apt_install',
 
18
    'apt_update',
 
19
    'config',
 
20
    'filter_installed_packages',
 
21
    'CONFIGS',
 
22
]
 
23
 
 
24
 
 
25
class CeilometerHooksTest(CharmTestCase):
 
26
 
 
27
    def setUp(self):
 
28
        super(CeilometerHooksTest, self).setUp(hooks, TO_PATCH)
 
29
        self.config.side_effect = self.test_config.get
 
30
 
 
31
    def test_configure_source(self):
 
32
        self.test_config.set('openstack-origin', 'cloud:precise-havana')
 
33
        hooks.hooks.execute(['hooks/install'])
 
34
        self.configure_installation_source.\
 
35
            assert_called_with('cloud:precise-havana')
 
36
 
 
37
    def test_install_hook(self):
 
38
        self.filter_installed_packages.return_value = \
 
39
            hooks.CEILOMETER_AGENT_PACKAGES
 
40
        hooks.hooks.execute(['hooks/install'])
 
41
        self.assertTrue(self.configure_installation_source.called)
 
42
        self.apt_update.assert_called_with(fatal=True)
 
43
        self.apt_install.assert_called_with(hooks.CEILOMETER_AGENT_PACKAGES,
 
44
                                            fatal=True)
 
45
 
 
46
    def test_ceilometer_changed(self):
 
47
        hooks.hooks.execute(['hooks/ceilometer-service-relation-changed'])
 
48
        self.assertTrue(self.CONFIGS.write_all.called)