Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
261:b51ddb0c260b | 262:61145dcd56e0 |
---|---|
1 import os.path | 1 import os.path |
2 import pytest | 2 import pytest |
3 from piecrust.baking.baker import PageBaker, Baker | 3 from piecrust.baking.baker import PageBaker, Baker |
4 from piecrust.baking.records import BakeRecord | 4 from piecrust.baking.records import BakeRecord |
5 from piecrust.routing import Route | |
5 from .mockutil import get_mock_app, mock_fs, mock_fs_scope | 6 from .mockutil import get_mock_app, mock_fs, mock_fs_scope |
6 | 7 |
7 | 8 |
8 @pytest.mark.parametrize('uri, page_num, pretty, expected', [ | 9 @pytest.mark.parametrize('uri, pretty, expected', [ |
9 # Pretty URLs | 10 # Pretty URLs |
10 ('', 1, True, 'index.html'), | 11 ('', True, 'index.html'), |
11 ('', 2, True, '2/index.html'), | 12 ('2', True, '2/index.html'), |
12 ('foo', 1, True, 'foo/index.html'), | 13 ('foo', True, 'foo/index.html'), |
13 ('foo', 2, True, 'foo/2/index.html'), | 14 ('foo/2', True, 'foo/2/index.html'), |
14 ('foo/bar', 1, True, 'foo/bar/index.html'), | 15 ('foo/bar', True, 'foo/bar/index.html'), |
15 ('foo/bar', 2, True, 'foo/bar/2/index.html'), | 16 ('foo/bar/2', True, 'foo/bar/2/index.html'), |
16 ('foo.ext', 1, True, 'foo.ext/index.html'), | 17 ('foo.ext', True, 'foo.ext/index.html'), |
17 ('foo.ext', 2, True, 'foo.ext/2/index.html'), | 18 ('foo.ext/2', True, 'foo.ext/2/index.html'), |
18 ('foo/bar.ext', 1, True, 'foo/bar.ext/index.html'), | 19 ('foo/bar.ext', True, 'foo/bar.ext/index.html'), |
19 ('foo/bar.ext', 2, True, 'foo/bar.ext/2/index.html'), | 20 ('foo/bar.ext/2', True, 'foo/bar.ext/2/index.html'), |
20 ('foo.bar.ext', 1, True, 'foo.bar.ext/index.html'), | 21 ('foo.bar.ext', True, 'foo.bar.ext/index.html'), |
21 ('foo.bar.ext', 2, True, 'foo.bar.ext/2/index.html'), | 22 ('foo.bar.ext/2', True, 'foo.bar.ext/2/index.html'), |
22 # Ugly URLs | 23 # Ugly URLs |
23 ('', 1, False, 'index.html'), | 24 ('', False, 'index.html'), |
24 ('', 2, False, '2.html'), | 25 ('2.html', False, '2.html'), |
25 ('foo', 1, False, 'foo.html'), | 26 ('foo.html', False, 'foo.html'), |
26 ('foo', 2, False, 'foo/2.html'), | 27 ('foo/2.html', False, 'foo/2.html'), |
27 ('foo/bar', 1, False, 'foo/bar.html'), | 28 ('foo/bar.html', False, 'foo/bar.html'), |
28 ('foo/bar', 2, False, 'foo/bar/2.html'), | 29 ('foo/bar/2.html', False, 'foo/bar/2.html'), |
29 ('foo.ext', 1, False, 'foo.ext'), | 30 ('foo.ext', False, 'foo.ext'), |
30 ('foo.ext', 2, False, 'foo/2.ext'), | 31 ('foo/2.ext', False, 'foo/2.ext'), |
31 ('foo/bar.ext', 1, False, 'foo/bar.ext'), | 32 ('foo/bar.ext', False, 'foo/bar.ext'), |
32 ('foo/bar.ext', 2, False, 'foo/bar/2.ext'), | 33 ('foo/bar/2.ext', False, 'foo/bar/2.ext'), |
33 ('foo.bar.ext', 1, False, 'foo.bar.ext'), | 34 ('foo.bar.ext', False, 'foo.bar.ext'), |
34 ('foo.bar.ext', 2, False, 'foo.bar/2.ext') | 35 ('foo.bar/2.ext', False, 'foo.bar/2.ext') |
35 ]) | 36 ]) |
36 def test_get_output_path(uri, page_num, pretty, expected): | 37 def test_get_output_path(uri, pretty, expected): |
37 app = get_mock_app() | 38 app = get_mock_app() |
38 if pretty: | 39 if pretty: |
39 app.config.set('site/pretty_urls', True) | 40 app.config.set('site/pretty_urls', True) |
40 assert app.config.get('site/pretty_urls') == pretty | 41 assert app.config.get('site/pretty_urls') == pretty |
41 | 42 |
42 baker = PageBaker(app, '/destination') | 43 baker = PageBaker(app, '/destination') |
43 sub_uri = baker.getOutputUri(uri, page_num) | 44 path = baker.getOutputPath(uri) |
44 path = baker.getOutputPath(sub_uri) | |
45 expected = os.path.normpath( | 45 expected = os.path.normpath( |
46 os.path.join('/destination', expected)) | 46 os.path.join('/destination', expected)) |
47 assert expected == path | 47 assert expected == path |
48 | 48 |
49 | 49 |