
The mock third party library was needed for mock support in py2 runtimes. Since we now only support py36 and later, we can use the standard lib unittest.mock module instead. Note that https://github.com/openstack/charms.openstack is used during tests and he need `mock`, unfortunatelly it doesn't declare `mock` in its requirements so it retrieve mock from other charm project (cross dependency). So we depend on charms.openstack first and when Ib1ed5b598a52375e29e247db9ab4786df5b6d142 will be merged then CI will pass without errors. Depends-On: Ib1ed5b598a52375e29e247db9ab4786df5b6d142 Change-Id: I55ccb5548917c8431b0080c956bec5543d31a9a3
78 lines
2.9 KiB
Python
78 lines
2.9 KiB
Python
# Copyright 2019 Canonical Ltd
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from unittest import mock
|
|
|
|
import reactive.masakari_handlers as handlers
|
|
|
|
import charms_openstack.test_utils as test_utils
|
|
|
|
|
|
class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|
|
|
def test_hooks(self):
|
|
defaults = [
|
|
'charm.installed',
|
|
'amqp.connected',
|
|
'shared-db.connected',
|
|
'identity-service.connected',
|
|
'identity-service.available', # enables SSL support
|
|
'config.changed',
|
|
'update-status']
|
|
hook_set = {
|
|
'when': {
|
|
'render_config': (
|
|
'shared-db.available',
|
|
'identity-service.available',
|
|
'amqp.available', ),
|
|
'init_db': ('config.rendered', ),
|
|
'cluster_connected': ('ha.connected', )}
|
|
}
|
|
self.registered_hooks_test_helper(handlers, hook_set, defaults)
|
|
|
|
|
|
class TestHandlers(test_utils.PatchHelper):
|
|
|
|
def _patch_provide_charm_instance(self):
|
|
masakari_charm = mock.MagicMock()
|
|
self.patch('charms_openstack.charm.provide_charm_instance',
|
|
name='provide_charm_instance',
|
|
new=mock.MagicMock())
|
|
self.provide_charm_instance().__enter__.return_value = masakari_charm
|
|
self.provide_charm_instance().__exit__.return_value = None
|
|
return masakari_charm
|
|
|
|
def test_render_config(self):
|
|
self.patch('charms.reactive.set_state', name='set_state')
|
|
masakari_charm = self._patch_provide_charm_instance()
|
|
handlers.render_config('keystone', 'shared-db', 'amqp')
|
|
masakari_charm.upgrade_if_available.assert_called_once_with(
|
|
('keystone', 'shared-db', 'amqp'))
|
|
masakari_charm.render_with_interfaces.assert_called_once_with(
|
|
('keystone', 'shared-db', 'amqp'))
|
|
masakari_charm.assess_status.assert_called_once_with()
|
|
self.set_state.assert_called_once_with('config.rendered')
|
|
|
|
def test_init_db(self):
|
|
masakari_charm = self._patch_provide_charm_instance()
|
|
handlers.init_db()
|
|
masakari_charm.db_sync.assert_called_once_with()
|
|
|
|
def test_cluster_connected(self):
|
|
masakari_charm = self._patch_provide_charm_instance()
|
|
handlers.cluster_connected('hacluster')
|
|
masakari_charm.configure_ha_resources.assert_called_once_with(
|
|
'hacluster')
|
|
masakari_charm.assess_status.assert_called_once_with()
|