rewrite HttpCheckFixture to not mock out entire HttpCheck class

The fixture only needs to mock out the __call__ method, and it needs
to use a real function as the replacement so that in the follow-up
patch we can introspect the result to see if we need to pass the rule
argument to it.

Change-Id: I22b0fc6bb3e40b54a24d9d53c9a20731af0064ee
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-09-12 11:05:00 +00:00
parent f874f26e44
commit 9aa963fcf0
1 changed files with 15 additions and 7 deletions

View File

@ -14,10 +14,8 @@ __all__ = ['HttpCheckFixture']
import fixtures
from oslo_policy import policy as oslo_policy
class HttpCheckFixture(fixtures.MockPatchObject):
class HttpCheckFixture(fixtures.Fixture):
"""Helps short circuit the external http call"""
def __init__(self, return_value=True):
@ -27,8 +25,18 @@ class HttpCheckFixture(fixtures.MockPatchObject):
implies that the policy check failed
:type return_value: boolean
"""
super(HttpCheckFixture, self).__init__(
oslo_policy._checks.HttpCheck,
'__call__',
return_value=return_value
super(HttpCheckFixture, self).__init__()
self.return_value = return_value
def setUp(self):
super(HttpCheckFixture, self).setUp()
def mocked_call(target, cred, enforcer, rule):
return self.return_value
self.useFixture(
fixtures.MonkeyPatch(
'oslo_policy._checks.HttpCheck.__call__',
mocked_call,
)
)