config: Add ExtensionConfigSchema.
This commit is contained in:
parent
0535084162
commit
980792e527
@ -209,3 +209,17 @@ class ConfigSchema(object):
|
||||
if errors:
|
||||
raise exceptions.ConfigError(errors)
|
||||
return values
|
||||
|
||||
|
||||
class ExtensionConfigSchema(ConfigSchema):
|
||||
"""Sub-classed ConfigSchema for use in extensions.
|
||||
|
||||
Ensures that `enabled` config value is present and that section name is
|
||||
prefixed with ext.
|
||||
"""
|
||||
def __init__(self):
|
||||
super(ExtensionConfigSchema, self).__init__()
|
||||
self['enabled'] = Boolean()
|
||||
|
||||
def format(self, name, values):
|
||||
return super(ExtensionConfigSchema, self).format('ext.%s' % name, values)
|
||||
|
||||
@ -320,3 +320,13 @@ class ConfigSchemaTest(unittest.TestCase):
|
||||
self.assertNotIn('foo', cm.exception)
|
||||
self.assertIn('failure', cm.exception['bar'])
|
||||
self.assertIn('not found', cm.exception['baz'])
|
||||
|
||||
|
||||
class ExtensionConfigSchemaTest(unittest.TestCase):
|
||||
def test_schema_includes_enabled(self):
|
||||
schema = config.ExtensionConfigSchema()
|
||||
self.assertIsInstance(schema['enabled'], config.Boolean)
|
||||
|
||||
def test_section_name_is_prefixed(self):
|
||||
schema = config.ExtensionConfigSchema()
|
||||
self.assertEqual('[ext.foo]', schema.format('foo', {}))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user