Commits

Eric Larson committed 5bfc942

Introduce alamode configuration helpers

Comments (0)

Files changed (2)

alamode/config/__init__.py

+"""Configuration Helpers for CherryPy
+
+CherryPy is extremely configurable, yet it doesn't provide many tools
+to make that configuration safely and easily. This hopefully improves
+that.
+"""
+from UserDict import UserDict
+
+
+class DictConfig(UserDict):
+    """
+    A config that produces a dictionary.
+    """
+    def __call__(self):
+        return self.data
+
+
+class ServerConfig(DictConfig):
+
+    def __init__(self, **kw):
+        pass

tests/unit/test_config.py

+from alamode.config import ServerConfig
+
+
+class TestServerConfig(object):
+
+    def test_server_host_and_port_attributes(self):
+        conf = ServerConfig(host='localhost', port=8080)
+
+        assert conf.host == 'localhost'
+        assert conf.port == 8080
+        assert conf() == {'server.socket_host': 'localhost',
+                          'server.socket_port': 8080}