Mercurial > piecrust2
diff tests/test_appconfig.py @ 805:fd694f1297c7
config: Cleanup config loading code. Add support for a `local.yml` config.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 10 Oct 2016 21:41:59 -0700 |
parents | ab5c6a8ae90a |
children | 72f17534d58e |
line wrap: on
line diff
--- a/tests/test_appconfig.py Wed Oct 12 21:01:42 2016 -0700 +++ b/tests/test_appconfig.py Mon Oct 10 21:41:59 2016 -0700 @@ -10,12 +10,6 @@ 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) @@ -33,18 +27,20 @@ app = fs.getApp() assert app.config.get('site/default_page_layout') == 'foo' assert app.config.get('site/default_post_layout') == 'bar' - assert app.config.get('site/sources')['pages']['default_layout'] == 'foo' - assert app.config.get('site/sources')['pages']['items_per_page'] == 5 - assert app.config.get('site/sources')['theme_pages']['default_layout'] == 'default' - assert app.config.get('site/sources')['theme_pages']['items_per_page'] == 5 - assert app.config.get('site/sources')['posts']['default_layout'] == 'bar' - assert app.config.get('site/sources')['posts']['items_per_page'] == 2 + assert app.config.get('site/sources/pages/default_layout') == 'foo' + assert app.config.get('site/sources/pages/items_per_page') == 5 + assert app.config.get( + 'site/sources/theme_pages/default_layout') == 'default' + assert app.config.get('site/sources/theme_pages/items_per_page') == 5 + assert app.config.get('site/sources/posts/default_layout') == 'bar' + assert app.config.get('site/sources/posts/items_per_page') == 2 + def test_config_site_add_source(): config = {'site': { 'sources': {'notes': {}}, 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] - }} + }} fs = mock_fs().withConfig(config) with mock_fs_scope(fs): app = fs.getApp() @@ -53,23 +49,25 @@ map( lambda v: v.get('generator') or v['source'], app.config.get('site/routes'))) == - ['notes', 'posts', 'posts_archives', 'posts_tags', 'posts_categories', 'pages', 'theme_pages']) - assert list(app.config.get('site/sources').keys()) == [ - 'theme_pages', 'pages', 'posts', 'notes'] + [ + 'notes', 'posts', 'posts_archives', 'posts_tags', + 'posts_categories', 'pages', 'theme_pages']) + assert set(app.config.get('site/sources').keys()) == set([ + '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))) + .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. @@ -78,7 +76,43 @@ map( lambda v: v.get('generator') or v['source'], app.config.get('site/routes'))) == - ['notes', 'posts', 'posts_archives', 'posts_tags', 'posts_categories', 'pages', 'theme_notes', 'theme_pages']) - assert list(app.config.get('site/sources').keys()) == [ - 'theme_pages', 'theme_notes', 'pages', 'posts', 'notes'] + [ + 'notes', 'posts', 'posts_archives', 'posts_tags', + 'posts_categories', 'pages', 'theme_notes', + 'theme_pages']) + assert set(app.config.get('site/sources').keys()) == set([ + 'theme_pages', 'theme_notes', 'pages', 'posts', 'notes']) + +def test_multiple_blogs(): + config = {'site': {'blogs': ['aaa', 'bbb']}} + fs = mock_fs().withConfig(config) + with mock_fs_scope(fs): + app = fs.getApp() + assert app.config.get('site/blogs') == ['aaa', 'bbb'] + assert (list( + map( + lambda v: v.get('generator') or v['source'], + app.config.get('site/routes'))) == + [ + 'aaa', 'aaa_archives', 'aaa_tags', 'aaa_categories', + 'bbb', 'bbb_archives', 'bbb_tags', 'bbb_categories', + 'pages', 'theme_pages']) + assert set(app.config.get('site/sources').keys()) == set([ + 'aaa', 'bbb', 'pages', 'theme_pages']) + + +def test_custom_list_setting(): + config = {'blah': ['foo', 'bar']} + fs = mock_fs().withConfig(config) + with mock_fs_scope(fs): + app = fs.getApp() + assert app.config.get('blah') == ['foo', 'bar'] + + +def test_custom_list_setting_in_site_section(): + config = {'site': {'blah': ['foo', 'bar']}} + fs = mock_fs().withConfig(config) + with mock_fs_scope(fs): + app = fs.getApp() + assert app.config.get('site/blah') == ['foo', 'bar']