diff options
| author | J08nY | 2017-08-01 01:00:34 +0200 |
|---|---|---|
| committer | J08nY | 2017-08-01 01:00:34 +0200 |
| commit | 8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b (patch) | |
| tree | a5d61f909810688d32fda0ba10ce422eccbb5be5 /src/mailman_pgp/config/tests/test_validator.py | |
| parent | 8c3ac4d693cfa6138a02bf2d58b98ff62fe4f234 (diff) | |
| parent | 89e7005f70a7feda03f15cbe39bf866a6f5bd059 (diff) | |
| download | mailman-pgp-8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b.tar.gz mailman-pgp-8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b.tar.zst mailman-pgp-8d4fdb5017bdeee344d9908ddc98b51ae3b7c79b.zip | |
Diffstat (limited to 'src/mailman_pgp/config/tests/test_validator.py')
| -rw-r--r-- | src/mailman_pgp/config/tests/test_validator.py | 86 |
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) |
