Mercurial > piecrust2
comparison tests/test_appconfig.py @ 683:ec384174b8b2
internal: More work/fixes on how default/theme/user configs are merged.
Change how the code is organized to have better data flow. Add some tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 09 Mar 2016 00:23:51 -0800 |
parents | 894d286b348f |
children | 15b5181b2e42 |
comparison
equal
deleted
inserted
replaced
682:99112a431de9 | 683:ec384174b8b2 |
---|---|
1 import yaml | |
1 from piecrust.appconfig import PieCrustConfiguration | 2 from piecrust.appconfig import PieCrustConfiguration |
2 from .mockutil import mock_fs, mock_fs_scope | 3 from .mockutil import mock_fs, mock_fs_scope |
3 | 4 |
4 | 5 |
5 def test_config_default(): | 6 def test_config_default(): |
6 values = {} | 7 values = {} |
7 config = PieCrustConfiguration(values=values) | 8 config = PieCrustConfiguration(values=values) |
8 assert config.get('site/root') == '/' | 9 assert config.get('site/root') == '/' |
9 assert len(config.get('site/sources')) == 2 # pages, posts | 10 assert len(config.get('site/sources')) == 3 # pages, posts, theme_pages |
10 | 11 |
11 | 12 |
12 def test_config_default2(): | 13 def test_config_default2(): |
13 config = PieCrustConfiguration() | 14 config = PieCrustConfiguration() |
14 assert config.get('site/root') == '/' | 15 assert config.get('site/root') == '/' |
15 assert len(config.get('site/sources')) == 2 # pages, posts | 16 assert len(config.get('site/sources')) == 3 # pages, posts, theme_pages |
16 | 17 |
17 | 18 |
18 def test_config_site_override_title(): | 19 def test_config_site_override_title(): |
19 values = {'site': {'title': "Whatever"}} | 20 values = {'site': {'title': "Whatever"}} |
20 config = PieCrustConfiguration(values=values) | 21 config = PieCrustConfiguration(values=values) |
21 assert config.get('site/root') == '/' | 22 assert config.get('site/root') == '/' |
22 assert config.get('site/title') == 'Whatever' | 23 assert config.get('site/title') == 'Whatever' |
23 | 24 |
24 | 25 |
25 def test_config_site_add_source(): | 26 def test_config_site_add_source(): |
26 values = {'site': { | |
27 'sources': {'notes': {}}, | |
28 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] | |
29 }} | |
30 config = PieCrustConfiguration(values=values) | |
31 # The order of routes is important. Sources, not so much. | |
32 # `posts` shows up 3 times in routes (posts, tags, categories) | |
33 assert list(map(lambda v: v['source'], config.get('site/routes'))) == [ | |
34 'notes', 'posts', 'posts', 'posts', 'pages'] | |
35 assert sorted(config.get('site/sources').keys()) == sorted([ | |
36 'pages', 'posts', 'notes']) | |
37 | |
38 | |
39 def test_config_site_add_source_with_theme(): | |
40 config = {'site': { | 27 config = {'site': { |
41 'sources': {'notes': {}}, | 28 'sources': {'notes': {}}, |
42 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] | 29 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] |
43 }} | 30 }} |
44 fs = mock_fs().withConfig(config) | 31 fs = mock_fs().withConfig(config) |
49 assert (list( | 36 assert (list( |
50 map( | 37 map( |
51 lambda v: v['source'], | 38 lambda v: v['source'], |
52 app.config.get('site/routes'))) == | 39 app.config.get('site/routes'))) == |
53 ['notes', 'posts', 'posts', 'posts', 'pages', 'theme_pages']) | 40 ['notes', 'posts', 'posts', 'posts', 'pages', 'theme_pages']) |
54 assert sorted(app.config.get('site/sources').keys()) == sorted([ | 41 assert list(app.config.get('site/sources').keys()) == [ |
55 'pages', 'posts', 'notes', 'theme_pages']) | 42 'theme_pages', 'pages', 'posts', 'notes'] |
56 | 43 |
44 | |
45 def test_config_site_add_source_in_both_site_and_theme(): | |
46 theme_config = {'site': { | |
47 'sources': {'theme_notes': {}}, | |
48 'routes': [{'url': '/theme_notes/%path:slug%', 'source': 'theme_notes'}] | |
49 }} | |
50 config = {'site': { | |
51 'sources': {'notes': {}}, | |
52 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] | |
53 }} | |
54 fs = (mock_fs() | |
55 .withConfig(config) | |
56 .withFile('kitchen/theme/theme_config.yml', yaml.dump(theme_config))) | |
57 with mock_fs_scope(fs): | |
58 app = fs.getApp() | |
59 # The order of routes is important. Sources, not so much. | |
60 # `posts` shows up 3 times in routes (posts, tags, categories) | |
61 assert (list( | |
62 map( | |
63 lambda v: v['source'], | |
64 app.config.get('site/routes'))) == | |
65 ['notes', 'posts', 'posts', 'posts', 'pages', 'theme_notes', 'theme_pages']) | |
66 assert list(app.config.get('site/sources').keys()) == [ | |
67 'theme_pages', 'theme_notes', 'pages', 'posts', 'notes'] | |
68 |