Merge "oslopolicy-sample-generator description support"

This commit is contained in:
Jenkins 2017-03-21 12:55:58 +00:00 committed by Gerrit Code Review
commit 0f10c1aaa3
2 changed files with 25 additions and 9 deletions

View File

@ -101,18 +101,25 @@ def _format_help_text(description):
def _format_rule_default_yaml(default, include_help=True):
"""Create a yaml node from the provided policy.RuleDefault.
"""Create a yaml node from policy.RuleDefault or policy.DocumentedRuleDefault.
:param default: A policy.RuleDefault object
:param default: A policy.RuleDefault or policy.DocumentedRuleDefault object
:returns: A string containing a yaml representation of the RuleDefault
"""
text = ('"%(name)s": "%(check_str)s"\n' %
{'name': default.name,
'check_str': default.check_str})
op = ""
if hasattr(default, 'operations'):
for operation in default.operations:
op += ('# %(method)s %(path)s\n' %
{'method': operation['method'], 'path': operation['path']})
if include_help:
text = ('%(help)s\n#%(text)s\n' %
text = ('%(help)s\n%(op)s#%(text)s\n' %
{'help': _format_help_text(default.description),
'op': op,
'text': text})
return text

View File

@ -26,12 +26,17 @@ from oslo_policy.tests import base
OPTS = {'base_rules': [policy.RuleDefault('admin', 'is_admin:True',
description='Basic admin check'),
policy.RuleDefault('owner',
'project_id:%(project_id)s',
description='This is a long '
'description to check '
'that line wrapping '
'functions properly')],
policy.DocumentedRuleDefault('owner',
('project_id:%'
'(project_id)s'),
'This is a long '
'description to check '
'that line wrapping '
'functions properly',
[{'path': '/foo/',
'method': 'GET'},
{'path': '/test/',
'method': 'POST'}])],
'custom_field': [policy.RuleDefault('shared',
'field:networks:shared=True')],
'rules': [policy.RuleDefault('admin_or_owner',
@ -93,6 +98,8 @@ class GenerateSampleTestCase(base.PolicyBaseTestCase):
# This is a long description to check that line wrapping functions
# properly
# GET /foo/
# POST /test/
#"owner": "project_id:%(project_id)s"
#
@ -130,6 +137,8 @@ class GenerateSampleTestCase(base.PolicyBaseTestCase):
# This is a long description to check that line wrapping functions
# properly
# GET /foo/
# POST /test/
#"owner": "project_id:%(project_id)s"
#