Mercurial > piecrust2
changeset 1098:2323f0788170
config: Report error if a non-asset source has no URL route.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 17 Feb 2018 11:52:31 -0800 |
parents | 2b2eaee96121 |
children | 07c23be08029 |
files | piecrust/appconfig.py tests/test_sources_autoconfig.py |
diffstat | 2 files changed, 52 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/appconfig.py Sat Feb 17 11:51:45 2018 -0800 +++ b/piecrust/appconfig.py Sat Feb 17 11:52:31 2018 -0800 @@ -418,7 +418,8 @@ # Check routes are referencing correct sources, have default # values, etc. used_sources = set() - existing_sources = set(values['site']['sources'].keys()) + source_configs = values['site']['sources'] + existing_sources = set(source_configs.keys()) for rc in v: if not isinstance(rc, dict): raise ConfigurationError("All routes in 'site/routes' must be " @@ -444,6 +445,15 @@ rc.setdefault('pass', 1) rc.setdefault('page_suffix', '/%num%') + # Raise errors about non-asset sources that have no URL routes. + sources_with_no_route = list(filter( + lambda s: source_configs[s].get('pipeline') != 'asset', + existing_sources.difference(used_sources))) + if sources_with_no_route: + raise ConfigurationError( + "The following sources have no routes: %s" % + ', '.join(sources_with_no_route)) + return v
--- a/tests/test_sources_autoconfig.py Sat Feb 17 11:51:45 2018 -0800 +++ b/tests/test_sources_autoconfig.py Sat Feb 17 11:52:31 2018 -0800 @@ -77,7 +77,10 @@ 'test': {'type': 'autoconfig', 'setting_name': 'foo', 'only_single_values': True} - } + }, + 'routes': [ + {'url': '/blah', 'source': 'test'} + ] } fs = mock_fs().withConfig({'site': site_config}) fs.withPage('test/bar1/bar2/something.md') @@ -140,30 +143,43 @@ @pytest.mark.parametrize( 'fs_fac, route_path, expected_path, expected_metadata', [ - (lambda: mock_fs(), 'missing', None, None), - (lambda: mock_fs().withPage('test/something.md'), - 'something', 'something.md', - {'slug': 'something', - 'config': {'foo': 0, 'foo_trail': [0]}}), - (lambda: mock_fs().withPage('test/bar/something.md'), - 'bar/something', 'bar/something.md', - {'slug': 'bar/something', - 'config': {'foo': 0, 'foo_trail': [0]}}), - (lambda: mock_fs().withPage('test/42_something.md'), - 'something', '42_something.md', - {'slug': 'something', - 'config': {'foo': 42, 'foo_trail': [42]}}), - (lambda: mock_fs().withPage('test/bar/42_something.md'), - 'bar/something', 'bar/42_something.md', - {'slug': 'bar/something', - 'config': {'foo': 42, 'foo_trail': [42]}}), - - ((lambda: mock_fs() - .withPage('test/42_something.md') - .withPage('test/43_other_something.md')), - 'something', '42_something.md', - {'slug': 'something', - 'config': {'foo': 42, 'foo_trail': [42]}}), + ( + lambda: mock_fs(), + 'missing', + None, + None), + ( + lambda: mock_fs().withPage('test/something.html'), + 'something', + 'something.html', + {'route_params': {'slug': 'something'}, + 'config': {'foo': 0, 'foo_trail': [0]}}), + ( + lambda: mock_fs().withPage('test/bar/something.html'), + 'bar/something', + 'bar/something.html', + {'route_params': {'slug': 'bar/something'}, + 'config': {'foo': 0, 'foo_trail': [0]}}), + ( + lambda: mock_fs().withPage('test/42_something.html'), + 'something', + '42_something.html', + {'route_params': {'slug': 'something'}, + 'config': {'foo': 42, 'foo_trail': [42]}}), + ( + lambda: mock_fs().withPage('test/bar/42_something.html'), + 'bar/something', + 'bar/42_something.html', + {'route_params': {'slug': 'bar/something'}, + 'config': {'foo': 42, 'foo_trail': [42]}}), + ( + (lambda: mock_fs() + .withPage('test/42_something.html') + .withPage('test/43_other_something.html')), + 'something', + '42_something.html', + {'route_params': {'slug': 'something'}, + 'config': {'foo': 42, 'foo_trail': [42]}}), ]) def test_ordered_source_find(fs_fac, route_path, expected_path, expected_metadata):