mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Also test pattern
This commit is contained in:
parent
4d4e94b59c
commit
07167422ba
@ -137,6 +137,18 @@ class ConfigTestCase(TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
item = config.StringConfig(title='Foo',
|
||||
description='Foo Item',
|
||||
pattern=r'^([\w_-]+)$')
|
||||
self.assertDictEqual(
|
||||
item.serialize(), {
|
||||
'type': 'string',
|
||||
'title': item.title,
|
||||
'description': item.description,
|
||||
'pattern': item.pattern
|
||||
}
|
||||
)
|
||||
|
||||
@skipIf(HAS_JSONSCHEMA is False, 'The \'jsonschema\' library is missing')
|
||||
def test_string_config_validation(self):
|
||||
class TestConf(config.Configuration):
|
||||
@ -190,6 +202,21 @@ class ConfigTestCase(TestCase):
|
||||
jsonschema.validate({'item': 'bin'}, TestConf.serialize())
|
||||
self.assertIn('is not one of', excinfo.exception.message)
|
||||
|
||||
class TestConf(config.Configuration):
|
||||
item = config.StringConfig(title='Foo', description='Foo Item',
|
||||
pattern=r'^([\w_-]+)$')
|
||||
|
||||
try:
|
||||
jsonschema.validate({'item': 'the-item'}, TestConf.serialize(),
|
||||
format_checker=jsonschema.FormatChecker())
|
||||
except jsonschema.exceptions.ValidationError as exc:
|
||||
self.fail('ValidationError raised: {0}'.format(exc))
|
||||
|
||||
with self.assertRaises(jsonschema.exceptions.ValidationError) as excinfo:
|
||||
jsonschema.validate({'item': 'the item'}, TestConf.serialize(),
|
||||
format_checker=jsonschema.FormatChecker())
|
||||
self.assertIn('does not match', excinfo.exception.message)
|
||||
|
||||
def test_email_config(self):
|
||||
item = config.EMailConfig(title='Foo', description='Foo Item')
|
||||
self.assertDictEqual(
|
||||
|
Loading…
Reference in New Issue
Block a user