From: Kevin Benton Date: Wed, 7 Oct 2015 02:28:47 +0000 (-0700) Subject: Mock oslo policy HTTPCheck instead of urllib X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a0f1d9d6de1560be91d3001c8ac9f880a7a5a7e0;p=openstack-build%2Fneutron-build.git Mock oslo policy HTTPCheck instead of urllib We were mocking internal behavior of oslo policy by patching urllib. This will break with the upcoming oslo release that switches to requests. This patch changes the mock to the HTTPCheck level and we can leave implementation details testing up to oslo_policy. Change-Id: I07957f01307e25f1547197c720eea6e3e7f0ef5a Closes-Bug: #1503890 --- diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index ed230179f..bed9740c9 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -19,8 +19,6 @@ import mock from oslo_policy import policy as oslo_policy from oslo_serialization import jsonutils from oslo_utils import importutils -import six -import six.moves.urllib.request as urlrequest import neutron from neutron.api.v2 import attributes @@ -105,25 +103,24 @@ class PolicyTestCase(base.BaseTestCase): result = policy.enforce(self.context, action, self.target) self.assertEqual(result, True) - @mock.patch.object(urlrequest, 'urlopen', - return_value=six.StringIO("True")) - def test_enforce_http_true(self, mock_urlrequest): + #TODO(kevinbenton): replace these private method mocks with a fixture + @mock.patch.object(oslo_policy._checks.HttpCheck, '__call__', + return_value=True) + def test_enforce_http_true(self, mock_httpcheck): action = "example:get_http" target = {} result = policy.enforce(self.context, action, target) self.assertEqual(result, True) - def test_enforce_http_false(self): - - def fakeurlopen(url, post_data): - return six.StringIO("False") - - with mock.patch.object(urlrequest, 'urlopen', new=fakeurlopen): - action = "example:get_http" - target = {} - self.assertRaises(oslo_policy.PolicyNotAuthorized, - policy.enforce, self.context, - action, target) + #TODO(kevinbenton): replace these private method mocks with a fixture + @mock.patch.object(oslo_policy._checks.HttpCheck, '__call__', + return_value=False) + def test_enforce_http_false(self, mock_httpcheck): + action = "example:get_http" + target = {} + self.assertRaises(oslo_policy.PolicyNotAuthorized, + policy.enforce, self.context, + action, target) def test_templatized_enforcement(self): target_mine = {'tenant_id': 'fake'}