comparison tests/test_appconfig.py @ 681:894d286b348f

internal: Refactor config loading some more. * Remove fixup code in the app to make the app config class more standalone. * Remove support for old-style variants... maybe bring it back later. * Try and fix various bugs introduced by subtle config value overriding order changes.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 08 Mar 2016 01:07:34 -0800
parents 3df808b133f8
children ec384174b8b2
comparison
equal deleted inserted replaced
680:c2ea75e37540 681:894d286b348f
1 from piecrust.appconfig import PieCrustConfiguration 1 from piecrust.appconfig import PieCrustConfiguration
2 from .mockutil import mock_fs, mock_fs_scope
2 3
3 4
4 def test_config_default(): 5 def test_config_default():
5 values = {} 6 values = {}
6 config = PieCrustConfiguration(values=values) 7 config = PieCrustConfiguration(values=values)
26 'sources': {'notes': {}}, 27 'sources': {'notes': {}},
27 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] 28 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}]
28 }} 29 }}
29 config = PieCrustConfiguration(values=values) 30 config = PieCrustConfiguration(values=values)
30 # The order of routes is important. Sources, not so much. 31 # The order of routes is important. Sources, not so much.
32 # `posts` shows up 3 times in routes (posts, tags, categories)
31 assert list(map(lambda v: v['source'], config.get('site/routes'))) == [ 33 assert list(map(lambda v: v['source'], config.get('site/routes'))) == [
32 'notes', 'posts', 'posts', 'posts', 'pages'] 34 'notes', 'posts', 'posts', 'posts', 'pages']
33 assert list(config.get('site/sources').keys()) == [ 35 assert sorted(config.get('site/sources').keys()) == sorted([
34 'pages', 'posts', 'notes'] 36 'pages', 'posts', 'notes'])
35 37
38
39 def test_config_site_add_source_with_theme():
40 config = {'site': {
41 'sources': {'notes': {}},
42 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}]
43 }}
44 fs = mock_fs().withConfig(config)
45 with mock_fs_scope(fs):
46 app = fs.getApp()
47 # The order of routes is important. Sources, not so much.
48 # `posts` shows up 3 times in routes (posts, tags, categories)
49 assert (list(
50 map(
51 lambda v: v['source'],
52 app.config.get('site/routes'))) ==
53 ['notes', 'posts', 'posts', 'posts', 'pages', 'theme_pages'])
54 assert sorted(app.config.get('site/sources').keys()) == sorted([
55 'pages', 'posts', 'notes', 'theme_pages'])
56