comparison 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
comparison
equal deleted inserted replaced
583:1eda551ee681 584:9ccc933ac2c7
1 from piecrust.appconfig import PieCrustConfiguration
2
3
4 def test_config_default():
5 values = {}
6 config = PieCrustConfiguration(values=values)
7 assert config.get('site/root') == '/'
8 assert len(config.get('site/sources')) == 3 # pages, posts, theme_pages
9
10
11 def test_config_default2():
12 config = PieCrustConfiguration()
13 assert config.get('site/root') == '/'
14 assert len(config.get('site/sources')) == 3 # pages, posts, theme_pages
15
16
17 def test_config_site_override_title():
18 values = {'site': {'title': "Whatever"}}
19 config = PieCrustConfiguration(values=values)
20 assert config.get('site/root') == '/'
21 assert config.get('site/title') == 'Whatever'
22
23
24 def test_config_site_add_source():
25 values = {'site': {
26 'sources': {'notes': {}},
27 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}]
28 }}
29 config = PieCrustConfiguration(values=values)
30 # The order of routes is important. Sources, not so much.
31 assert list(map(lambda v: v['source'], config.get('site/routes'))) == [
32 'notes', 'pages', 'posts', 'posts', 'posts', 'theme_pages']
33 assert list(config.get('site/sources').keys()) == [
34 'posts', 'pages', 'notes', 'theme_pages']
35