mogan/nimble/tests/policy_fixture.py
Shaohe Feng f9e3c1fb01 add PolicyFixture for functional test.
At present, policy_data is empty.
And policy_data will be written in a policy.json file in /tmp path.
such as:
    /tmp/tmppgM04u/tmpgVJy4J/policy.json

So we want to pass the authorization for api test, we need to add the policy
item in this policy_data.

Such as:
 policy_data = """
 {
   'nimble:instance:get': '@'
 }
 """

Change-Id: I1a645312ea8ba98310945121c0205280ac740c09
2016-11-17 03:41:25 +08:00

44 lines
1.3 KiB
Python

# Copyright 2016 Intel
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import fixtures
from oslo_config import cfg
from oslo_policy import opts as policy_opts
from nimble.common import policy as nimble_policy
CONF = cfg.CONF
policy_data = """
{
}
"""
class PolicyFixture(fixtures.Fixture):
def setUp(self):
super(PolicyFixture, self).setUp()
self.policy_dir = self.useFixture(fixtures.TempDir())
self.policy_file_name = os.path.join(self.policy_dir.path,
'policy.json')
with open(self.policy_file_name, 'w') as policy_file:
policy_file.write(policy_data)
policy_opts.set_defaults(CONF)
CONF.set_override('policy_file', self.policy_file_name, 'oslo_policy')
nimble_policy._ENFORCER = None
self.addCleanup(nimble_policy.get_enforcer().clear)