5cf940702e
The __future__ module [1] was used in this context to ensure compatibility between python 2 and python 3. We previously dropped the support of python 2.7 [2] and now we only support python 3 so we don't need to continue to use this module and the imports listed below. Imports commonly used and their related PEPs: - `division` is related to PEP 238 [3] - `print_function` is related to PEP 3105 [4] - `unicode_literals` is related to PEP 3112 [5] - `with_statement` is related to PEP 343 [6] - `absolute_import` is related to PEP 328 [7] [1] https://docs.python.org/3/library/__future__.html [2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html [3] https://www.python.org/dev/peps/pep-0238 [4] https://www.python.org/dev/peps/pep-3105 [5] https://www.python.org/dev/peps/pep-3112 [6] https://www.python.org/dev/peps/pep-0343 [7] https://www.python.org/dev/peps/pep-0328 Change-Id: I7a471711b984cdc8e5cb74ebcf74420fa73202a7
124 lines
4.6 KiB
Python
124 lines
4.6 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.
|
|
|
|
import mock
|
|
|
|
import charm.openstack.keystone_saml_mellon as keystone_saml_mellon
|
|
import reactive.keystone_saml_mellon_handlers as handlers
|
|
|
|
import charms_openstack.test_utils as test_utils
|
|
|
|
|
|
class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|
|
|
def test_hooks(self):
|
|
defaults = [
|
|
'charm.installed',
|
|
'update-status']
|
|
hook_set = {
|
|
'hook': {
|
|
'default_upgrade_charm': ('upgrade-charm',),
|
|
},
|
|
'when': {
|
|
'publish_sp_fid': (
|
|
'keystone-fid-service-provider.connected',),
|
|
'render_config': (
|
|
'keystone-fid-service-provider.available',),
|
|
'configure_websso': (
|
|
'websso-fid-service-provider.connected',),
|
|
},
|
|
'when_not': {
|
|
'keystone_departed': (
|
|
'keystone-fid-service-provider.connected',),
|
|
'assess_status': ('always.run',),
|
|
},
|
|
}
|
|
# test that the hooks were registered via the
|
|
# reactive.keystone_saml_mellon_handlers
|
|
self.registered_hooks_test_helper(handlers, hook_set, defaults)
|
|
|
|
|
|
class TestKeystoneSAMLMellonHandlers(test_utils.PatchHelper):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.patch_release(
|
|
keystone_saml_mellon.KeystoneSAMLMellonCharm.release)
|
|
self.keystone_saml_mellon_charm = mock.MagicMock()
|
|
self.patch_object(handlers.charm, 'provide_charm_instance',
|
|
new=mock.MagicMock())
|
|
self.provide_charm_instance().__enter__.return_value = (
|
|
self.keystone_saml_mellon_charm)
|
|
self.provide_charm_instance().__exit__.return_value = None
|
|
|
|
self.patch_object(handlers.reactive, 'any_file_changed',
|
|
new=mock.MagicMock())
|
|
|
|
self.endpoint = mock.MagicMock()
|
|
|
|
self.protocol_name = "mapped"
|
|
self.remote_id_attribute = "https://samltest.id"
|
|
self.idp_name = "samltest"
|
|
self.user_facing_name = "samltest.id"
|
|
self.keystone_saml_mellon_charm.options.protocol_name = (
|
|
self.protocol_name)
|
|
self.keystone_saml_mellon_charm.options.remote_id_attribute = (
|
|
self.remote_id_attribute)
|
|
self.keystone_saml_mellon_charm.options.idp_name = self.idp_name
|
|
self.keystone_saml_mellon_charm.options.user_facing_name = (
|
|
self.user_facing_name)
|
|
|
|
self.all_joined_units = []
|
|
for i in range(0, 2):
|
|
unit = mock.MagicMock()
|
|
unit.name = "keystone-{}".format(i)
|
|
unit.recieved = {"hostname": unit.name,
|
|
"port": "5000",
|
|
"tls-enabled": True}
|
|
self.all_joined_units.append(unit)
|
|
|
|
def test_keystone_departed(self):
|
|
handlers.keystone_departed()
|
|
self.keystone_saml_mellon_charm.remove_config.assert_called_once_with()
|
|
|
|
def test_publish_sp_fid(self):
|
|
handlers.publish_sp_fid(self.endpoint)
|
|
self.endpoint.publish.assert_called_once_with(
|
|
self.protocol_name, self.remote_id_attribute)
|
|
|
|
def test_render_config(self):
|
|
# No restart
|
|
self.any_file_changed.return_value = False
|
|
(self.keystone_saml_mellon_charm
|
|
.configuration_complete.return_value) = True
|
|
|
|
handlers.render_config(self.endpoint)
|
|
self.keystone_saml_mellon_charm.render_config.assert_called_once_with(
|
|
self.endpoint)
|
|
self.endpoint.request_restart.assert_not_called()
|
|
|
|
# Restart
|
|
self.any_file_changed.return_value = True
|
|
handlers.render_config(self.endpoint)
|
|
self.endpoint.request_restart.assert_called_once_with()
|
|
|
|
def test_configure_websso(self):
|
|
handlers.configure_websso(self.endpoint)
|
|
self.endpoint.publish.assert_called_once_with(
|
|
self.protocol_name, self.idp_name, self.user_facing_name)
|
|
|
|
def test_assess_status(self):
|
|
handlers.assess_status()
|
|
self.keystone_saml_mellon_charm.assess_status.assert_called_once_with()
|