summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhar Hrachyshka <ihrachys@redhat.com>2015-02-26 17:08:56 +0100
committerIhar Hrachyshka <ihrachys@redhat.com>2015-03-03 14:14:55 +0100
commit05b30754a45da48a6c65f9fd9dccf84cfd78ab49 (patch)
tree810ce50f811fecb6fffd28a523d7cbf7a98671c6
parent8ddd45d23d3a296b871c54a7280ac8839c413763 (diff)
downloadoslo-policy-05b30754a45da48a6c65f9fd9dccf84cfd78ab49.tar.gz
Expose register and Check as part of public API
Those symbols are used by Neutron for legitimate cases (defining a custom check). Change-Id: I96e9838068194b7b0903a738a94eb8f1b01ecdbe Closes-Bug: #1426005
-rw-r--r--oslo_policy/policy.py4
-rw-r--r--oslo_policy/tests/test_policy.py12
2 files changed, 16 insertions, 0 deletions
diff --git a/oslo_policy/policy.py b/oslo_policy/policy.py
index e4f4a07..e24f881 100644
--- a/oslo_policy/policy.py
+++ b/oslo_policy/policy.py
@@ -219,6 +219,10 @@ from oslo_policy import opts
LOG = logging.getLogger(__name__)
+register = _checks.register
+Check = _checks.Check
+
+
class PolicyNotAuthorized(Exception):
"""Default exception raised for policy enforcement failure."""
diff --git a/oslo_policy/tests/test_policy.py b/oslo_policy/tests/test_policy.py
index 6cb92fb..f1f7ddb 100644
--- a/oslo_policy/tests/test_policy.py
+++ b/oslo_policy/tests/test_policy.py
@@ -425,3 +425,15 @@ class CheckFunctionTestCase(base.PolicyBaseTestCase):
self.assertEqual(dict(kw1='kwarg1', kw2='kwarg2'), exc.kwargs)
else:
self.fail('enforcer.enforce() failed to raise requested exception')
+
+
+class RegisterCheckTestCase(base.PolicyBaseTestCase):
+
+ @mock.patch.object(_checks, 'registered_checks', {})
+ def test_register_check(self):
+ class TestCheck(policy.Check):
+ pass
+
+ policy.register('spam', TestCheck)
+
+ self.assertEqual(dict(spam=TestCheck), _checks.registered_checks)