do not mock private methods of objects from libraries

This patch fixes tests that were using mock to replace a private method
of a library instead of using the public testing interface provided by
that library. The new release of stevedore changes the name of that
private method, which breaks these tests. Because the requirements list
is gated on glance's unit tests, the test failure is preventing other
projects from adopting the new release of stevedore.

Change-Id: Ie9af444e7f8842ffb3e275ede52b802de02e6e99
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-01-27 17:56:44 -05:00 committed by Davanum Srinivas (dims)
parent 0108666f2b
commit d64f6bcbae
2 changed files with 35 additions and 17 deletions

View File

@ -43,8 +43,8 @@ CONF.register_opts(plugins_opts)
class ArtifactsPluginLoader(object):
def __init__(self, namespace):
self.mgr = enabled.EnabledExtensionManager(
def __init__(self, namespace, test_plugins=None):
self.mgr = test_plugins or enabled.EnabledExtensionManager(
check_func=self._gen_check_func(),
namespace=namespace,
propagate_map_exceptions=True,

View File

@ -17,9 +17,9 @@ import uuid
import mock
from oslo_serialization import jsonutils
import pkg_resources
import requests
from six.moves import http_client as http
from stevedore import extension
from glance.api.glare.v0_1 import glare
from glance.api.glare.v0_1 import router
@ -60,20 +60,38 @@ class ArtifactWithBlob(definitions.ArtifactType):
def _create_resource():
plugins = None
mock_this = 'stevedore.extension.ExtensionManager._find_entry_points'
with mock.patch(mock_this) as fep:
path = 'glance.tests.functional.glare.test_glare'
fep.return_value = [
pkg_resources.EntryPoint.parse('WithProps=%s:Artifact' % path),
pkg_resources.EntryPoint.parse(
'NoProp=%s:ArtifactNoProps' % path),
pkg_resources.EntryPoint.parse(
'NoProp=%s:ArtifactNoProps1' % path),
pkg_resources.EntryPoint.parse(
'WithBlob=%s:ArtifactWithBlob' % path)
]
plugins = loader.ArtifactsPluginLoader('glance.artifacts.types')
test_loader = extension.ExtensionManager.make_test_instance(
extensions=[
extension.Extension(
name='WithProps',
entry_point=mock.Mock(),
plugin=Artifact,
obj=None,
),
extension.Extension(
name='NoProp',
entry_point=mock.Mock(),
plugin=ArtifactNoProps,
obj=None,
),
extension.Extension(
name='NoProp',
entry_point=mock.Mock(),
plugin=ArtifactNoProps1,
obj=None,
),
extension.Extension(
name='WithBlob',
entry_point=mock.Mock(),
plugin=ArtifactWithBlob,
obj=None,
),
],
)
plugins = loader.ArtifactsPluginLoader(
'glance.artifacts.types',
test_plugins=test_loader,
)
deserializer = glare.RequestDeserializer(plugins=plugins)
serializer = glare.ResponseSerializer()
controller = glare.ArtifactsController(plugins=plugins)