Modify tests in test_generator

This change is needed to comment out rule from the generated
sample-policy file. Added new parameter 'include_help' to
_generate_sample method and changed the tests accordingly.

blueprint policy-docs

Change-Id: I6883f248dcd6ec4829e684210c2de44863431df7
This commit is contained in:
Anusha Unnam 2017-03-17 15:30:50 +00:00
parent d4ed4a09a7
commit bb33bf3a6d
2 changed files with 15 additions and 5 deletions

View File

@ -135,7 +135,7 @@ def _sort_and_format_by_section(policies, include_help=True):
include_help=include_help)
def _generate_sample(namespaces, output_file=None):
def _generate_sample(namespaces, output_file=None, include_help=True):
"""Generate a sample policy file.
List all of the policies available via the namespace specified in the
@ -145,13 +145,17 @@ def _generate_sample(namespaces, output_file=None):
'oslo.policy.policies'. Stevedore will look here for
policy options.
:param output_file: The path of a file to output to. stdout used if None.
:param include_help: True, generates a sample-policy file with help text
along with rules in which everything is commented out.
False, generates a sample-policy file with only rules.
"""
policies = _get_policies_dict(namespaces)
output_file = (open(output_file, 'w') if output_file
else sys.stdout)
for section in _sort_and_format_by_section(policies):
for section in _sort_and_format_by_section(policies,
include_help=include_help):
output_file.write(section)

View File

@ -60,7 +60,9 @@ class GenerateSampleTestCase(base.PolicyBaseTestCase):
output_file = self.get_config_file_fullname('policy.yaml')
with mock.patch('stevedore.named.NamedExtensionManager',
return_value=test_mgr) as mock_ext_mgr:
generator._generate_sample(['base_rules', 'rules'], output_file)
# generate sample-policy file with only rules
generator._generate_sample(['base_rules', 'rules'], output_file,
include_help=False)
mock_ext_mgr.assert_called_once_with(
'oslo.policy.policies', names=['base_rules', 'rules'],
on_load_failure_callback=generator.on_load_failure_callback,
@ -230,7 +232,9 @@ class GeneratePolicyTestCase(base.PolicyBaseTestCase):
sample_file = self.get_config_file_fullname('policy-sample.yaml')
with mock.patch('stevedore.named.NamedExtensionManager',
return_value=test_mgr):
generator._generate_sample(['base_rules', 'rules'], sample_file)
# generate sample-policy file with only rules
generator._generate_sample(['base_rules', 'rules'], sample_file,
include_help=False)
enforcer = policy.Enforcer(self.conf, policy_file='policy-sample.yaml')
# register an opt defined in the file
@ -288,7 +292,9 @@ class ListRedundantTestCase(base.PolicyBaseTestCase):
sample_file = self.get_config_file_fullname('policy-sample.yaml')
with mock.patch('stevedore.named.NamedExtensionManager',
return_value=test_mgr):
generator._generate_sample(['base_rules', 'rules'], sample_file)
# generate sample-policy file with only rules
generator._generate_sample(['base_rules', 'rules'], sample_file,
include_help=False)
enforcer = policy.Enforcer(self.conf, policy_file='policy-sample.yaml')
# register opts that match those defined in policy-sample.yaml