From 9aa963fcf08d3ce115c5b4fc8de8837ac662d89c Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 12 Sep 2017 11:05:00 +0000 Subject: [PATCH] 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 --- oslo_policy/fixture.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/oslo_policy/fixture.py b/oslo_policy/fixture.py index a12aa1f9..66ae6c64 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, + ) )