summaryrefslogtreecommitdiff
path: root/oslo_policy/fixture.py
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2017-09-12 11:05:00 +0000
committerDoug Hellmann <doug@doughellmann.com>2017-09-12 11:06:46 +0000
commit9aa963fcf08d3ce115c5b4fc8de8837ac662d89c (patch)
tree2103216dbe69cbface39c8288e5f60b5cf4afbfe /oslo_policy/fixture.py
parentf874f26e44ac6781086e1badc5a53200900d355c (diff)
downloadoslo-policy-9aa963fcf08d3ce115c5b4fc8de8837ac662d89c.tar.gz
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>
Diffstat (limited to 'oslo_policy/fixture.py')
-rw-r--r--oslo_policy/fixture.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/oslo_policy/fixture.py b/oslo_policy/fixture.py
index a12aa1f..66ae6c6 100644
--- a/oslo_policy/fixture.py
+++ b/oslo_policy/fixture.py
@@ -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,
+ )
)