diff tests/test_appconfig.py @ 584:9ccc933ac2c7

internal: Refactor the app configuration class. * Moved to its own module. * More extensible validation. * Allow easier setup of defaults so `showconfig` shows more useful stuff.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 01 Jan 2016 23:18:26 -0800
parents
children 25df894f9ab9
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_appconfig.py	Fri Jan 01 23:18:26 2016 -0800
@@ -0,0 +1,35 @@
+from piecrust.appconfig import PieCrustConfiguration
+
+
+def test_config_default():
+    values = {}
+    config = PieCrustConfiguration(values=values)
+    assert config.get('site/root') == '/'
+    assert len(config.get('site/sources')) == 3  # pages, posts, theme_pages
+
+
+def test_config_default2():
+    config = PieCrustConfiguration()
+    assert config.get('site/root') == '/'
+    assert len(config.get('site/sources')) == 3  # pages, posts, theme_pages
+
+
+def test_config_site_override_title():
+    values = {'site': {'title': "Whatever"}}
+    config = PieCrustConfiguration(values=values)
+    assert config.get('site/root') == '/'
+    assert config.get('site/title') == 'Whatever'
+
+
+def test_config_site_add_source():
+    values = {'site': {
+        'sources': {'notes': {}},
+        'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}]
+        }}
+    config = PieCrustConfiguration(values=values)
+    # The order of routes is important. Sources, not so much.
+    assert list(map(lambda v: v['source'], config.get('site/routes'))) == [
+            'notes', 'pages', 'posts', 'posts', 'posts', 'theme_pages']
+    assert list(config.get('site/sources').keys()) == [
+            'posts', 'pages', 'notes', 'theme_pages']
+