From ec8620a4e2bc4e62e75df8b9608fca84ad99af2c Mon Sep 17 00:00:00 2001 From: Alexander Pugachev Date: Mon, 10 Jul 2017 12:37:28 +0100 Subject: [PATCH] Increases code coverage Covers manilaclient/common/apiclient/auth.py:discover_auth_systems(). Coverage for manilaclient/common/apiclient/auth.py goes from 0% to 35%. Overall coverage goes from 71% to 74%. Change-Id: I685051bbe3e0f82e69efef7d25aa42e385acc3f9 Partial-Bug: #1364800 --- manilaclient/common/apiclient/auth.py | 5 +- manilaclient/common/constants.py | 2 + .../tests/unit/common/apiclient/__init__.py | 0 .../tests/unit/common/apiclient/test_auth.py | 48 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 manilaclient/tests/unit/common/apiclient/__init__.py create mode 100644 manilaclient/tests/unit/common/apiclient/test_auth.py diff --git a/manilaclient/common/apiclient/auth.py b/manilaclient/common/apiclient/auth.py index a2250da..ed640a1 100644 --- a/manilaclient/common/apiclient/auth.py +++ b/manilaclient/common/apiclient/auth.py @@ -25,7 +25,7 @@ import six from stevedore import extension from manilaclient.common.apiclient import exceptions - +from manilaclient.common import constants _discovered_plugins = {} @@ -41,8 +41,7 @@ def discover_auth_systems(): def add_plugin(ext): _discovered_plugins[ext.name] = ext.plugin - ep_namespace = "manilaclient.common.apiclient.auth" - mgr = extension.ExtensionManager(ep_namespace) + mgr = extension.ExtensionManager(constants.EXTENSION_PLUGIN_NAMESPACE) mgr.map(add_plugin) diff --git a/manilaclient/common/constants.py b/manilaclient/common/constants.py index 4e0814f..5249f83 100644 --- a/manilaclient/common/constants.py +++ b/manilaclient/common/constants.py @@ -79,3 +79,5 @@ V1_SERVICE_TYPE = 'share' V2_SERVICE_TYPE = 'sharev2' SERVICE_TYPES = {'1': V1_SERVICE_TYPE, '2': V2_SERVICE_TYPE} + +EXTENSION_PLUGIN_NAMESPACE = 'manilaclient.common.apiclient.auth' diff --git a/manilaclient/tests/unit/common/apiclient/__init__.py b/manilaclient/tests/unit/common/apiclient/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/manilaclient/tests/unit/common/apiclient/test_auth.py b/manilaclient/tests/unit/common/apiclient/test_auth.py new file mode 100644 index 0000000..035f344 --- /dev/null +++ b/manilaclient/tests/unit/common/apiclient/test_auth.py @@ -0,0 +1,48 @@ +# 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 ddt +import mock + +from manilaclient.common.apiclient import auth +from manilaclient.common import constants +from manilaclient.tests.unit import utils + + +@ddt.ddt +class DiscoverAuthSystems(utils.TestCase): + + @ddt.unpack + @ddt.data( + {'plugins': {'a': 42, 'b': 'bar'}, 'discovered': {}}, + {'plugins': {'a': 42, 'b': 'bar'}, 'discovered': {'b': 'overwrite'}}, + {'plugins': {'a': 42, 'b': 'bar'}, 'discovered': {'c': 'reset'}} + ) + @mock.patch.dict('stevedore.extension.ExtensionManager.ENTRY_POINT_CACHE', + clear=True) + def test_plugins(self, plugins, discovered): + mock_plugins = [] + for name, return_value in plugins.items(): + plugin = mock.Mock() + plugin.resolve = mock.Mock(return_value=return_value) + plugin.name = name + mock_plugins.append(plugin) + with mock.patch.dict( + 'manilaclient.common.apiclient.auth._discovered_plugins', + discovered, clear=True): + with mock.patch('pkg_resources.iter_entry_points') as ep_mock: + ep_mock.return_value = mock_plugins + auth.discover_auth_systems() + ep_mock.assert_called_with( + constants.EXTENSION_PLUGIN_NAMESPACE + ) + self.assertEqual(plugins, auth._discovered_plugins)