aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJ08nY2017-08-01 00:34:47 +0200
committerJ08nY2017-08-01 00:34:47 +0200
commitcce2409e111c4b29bb8739c0699885007e7b81a2 (patch)
tree5345dfc50cbc4c03aef2044ffdafe6b41dd03443 /src
parent8f821848175281cc95f1e4ef1294ec6ca216c2c3 (diff)
downloadmailman-pgp-cce2409e111c4b29bb8739c0699885007e7b81a2.tar.gz
mailman-pgp-cce2409e111c4b29bb8739c0699885007e7b81a2.tar.zst
mailman-pgp-cce2409e111c4b29bb8739c0699885007e7b81a2.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman_pgp/config/__init__.py36
-rw-r--r--src/mailman_pgp/config/config.py61
-rw-r--r--src/mailman_pgp/config/converter.py8
-rw-r--r--src/mailman_pgp/config/tests/test_config.py34
-rw-r--r--src/mailman_pgp/config/tests/test_converter.py27
-rw-r--r--src/mailman_pgp/config/tests/test_validator.py24
-rw-r--r--src/mailman_pgp/plugin.py1
7 files changed, 107 insertions, 84 deletions
diff --git a/src/mailman_pgp/config/__init__.py b/src/mailman_pgp/config/__init__.py
index 13b6eba..7e86f45 100644
--- a/src/mailman_pgp/config/__init__.py
+++ b/src/mailman_pgp/config/__init__.py
@@ -15,42 +15,10 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-"""Mailman PGP configuration module."""
-
-from configparser import ConfigParser
-
from mailman.config import config as mailman_config
-from mailman.utilities.modules import expand_path
-from pkg_resources import resource_string
-from public.public import public
-
-from mailman_pgp.config.validator import ConfigValidator
-
-
-@public
-class Config(ConfigParser):
- """A ConfigParser with a name."""
-
- def load(self, name):
- """
- Load the plugin configuration, and set our name.
-
- :param name: The name to set/load configuration for.
- :type name: str
- """
- self.name = name
- self.read(expand_path(
- dict(mailman_config.plugin_configs)[self.name].configuration))
-
- def validate(self):
- """
-
- """
- validator = ConfigValidator(
- resource_string('mailman_pgp.config',
- 'schema.cfg').decode('utf-8'))
- validator.validate(self)
+from public import public
+from mailman_pgp.config.config import Config
config = Config()
public(config=config)
diff --git a/src/mailman_pgp/config/config.py b/src/mailman_pgp/config/config.py
new file mode 100644
index 0000000..7999e65
--- /dev/null
+++ b/src/mailman_pgp/config/config.py
@@ -0,0 +1,61 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""Mailman PGP configuration module."""
+from configparser import ConfigParser
+
+from mailman.config import config as mailman_config
+from mailman.utilities.modules import expand_path
+from pkg_resources import resource_string
+from public.public import public
+
+from mailman_pgp.config.converter import ConfigConverter
+from mailman_pgp.config.validator import ConfigValidator
+
+
+@public
+class Config(ConfigParser):
+ """A ConfigParser with a name."""
+
+ def load(self, name):
+ """
+ Load the plugin configuration, and set our name.
+
+ :param name: The name to set/load configuration for.
+ :type name: str
+ """
+ self.name = name
+ self.read(expand_path(
+ dict(mailman_config.plugin_configs)[self.name].configuration))
+
+ def validate(self):
+ """
+
+ """
+ validator = ConfigValidator(
+ resource_string('mailman_pgp.config',
+ 'schema.cfg').decode('utf-8'))
+ validator.validate(self)
+
+ def convert(self):
+ """
+
+ """
+ converter = ConfigConverter(
+ resource_string('mailman_pgp.config',
+ 'schema.cfg').decode('utf-8'))
+ converter.convert(self)
diff --git a/src/mailman_pgp/config/converter.py b/src/mailman_pgp/config/converter.py
index 6f458d9..ac2cf22 100644
--- a/src/mailman_pgp/config/converter.py
+++ b/src/mailman_pgp/config/converter.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-""""""
+"""Config conversion."""
import builtins
import re
from configparser import ConfigParser
@@ -41,8 +41,8 @@ class ConfigConverter:
out[section] = dict()
for option in self.schema.options(section):
out[section][option] = self._transform_option(
- cfg.get(section, option),
- self.schema.get(section, option))
+ cfg.get(section, option),
+ self.schema.get(section, option))
return out
def _transform_option(self, value, schema):
@@ -58,7 +58,7 @@ class ConfigConverter:
match = re.search(schema, value)
if match is None:
raise ValueError
- return match
+ return match.group()
if call is None:
raise ValueError
diff --git a/src/mailman_pgp/config/tests/test_config.py b/src/mailman_pgp/config/tests/test_config.py
index 3ad4ca2..d3ef9ea 100644
--- a/src/mailman_pgp/config/tests/test_config.py
+++ b/src/mailman_pgp/config/tests/test_config.py
@@ -15,12 +15,15 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
+""""""
from unittest import TestCase
+from pkg_resources import resource_filename, resource_string
+
from mailman_pgp.config import config
-from mailman_pgp.database import Database
-from mailman_pgp.pgp import PGP
-from mailman_pgp.testing.layers import PGPConfigLayer
+from mailman_pgp.config.config import Config
+from mailman_pgp.config.validator import ConfigValidator
+from mailman_pgp.testing.layers import PGPConfigLayer, PGPLayer
class TestConfig(TestCase):
@@ -29,14 +32,21 @@ class TestConfig(TestCase):
def test_name(self):
self.assertEqual(config.name, 'pgp')
- def test_sections(self):
- sections = sorted(['db', 'keydirs', 'keypairs', 'queues', 'misc'])
- self.assertListEqual(sorted(config.sections()), sections)
- def test_db(self):
- self.assertTrue(hasattr(config, 'db'))
- self.assertIsInstance(config.db, Database)
+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_pgp(self):
- self.assertTrue(hasattr(config, 'pgp'))
- self.assertIsInstance(config.pgp, PGP)
+ def test_testing_config(self):
+ cfg = Config()
+ cfg.read(resource_filename('mailman_pgp.testing', 'mailman_pgp.cfg'))
+ self.validator.validate(cfg)
diff --git a/src/mailman_pgp/config/tests/test_converter.py b/src/mailman_pgp/config/tests/test_converter.py
index 0509a44..842ccc4 100644
--- a/src/mailman_pgp/config/tests/test_converter.py
+++ b/src/mailman_pgp/config/tests/test_converter.py
@@ -18,7 +18,7 @@
""""""
from unittest import TestCase
-from mailman_pgp.config import Config
+from mailman_pgp.config.config import Config
from mailman_pgp.config.converter import ConfigConverter
from mailman_pgp.testing.layers import PGPLayer
@@ -31,7 +31,7 @@ class TestConverter(TestCase):
[test]
test_option: int
"""
- validator = ConfigConverter(schema)
+ converter = ConfigConverter(schema)
valid = Config()
valid.read_string("""\
[test]
@@ -42,15 +42,16 @@ class TestConverter(TestCase):
[test]
test_option: xyz
""")
- validator.convert(valid)
- self.assertRaises(ValueError, validator.convert, invalid)
+ out = converter.convert(valid)
+ self.assertEqual(out['test']['test_option'], 5)
+ self.assertRaises(ValueError, converter.convert, invalid)
def test_callable(self):
schema = """\
[test]
test_option: lazr.config.as_boolean
"""
- validator = ConfigConverter(schema)
+ converter = ConfigConverter(schema)
valid = Config()
valid.read_string("""\
[test]
@@ -61,15 +62,16 @@ class TestConverter(TestCase):
[test]
test_option: xyz
""")
- validator.convert(valid)
- self.assertRaises(ValueError, validator.convert, invalid)
+ out = converter.convert(valid)
+ self.assertEqual(out['test']['test_option'], True)
+ self.assertRaises(ValueError, converter.convert, invalid)
def test_regex(self):
schema = """\
[test]
test_option: 29*4
"""
- validator = ConfigConverter(schema)
+ converter = ConfigConverter(schema)
valid = Config()
valid.read_string("""\
[test]
@@ -80,18 +82,19 @@ class TestConverter(TestCase):
[test]
test_option: xyz
""")
- validator.convert(valid)
- self.assertRaises(ValueError, validator.convert, invalid)
+ out = converter.convert(valid)
+ self.assertEqual(out['test']['test_option'], '2999999994')
+ self.assertRaises(ValueError, converter.convert, invalid)
def test_none(self):
schema = """\
[test]
test_option:
"""
- validator = ConfigConverter(schema)
+ converter = ConfigConverter(schema)
cfg = Config()
cfg.read_string("""\
[test]
test_option: something
""")
- self.assertRaises(ValueError, validator.convert, cfg)
+ self.assertRaises(ValueError, converter.convert, cfg)
diff --git a/src/mailman_pgp/config/tests/test_validator.py b/src/mailman_pgp/config/tests/test_validator.py
index 51570c3..10beba6 100644
--- a/src/mailman_pgp/config/tests/test_validator.py
+++ b/src/mailman_pgp/config/tests/test_validator.py
@@ -18,31 +18,11 @@
""""""
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
diff --git a/src/mailman_pgp/plugin.py b/src/mailman_pgp/plugin.py
index 9824716..7ee31e2 100644
--- a/src/mailman_pgp/plugin.py
+++ b/src/mailman_pgp/plugin.py
@@ -36,6 +36,7 @@ class PGPMailman:
"""See `IPlugin`."""
config.load(self.name)
config.validate()
+ config.convert()
config.db = Database()
config.pgp = PGP()