summaryrefslogtreecommitdiff
path: root/src/mailman/config/tests/test_configuration.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/config/tests/test_configuration.py')
-rw-r--r--src/mailman/config/tests/test_configuration.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/mailman/config/tests/test_configuration.py b/src/mailman/config/tests/test_configuration.py
index 88e00cbb9..08f27c094 100644
--- a/src/mailman/config/tests/test_configuration.py
+++ b/src/mailman/config/tests/test_configuration.py
@@ -22,12 +22,17 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'TestConfiguration',
+ 'TestExternal',
]
import unittest
-from mailman.interfaces.configuration import ConfigurationUpdatedEvent
+from pkg_resources import resource_filename
+
+from mailman.config.config import external_configuration, load_external
+from mailman.interfaces.configuration import (
+ ConfigurationUpdatedEvent, MissingConfigurationFileError)
from mailman.testing.helpers import configuration, event_subscribers
from mailman.testing.layers import ConfigLayer
@@ -51,3 +56,46 @@ class TestConfiguration(unittest.TestCase):
# for the push leaving 'my test' on the top of the stack, and one for
# the pop, leaving the ConfigLayer's 'test config' on top.
self.assertEqual(events, ['my test', 'test config'])
+
+
+
+class TestExternal(unittest.TestCase):
+ """Test external configuration file loading APIs."""
+
+ def test_load_external_by_filename_as_bytes(self):
+ filename = resource_filename('mailman.config', 'postfix.cfg')
+ contents = load_external(filename)
+ self.assertIsInstance(contents, bytes)
+ self.assertEqual(contents[:9], b'[postfix]')
+
+ def test_load_external_by_path_as_bytes(self):
+ contents = load_external('python:mailman.config.postfix')
+ self.assertIsInstance(contents, bytes)
+ self.assertEqual(contents[:9], b'[postfix]')
+
+ def test_load_external_by_filename_as_string(self):
+ filename = resource_filename('mailman.config', 'postfix.cfg')
+ contents = load_external(filename, encoding='utf-8')
+ self.assertIsInstance(contents, unicode)
+ self.assertEqual(contents[:9], '[postfix]')
+
+ def test_load_external_by_path_as_string(self):
+ contents = load_external('python:mailman.config.postfix', 'utf-8')
+ self.assertIsInstance(contents, unicode)
+ self.assertEqual(contents[:9], '[postfix]')
+
+ def test_external_configuration_by_filename(self):
+ filename = resource_filename('mailman.config', 'postfix.cfg')
+ parser = external_configuration(filename)
+ self.assertEqual(parser.get('postfix', 'postmap_command'),
+ '/usr/sbin/postmap')
+
+ def test_external_configuration_by_path(self):
+ parser = external_configuration('python:mailman.config.postfix')
+ self.assertEqual(parser.get('postfix', 'postmap_command'),
+ '/usr/sbin/postmap')
+
+ def test_missing_configuration_file(self):
+ with self.assertRaises(MissingConfigurationFileError) as cm:
+ external_configuration('path:mailman.config.missing')
+ self.assertEqual(cm.exception.path, 'path:mailman.config.missing')