aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/config/tests/test_validator.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/config/tests/test_validator.py')
-rw-r--r--src/mailman_pgp/config/tests/test_validator.py86
1 files changed, 25 insertions, 61 deletions
diff --git a/src/mailman_pgp/config/tests/test_validator.py b/src/mailman_pgp/config/tests/test_validator.py
index d24dfc7..10beba6 100644
--- a/src/mailman_pgp/config/tests/test_validator.py
+++ b/src/mailman_pgp/config/tests/test_validator.py
@@ -18,100 +18,64 @@
""""""
from unittest import TestCase
-from pkg_resources import resource_filename, resource_string
-
-from mailman_pgp.config import Config, ConfigValidator
+from mailman_pgp.config.config import Config
+from mailman_pgp.config.validator import ConfigValidator
from mailman_pgp.testing.layers import PGPLayer
-class TestConfigs(TestCase):
- layer = PGPLayer
-
- def setUp(self):
- self.validator = ConfigValidator(
- resource_string('mailman_pgp.config',
- 'schema.cfg').decode('utf-8'))
-
- def test_default_config(self):
- cfg = Config()
- cfg.read(resource_filename('mailman_pgp.config', 'mailman_pgp.cfg'))
- self.validator.validate(cfg)
-
- def test_testing_config(self):
- cfg = Config()
- cfg.read(resource_filename('mailman_pgp.testing', 'mailman_pgp.cfg'))
- self.validator.validate(cfg)
-
-
class TestValidator(TestCase):
layer = PGPLayer
- def test_builtins(self):
+ def test_missing_section(self):
schema = """\
[test]
- test_option: int
+ test_option: something
"""
validator = ConfigValidator(schema)
- valid = Config()
- valid.read_string("""\
- [test]
- test_option: 5
- """)
- invalid = Config()
- invalid.read_string("""\
- [test]
- test_option: xyz
+ cfg = Config()
+ cfg.read_string("""\
+ [other_section]
+ some_option: something else
""")
- validator.validate(valid)
- self.assertRaises(ValueError, validator.validate, invalid)
+ self.assertRaises(ValueError, validator.validate, cfg)
- def test_callable(self):
+ def test_additional_section(self):
schema = """\
[test]
- test_option: lazr.config.as_boolean
+ test_option: something
"""
validator = ConfigValidator(schema)
- valid = Config()
- valid.read_string("""\
- [test]
- test_option: yes
- """)
- invalid = Config()
- invalid.read_string("""\
+ cfg = Config()
+ cfg.read_string("""\
[test]
- test_option: xyz
+ test_option: something
+ [other_section]
+ some_option: something else
""")
- validator.validate(valid)
- self.assertRaises(ValueError, validator.validate, invalid)
+ self.assertRaises(ValueError, validator.validate, cfg)
- def test_regex(self):
+ def test_missing_option(self):
schema = """\
[test]
- test_option: 29*4
+ test_option: something
"""
validator = ConfigValidator(schema)
- valid = Config()
- valid.read_string("""\
- [test]
- test_option: 2999999994
- """)
- invalid = Config()
- invalid.read_string("""\
+ cfg = Config()
+ cfg.read_string("""\
[test]
- test_option: xyz
""")
- validator.validate(valid)
- self.assertRaises(ValueError, validator.validate, invalid)
+ self.assertRaises(ValueError, validator.validate, cfg)
- def test_none(self):
+ def test_additional_option(self):
schema = """\
[test]
- test_option:
+ test_option: something
"""
validator = ConfigValidator(schema)
cfg = Config()
cfg.read_string("""\
[test]
test_option: something
+ other_option: something else
""")
self.assertRaises(ValueError, validator.validate, cfg)