Mercurial > piecrust2
annotate tests/test_routing.py @ 415:0e9a94b7fdfa
bake: Improve bake record information.
* Store things in the bake record that require less interaction between the
master process and the workers. For instance, don't store the paginator
object in the render pass info -- instead, just store whether pagination
was used, and whether it had more items.
* Simplify information passing between workers and bake passes by saving the
rendering info to the JSON cache. This means the "render first sub" job
doesn't have to return anything except errors now.
* Add more performance counter info.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 20 Jun 2015 19:23:16 -0700 |
parents | f33712c4cfab |
children | 6b6c5442c790 |
rev | line source |
---|---|
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import pytest |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from piecrust.routing import Route |
262
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
3 from .mockutil import get_mock_app |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 @pytest.mark.parametrize( |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 'config, metadata, expected', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 [ |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 ({'url': '/%foo%'}, |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 {'foo': 'bar'}, True), |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 ({'url': '/%foo%'}, |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 {'zoo': 'zar', 'foo': 'bar'}, True), |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 ({'url': '/%foo%'}, |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 {'zoo': 'zar'}, False), |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 ({'url': '/%foo%/%zoo%'}, |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 {'zoo': 'zar'}, False) |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 ]) |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 def test_matches_metadata(config, metadata, expected): |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
19 app = get_mock_app() |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
20 app.config.set('site/root', '/') |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 config.setdefault('source', 'blah') |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 route = Route(app, config) |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 m = route.matchesMetadata(metadata) |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 assert m == expected |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 @pytest.mark.parametrize( |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
28 'site_root, route_pattern, expected_required_metadata', |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 [ |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
30 ('/', '/%foo%', set(['foo'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
31 ('/', '/%path:foo%', set(['foo'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
32 ('/', '/%foo%/%bar%', set(['foo', 'bar'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
33 ('/', '/%foo%/%path:bar%', set(['foo', 'bar'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
34 ('/something', '/%foo%', set(['foo'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
35 ('/something', '/%path:foo%', set(['foo'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
36 ('/something', '/%foo%/%bar%', set(['foo', 'bar'])), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
37 ('/something', '/%foo%/%path:bar%', set(['foo', 'bar'])) |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
38 ]) |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
39 def test_required_metadata(site_root, route_pattern, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
40 expected_required_metadata): |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
41 app = get_mock_app() |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
42 app.config.set('site/root', site_root.rstrip('/') + '/') |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
43 config = {'url': route_pattern, 'source': 'blah'} |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
44 route = Route(app, config) |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
45 assert route.required_route_metadata == expected_required_metadata |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
46 |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
47 |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
48 @pytest.mark.parametrize( |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
49 'site_root, config, uri, expected_match', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
50 [ |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
51 ('/', {'url': '/%foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
52 'something', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 {'foo': 'something'}), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
54 ('/', {'url': '/%foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 'something/other', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 None), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
57 ('/', {'url': '/%path:foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 'something/other', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 {'foo': 'something/other'}), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
60 ('/', {'url': '/%path:foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
61 '', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
62 {'foo': ''}), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
63 ('/', {'url': '/prefix/%path:foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
64 'prefix/something/other', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
65 {'foo': 'something/other'}), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
66 ('/', {'url': '/prefix/%path:foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
67 'prefix/', |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
68 {'foo': ''}), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
69 ('/', {'url': '/prefix/%path:foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
70 'prefix', |
380
f33712c4cfab
routing: Fix bugs with matching URLs with correct route but missing metadata.
Ludovic Chabant <ludovic@chabant.com>
parents:
369
diff
changeset
|
71 {'foo': ''}), |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
72 |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
73 ('/blah', {'url': '/%foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
74 'something', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
75 {'foo': 'something'}), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
76 ('/blah', {'url': '/%foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
77 'something/other', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
78 None), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
79 ('/blah', {'url': '/%path:foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
80 'something/other', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
81 {'foo': 'something/other'}), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
82 ('/blah', {'url': '/%path:foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
83 '', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
84 {'foo': ''}), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
85 ('/blah', {'url': '/prefix/%path:foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
86 'prefix/something/other', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
87 {'foo': 'something/other'}), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
88 ('/blah', {'url': '/prefix/%path:foo%'}, |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
89 'prefix/', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
90 {'foo': ''}), |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
91 ('/blah', {'url': '/prefix/%path:foo%'}, |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 'prefix', |
380
f33712c4cfab
routing: Fix bugs with matching URLs with correct route but missing metadata.
Ludovic Chabant <ludovic@chabant.com>
parents:
369
diff
changeset
|
93 {'foo': ''}), |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 ]) |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
95 def test_match_uri(site_root, config, uri, expected_match): |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
96 site_root = site_root.rstrip('/') + '/' |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
97 app = get_mock_app() |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
98 app.config.set('site/root', site_root) |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
99 config.setdefault('source', 'blah') |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
100 route = Route(app, config) |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
101 assert route.uri_pattern == config['url'].lstrip('/') |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
102 m = route.matchUri(site_root + uri) |
177
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
103 assert m == expected_match |
4b0c87e7df73
tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
104 |
262
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
105 |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
106 @pytest.mark.parametrize( |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
107 'site_root', |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
108 [ |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
109 ('/'), ('/whatever') |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
110 ]) |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
111 def test_match_uri_requires_absolute_uri(site_root): |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
112 with pytest.raises(Exception): |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
113 app = get_mock_app() |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
114 app.config.set('site/root', site_root.rstrip('/') + '/') |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
115 config = {'url': '/%path:slug%', 'source': 'blah'} |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
116 route = Route(app, config) |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
117 route.matchUri('notabsuri') |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
118 |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
119 |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
120 @pytest.mark.parametrize( |
262
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
121 'slug, page_num, pretty, expected', |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
122 [ |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
123 # Pretty URLs |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
124 ('', 1, True, ''), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
125 ('', 2, True, '2'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
126 ('foo', 1, True, 'foo'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
127 ('foo', 2, True, 'foo/2'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
128 ('foo/bar', 1, True, 'foo/bar'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
129 ('foo/bar', 2, True, 'foo/bar/2'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
130 ('foo.ext', 1, True, 'foo.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
131 ('foo.ext', 2, True, 'foo.ext/2'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
132 ('foo/bar.ext', 1, True, 'foo/bar.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
133 ('foo/bar.ext', 2, True, 'foo/bar.ext/2'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
134 ('foo.bar.ext', 1, True, 'foo.bar.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
135 ('foo.bar.ext', 2, True, 'foo.bar.ext/2'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
136 # Ugly URLs |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
137 ('', 1, False, ''), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
138 ('', 2, False, '2.html'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
139 ('foo', 1, False, 'foo.html'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
140 ('foo', 2, False, 'foo/2.html'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
141 ('foo/bar', 1, False, 'foo/bar.html'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
142 ('foo/bar', 2, False, 'foo/bar/2.html'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
143 ('foo.ext', 1, False, 'foo.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
144 ('foo.ext', 2, False, 'foo/2.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
145 ('foo/bar.ext', 1, False, 'foo/bar.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
146 ('foo/bar.ext', 2, False, 'foo/bar/2.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
147 ('foo.bar.ext', 1, False, 'foo.bar.ext'), |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
148 ('foo.bar.ext', 2, False, 'foo.bar/2.ext') |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
149 ]) |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
150 def test_get_uri(slug, page_num, pretty, expected): |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
151 app = get_mock_app() |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
262
diff
changeset
|
152 app.config.set('site/root', '/blah/') |
262
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
153 app.config.set('site/pretty_urls', pretty) |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
154 app.config.set('site/trailing_slash', False) |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
155 app.config.set('__cache/pagination_suffix_format', '/%(num)d') |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
156 |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
157 config = {'url': '/%path:slug%', 'source': 'blah'} |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
158 route = Route(app, config) |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
159 uri = route.getUri({'slug': slug}, sub_num=page_num) |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
160 assert uri == ('/blah/' + expected) |
61145dcd56e0
routing: Better generate URLs according to the site configuration.
Ludovic Chabant <ludovic@chabant.com>
parents:
177
diff
changeset
|
161 |