Mercurial > piecrust2
diff 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 |
line wrap: on
line diff
--- a/tests/test_appconfig.py Tue Mar 08 01:07:56 2016 -0800 +++ b/tests/test_appconfig.py Wed Mar 09 00:23:51 2016 -0800 @@ -1,3 +1,4 @@ +import yaml from piecrust.appconfig import PieCrustConfiguration from .mockutil import mock_fs, mock_fs_scope @@ -6,13 +7,13 @@ values = {} config = PieCrustConfiguration(values=values) assert config.get('site/root') == '/' - assert len(config.get('site/sources')) == 2 # pages, posts + 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')) == 2 # pages, posts + assert len(config.get('site/sources')) == 3 # pages, posts, theme_pages def test_config_site_override_title(): @@ -23,20 +24,6 @@ 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. - # `posts` shows up 3 times in routes (posts, tags, categories) - assert list(map(lambda v: v['source'], config.get('site/routes'))) == [ - 'notes', 'posts', 'posts', 'posts', 'pages'] - assert sorted(config.get('site/sources').keys()) == sorted([ - 'pages', 'posts', 'notes']) - - -def test_config_site_add_source_with_theme(): config = {'site': { 'sources': {'notes': {}}, 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] @@ -51,6 +38,31 @@ lambda v: v['source'], app.config.get('site/routes'))) == ['notes', 'posts', 'posts', 'posts', 'pages', 'theme_pages']) - assert sorted(app.config.get('site/sources').keys()) == sorted([ - 'pages', 'posts', 'notes', 'theme_pages']) + assert list(app.config.get('site/sources').keys()) == [ + 'theme_pages', 'pages', 'posts', 'notes'] + +def test_config_site_add_source_in_both_site_and_theme(): + theme_config = {'site': { + 'sources': {'theme_notes': {}}, + 'routes': [{'url': '/theme_notes/%path:slug%', 'source': 'theme_notes'}] + }} + config = {'site': { + 'sources': {'notes': {}}, + 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] + }} + fs = (mock_fs() + .withConfig(config) + .withFile('kitchen/theme/theme_config.yml', yaml.dump(theme_config))) + with mock_fs_scope(fs): + app = fs.getApp() + # The order of routes is important. Sources, not so much. + # `posts` shows up 3 times in routes (posts, tags, categories) + assert (list( + map( + lambda v: v['source'], + app.config.get('site/routes'))) == + ['notes', 'posts', 'posts', 'posts', 'pages', 'theme_notes', 'theme_pages']) + assert list(app.config.get('site/sources').keys()) == [ + 'theme_pages', 'theme_notes', 'pages', 'posts', 'notes'] +