Merge "Init policy in pecan after hook as well"

This commit is contained in:
Jenkins 2017-03-14 23:13:54 +00:00 committed by Gerrit Code Review
commit 5cf17dd8ec
2 changed files with 12 additions and 0 deletions

View File

@ -163,6 +163,7 @@ class PolicyHook(hooks.PecanHook):
return
if not data or (resource not in data and collection not in data):
return
policy.init()
is_single = resource in data
action_type = pecan_constants.ACTION_MAP[state.request.method]
if action_type == 'get':

View File

@ -221,6 +221,17 @@ class TestPolicyEnforcementHook(test_functional.PecanFunctionalTest):
json_response = jsonutils.loads(response.body)
self.assertNotIn('restricted_attr', json_response['mehs'][0])
def test_after_inits_policy(self):
self.mock_plugin.get_mehs.return_value = [{
'id': 'xxx',
'attr': 'meh',
'restricted_attr': '',
'tenant_id': 'tenid'}]
policy.reset()
response = self.app.get('/v2.0/mehs',
headers={'X-Project-Id': 'tenid'})
self.assertEqual(200, response.status_int)
class TestMetricsNotifierHook(test_functional.PecanFunctionalTest):