Mercurial > piecrust2
diff tests/test_baking_baker.py @ 262:61145dcd56e0
routing: Better generate URLs according to the site configuration.
This fixes problems now that even the chef server generates URLs that are
appropriate given the `pretty_urls` and `trailing_slash` settings.
Add some tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 24 Feb 2015 08:06:25 -0800 |
parents | dce37d1d4f05 |
children | a2d283d1033d |
line wrap: on
line diff
--- a/tests/test_baking_baker.py Tue Feb 24 08:04:49 2015 -0800 +++ b/tests/test_baking_baker.py Tue Feb 24 08:06:25 2015 -0800 @@ -2,46 +2,46 @@ import pytest from piecrust.baking.baker import PageBaker, Baker from piecrust.baking.records import BakeRecord +from piecrust.routing import Route from .mockutil import get_mock_app, mock_fs, mock_fs_scope -@pytest.mark.parametrize('uri, page_num, pretty, expected', [ +@pytest.mark.parametrize('uri, pretty, expected', [ # Pretty URLs - ('', 1, True, 'index.html'), - ('', 2, True, '2/index.html'), - ('foo', 1, True, 'foo/index.html'), - ('foo', 2, True, 'foo/2/index.html'), - ('foo/bar', 1, True, 'foo/bar/index.html'), - ('foo/bar', 2, True, 'foo/bar/2/index.html'), - ('foo.ext', 1, True, 'foo.ext/index.html'), - ('foo.ext', 2, True, 'foo.ext/2/index.html'), - ('foo/bar.ext', 1, True, 'foo/bar.ext/index.html'), - ('foo/bar.ext', 2, True, 'foo/bar.ext/2/index.html'), - ('foo.bar.ext', 1, True, 'foo.bar.ext/index.html'), - ('foo.bar.ext', 2, True, 'foo.bar.ext/2/index.html'), + ('', True, 'index.html'), + ('2', True, '2/index.html'), + ('foo', True, 'foo/index.html'), + ('foo/2', True, 'foo/2/index.html'), + ('foo/bar', True, 'foo/bar/index.html'), + ('foo/bar/2', True, 'foo/bar/2/index.html'), + ('foo.ext', True, 'foo.ext/index.html'), + ('foo.ext/2', True, 'foo.ext/2/index.html'), + ('foo/bar.ext', True, 'foo/bar.ext/index.html'), + ('foo/bar.ext/2', True, 'foo/bar.ext/2/index.html'), + ('foo.bar.ext', True, 'foo.bar.ext/index.html'), + ('foo.bar.ext/2', True, 'foo.bar.ext/2/index.html'), # Ugly URLs - ('', 1, False, 'index.html'), - ('', 2, False, '2.html'), - ('foo', 1, False, 'foo.html'), - ('foo', 2, False, 'foo/2.html'), - ('foo/bar', 1, False, 'foo/bar.html'), - ('foo/bar', 2, False, 'foo/bar/2.html'), - ('foo.ext', 1, False, 'foo.ext'), - ('foo.ext', 2, False, 'foo/2.ext'), - ('foo/bar.ext', 1, False, 'foo/bar.ext'), - ('foo/bar.ext', 2, False, 'foo/bar/2.ext'), - ('foo.bar.ext', 1, False, 'foo.bar.ext'), - ('foo.bar.ext', 2, False, 'foo.bar/2.ext') + ('', False, 'index.html'), + ('2.html', False, '2.html'), + ('foo.html', False, 'foo.html'), + ('foo/2.html', False, 'foo/2.html'), + ('foo/bar.html', False, 'foo/bar.html'), + ('foo/bar/2.html', False, 'foo/bar/2.html'), + ('foo.ext', False, 'foo.ext'), + ('foo/2.ext', False, 'foo/2.ext'), + ('foo/bar.ext', False, 'foo/bar.ext'), + ('foo/bar/2.ext', False, 'foo/bar/2.ext'), + ('foo.bar.ext', False, 'foo.bar.ext'), + ('foo.bar/2.ext', False, 'foo.bar/2.ext') ]) -def test_get_output_path(uri, page_num, pretty, expected): +def test_get_output_path(uri, pretty, expected): app = get_mock_app() if pretty: app.config.set('site/pretty_urls', True) assert app.config.get('site/pretty_urls') == pretty baker = PageBaker(app, '/destination') - sub_uri = baker.getOutputUri(uri, page_num) - path = baker.getOutputPath(sub_uri) + path = baker.getOutputPath(uri) expected = os.path.normpath( os.path.join('/destination', expected)) assert expected == path