Make policy file support in fixture optional

The ksfixtures.Policy object used to accept two arguments. One was
the path of the policy file and the other was the test fixture. Since
policy is now kept in code and the default policy file has been
removed from keystone source, we can simplify the fixture to
optionally deal with a file path, instead of passing a non-existant
file to it all the time.

Change-Id: I9d8c4cbf963099fe73e39dbf46e03f66f9a79f43
This commit is contained in:
Lance Bragstad 2018-08-22 18:05:57 +00:00
parent f872a40290
commit a394558dc4
6 changed files with 19 additions and 9 deletions

View File

@ -682,7 +682,7 @@ class TestCase(BaseTestCase):
return []
def _policy_fixture(self):
return ksfixtures.Policy(dirs.etc('policy.json'), self.config_fixture)
return ksfixtures.Policy(self.config_fixture)
@contextlib.contextmanager
def make_request(self, path='/', **kwargs):

View File

@ -20,7 +20,7 @@ from keystone.common.rbac_enforcer import policy
class Policy(fixtures.Fixture):
"""A fixture for working with policy configuration."""
def __init__(self, policy_file, config_fixture):
def __init__(self, config_fixture, policy_file=None):
self._policy_file = policy_file
self._config_fixture = config_fixture

View File

@ -46,7 +46,9 @@ class PolicyFileTestCase(unit.TestCase):
self.target = {}
def _policy_fixture(self):
return ksfixtures.Policy(self.tmpfilename, self.config_fixture)
return ksfixtures.Policy(
self.config_fixture, policy_file=self.tmpfilename
)
def test_modified_policy_reloads(self):
action = "example:test"

View File

@ -2600,8 +2600,10 @@ class TestTokenRevokeSelfAndAdmin(test_v3.RestfulTestCase):
)
def _policy_fixture(self):
return ksfixtures.Policy(unit.dirs.etc('policy.v3cloudsample.json'),
self.config_fixture)
return ksfixtures.Policy(
self.config_fixture,
policy_file=unit.dirs.etc('policy.v3cloudsample.json')
)
def test_user_revokes_own_token(self):
user_token = self.get_requested_token(

View File

@ -39,7 +39,9 @@ class IdentityTestFilteredCase(filtering.FilterTests,
"""Test filter enforcement on the v3 Identity API."""
def _policy_fixture(self):
return ksfixtures.Policy(self.tmpfilename, self.config_fixture)
return ksfixtures.Policy(
self.config_fixture, policy_file=self.tmpfilename
)
def setUp(self):
"""Setup for Identity Filter Test Cases."""

View File

@ -37,7 +37,9 @@ class IdentityTestProtectedCase(test_v3.RestfulTestCase):
"""Test policy enforcement on the v3 Identity API."""
def _policy_fixture(self):
return ksfixtures.Policy(self.tmpfilename, self.config_fixture)
return ksfixtures.Policy(
self.config_fixture, policy_file=self.tmpfilename
)
def setUp(self):
"""Setup for Identity Protection Test Cases.
@ -643,8 +645,10 @@ class IdentityTestv3CloudPolicySample(test_v3.RestfulTestCase,
"""Test policy enforcement of the sample v3 cloud policy file."""
def _policy_fixture(self):
return ksfixtures.Policy(unit.dirs.etc('policy.v3cloudsample.json'),
self.config_fixture)
return ksfixtures.Policy(
self.config_fixture,
policy_file=unit.dirs.etc('policy.v3cloudsample.json')
)
def setUp(self):
"""Setup for v3 Cloud Policy Sample Test Cases.