Unit testing
Increase unit test coverage to 100% Change-Id: I56320abb0fc5e5112278ab632dee845c48c8980c
This commit is contained in:
parent
77c1a3d38f
commit
5dda150e02
|
@ -158,7 +158,7 @@ class DRAgentCharm(charms_openstack.charm.OpenStackCharm):
|
|||
self.package_codenames)
|
||||
|
||||
def disable_services(self):
|
||||
"""Disble services, typically used awaiting required relations."""
|
||||
"""Disable services, typically used awaiting required relations."""
|
||||
for service in self.services:
|
||||
ch_core.host.service('disable', service)
|
||||
ch_core.host.service('stop', service)
|
||||
|
|
|
@ -58,7 +58,7 @@ def setup_amqp_req(amqp):
|
|||
|
||||
|
||||
@reactive.when('amqp.available.ssl')
|
||||
def configure_ssl(amqp):
|
||||
def configure_ssl(_amqp):
|
||||
with charm.provide_charm_instance() as instance:
|
||||
instance.configure_ssl()
|
||||
|
||||
|
|
|
@ -89,6 +89,20 @@ class TestDRAgentHandlers(test_utils.PatchHelper):
|
|||
amqp.request_access.assert_called_once_with(
|
||||
username='neutron', vhost='openstack')
|
||||
|
||||
def test_configure_ssl(self):
|
||||
handlers.configure_ssl(mock.MagicMock())
|
||||
self.dragent_charm.configure_ssl.assert_called_once_with()
|
||||
|
||||
def test_disable_services(self):
|
||||
handlers.disable_services()
|
||||
self.dragent_charm.disable_services.assert_called_once_with()
|
||||
self.dragent_charm.assess_status.assert_called_once_with()
|
||||
|
||||
def test_enable_services(self):
|
||||
handlers.enable_services()
|
||||
self.dragent_charm.enable_services.assert_called_once_with()
|
||||
self.dragent_charm.assess_status.assert_called_once_with()
|
||||
|
||||
def test_render_configs(self):
|
||||
self.patch_object(handlers.reactive, 'set_flag')
|
||||
amqp = mock.MagicMock()
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import mock
|
||||
|
||||
import charm.openstack.dragent as dragent
|
||||
|
||||
import charms_openstack.test_utils as test_utils
|
||||
|
@ -72,3 +74,44 @@ class TestDRAgentCharm(Helper):
|
|||
dra = dragent.DRAgentCharm()
|
||||
self.assertEqual(dra.bgp_speaker_bindings(),
|
||||
[dragent.SPEAKER_BINDING])
|
||||
|
||||
def test_get_os_codename(self):
|
||||
dra = dragent.DRAgentCharm()
|
||||
codename = 'codename'
|
||||
with mock.patch('charms_openstack.charm.OpenStackCharm.'
|
||||
'get_os_codename_package',
|
||||
return_value=codename) as mock_get_os_codename:
|
||||
self.assertEquals(dra.get_os_codename(), codename)
|
||||
mock_get_os_codename.assert_called_with(
|
||||
dra.release_pkg, dra.package_codenames
|
||||
)
|
||||
|
||||
def test_disable_services(self):
|
||||
dra = dragent.DRAgentCharm()
|
||||
with mock.patch('charmhelpers.core.host.service') as mock_service:
|
||||
dra.disable_services()
|
||||
calls = [
|
||||
mock.call(action, svc)
|
||||
for action in ('disable', 'stop')
|
||||
for svc in dra.services
|
||||
]
|
||||
mock_service.assert_has_calls(calls)
|
||||
|
||||
def test_enable_services(self):
|
||||
dra = dragent.DRAgentCharm()
|
||||
with mock.patch('charmhelpers.core.host.service') as mock_service:
|
||||
dra.enable_services()
|
||||
calls = [
|
||||
mock.call(action, svc)
|
||||
for action in ('enable', 'start')
|
||||
for svc in dra.services
|
||||
]
|
||||
mock_service.assert_has_calls(calls)
|
||||
|
||||
def test_db_migration_overrides_base_class(self):
|
||||
dra = dragent.DRAgentCharm()
|
||||
with mock.patch(
|
||||
'charms_openstack.charm.OpenStackCharm.'
|
||||
'do_openstack_upgrade_db_migration') as base_db_migrate:
|
||||
dra.do_openstack_upgrade_db_migration()
|
||||
base_db_migrate.assert_not_called()
|
||||
|
|
Loading…
Reference in New Issue