Merge "Simplify message of exception PolicyNotAuthorized"

This commit is contained in:
Jenkins 2017-05-24 20:21:56 +00:00 committed by Gerrit Code Review
commit deffa995a6
2 changed files with 5 additions and 5 deletions

View File

@ -296,9 +296,7 @@ class PolicyNotAuthorized(Exception):
"""Default exception raised for policy enforcement failure."""
def __init__(self, rule, target, creds):
msg = (_('%(target)s is disallowed by policy rule %(rule)s '
'with %(creds)s ') %
{'rule': rule, 'target': target, 'creds': creds})
msg = _("%(rule)s is disallowed by policy") % {'rule': rule}
super(PolicyNotAuthorized, self).__init__(msg)

View File

@ -724,8 +724,10 @@ class CheckFunctionTestCase(base.PolicyBaseTestCase):
# raised.
self.enforcer.set_rules(dict(default=_checks.FalseCheck()))
self.assertRaises(policy.PolicyNotAuthorized, self.enforcer.enforce,
'rule', 'target', 'creds', True)
self.assertRaisesRegex(policy.PolicyNotAuthorized,
" is disallowed by policy",
self.enforcer.enforce,
'rule', 'target', 'creds', True)
def test_check_raise_custom_exception(self):
self.enforcer.set_rules(dict(default=_checks.FalseCheck()))