Mercurial > piecrust2
annotate tests/test_uriutil.py @ 1051:971b4d67e82a
serve: Fix problems with assets disappearing between servings.
When an asset file changes, its source's pipeline is re-run. But that created
a bake record that only had that pipeline's output, so the other outputs were
incorrectly considered empty and therefore any stray files were removed. Now we
copy over bake records for the pipelines we don't run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 26 Jan 2018 18:05:02 -0800 |
parents | e85f29b28b84 |
children |
rev | line source |
---|---|
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
1 import mock |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import pytest |
710
e85f29b28b84
internal: Remove unused piece of code.
Ludovic Chabant <ludovic@chabant.com>
parents:
495
diff
changeset
|
3 from piecrust.uriutil import split_sub_uri |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
5 |
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
6 @pytest.mark.parametrize('uri, expected, pretty_urls', [ |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
7 ('/', ('/', 1), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
8 ('/2', ('/', 2), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
9 ('/foo/bar', ('/foo/bar', 1), True), |
495
4284c673bb91
internal: Fix some edge-cases for splitting sub-URIs.
Ludovic Chabant <ludovic@chabant.com>
parents:
484
diff
changeset
|
10 ('/foo/bar/', ('/foo/bar', 1), True), |
4284c673bb91
internal: Fix some edge-cases for splitting sub-URIs.
Ludovic Chabant <ludovic@chabant.com>
parents:
484
diff
changeset
|
11 ('/foo/bar/2/', ('/foo/bar', 2), True), |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
12 ('/foo/bar.ext', ('/foo/bar.ext', 1), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
13 ('/foo/bar.ext/2', ('/foo/bar.ext', 2), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
14 ('/', ('/', 1), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
15 ('/2.html', ('/', 2), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
16 ('/foo/bar.html', ('/foo/bar.html', 1), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
17 ('/foo/bar/2.html', ('/foo/bar.html', 2), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
18 ('/foo/bar.ext', ('/foo/bar.ext', 1), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
19 ('/foo/bar/2.ext', ('/foo/bar.ext', 2), False) |
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
20 ]) |
316
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
21 def test_split_sub_uri(uri, expected, pretty_urls): |
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
22 app = mock.MagicMock() |
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
23 app.config = { |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
24 'site/root': '/', |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
25 'site/pretty_urls': pretty_urls, |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
26 '__cache/pagination_suffix_re': '/(?P<num>\\d+)$'} |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
27 actual = split_sub_uri(app, uri) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
28 assert actual == (expected[0], expected[1]) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
29 |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
30 |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
31 @pytest.mark.parametrize('uri, expected, pretty_urls', [ |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
32 ('/', ('/', 1), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
33 ('/2/', ('/', 2), True), |
495
4284c673bb91
internal: Fix some edge-cases for splitting sub-URIs.
Ludovic Chabant <ludovic@chabant.com>
parents:
484
diff
changeset
|
34 ('/foo/bar', ('/foo/bar/', 1), True), |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
35 ('/foo/bar/', ('/foo/bar/', 1), True), |
495
4284c673bb91
internal: Fix some edge-cases for splitting sub-URIs.
Ludovic Chabant <ludovic@chabant.com>
parents:
484
diff
changeset
|
36 ('/foo/bar/2', ('/foo/bar/', 2), True), |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
37 ('/foo/bar/2/', ('/foo/bar/', 2), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
38 ('/foo/bar.ext/', ('/foo/bar.ext/', 1), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
39 ('/foo/bar.ext/2/', ('/foo/bar.ext/', 2), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
40 ]) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
41 def test_split_sub_uri_trailing_slash(uri, expected, pretty_urls): |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
42 app = mock.MagicMock() |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
43 app.config = { |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
44 'site/root': '/', |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
45 'site/pretty_urls': pretty_urls, |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
46 'site/trailing_slash': True, |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
47 '__cache/pagination_suffix_re': '/(?P<num>\\d+)$'} |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
48 actual = split_sub_uri(app, uri) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
49 assert actual == (expected[0], expected[1]) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
50 |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
51 |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
52 @pytest.mark.parametrize('uri, expected, pretty_urls', [ |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
53 ('/', ('/', 1), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
54 ('/2', ('/', 2), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
55 ('/foo/bar', ('/foo/bar', 1), True), |
495
4284c673bb91
internal: Fix some edge-cases for splitting sub-URIs.
Ludovic Chabant <ludovic@chabant.com>
parents:
484
diff
changeset
|
56 ('/foo/bar/', ('/foo/bar', 1), True), |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
57 ('/foo/bar/2', ('/foo/bar', 2), True), |
495
4284c673bb91
internal: Fix some edge-cases for splitting sub-URIs.
Ludovic Chabant <ludovic@chabant.com>
parents:
484
diff
changeset
|
58 ('/foo/bar/2/', ('/foo/bar', 2), True), |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
59 ('/foo/bar.ext', ('/foo/bar.ext', 1), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
60 ('/foo/bar.ext/2', ('/foo/bar.ext', 2), True), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
61 ('/', ('/', 1), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
62 ('/2.html', ('/', 2), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
63 ('/foo/bar.html', ('/foo/bar.html', 1), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
64 ('/foo/bar/2.html', ('/foo/bar.html', 2), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
65 ('/foo/bar.ext', ('/foo/bar.ext', 1), False), |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
66 ('/foo/bar/2.ext', ('/foo/bar.ext', 2), False) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
67 ]) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
68 def test_split_sub_uri_with_root(uri, expected, pretty_urls): |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
69 app = mock.MagicMock() |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
70 app.config = { |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
316
diff
changeset
|
71 'site/root': '/whatever/', |
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
72 'site/pretty_urls': pretty_urls, |
316
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
73 '__cache/pagination_suffix_re': '/(?P<num>\\d+)$'} |
484
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
74 actual = split_sub_uri(app, '/whatever' + uri) |
d4321317beae
internal: Correctly split sub URIs. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
329
diff
changeset
|
75 assert actual == ('/whatever' + expected[0], expected[1]) |
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
76 |