Mercurial > piecrust2
annotate tests/test_uriutil.py @ 369:4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
* We need a distinction between source metadata and route metadata. In most
cases they're the same, but in cases like taxonomy pages, route metadata
contains more things that can't be in source metadata if we want to re-use
cached pages.
* Create a new `QualifiedPage` type which is a page with a specific route
and route metadata. Pass this around in many places.
* Instead of passing an URL around, use the route in the `QualifiedPage` to
generate URLs. This is better since it removes the guess-work from trying
to generate URLs for sub-pages.
* Deep-copy app and page configurations before passing them around to things
that could modify them, like data builders and such.
* Exclude taxonomy pages from iterator data providers.
* Properly nest iterator data providers for when the theme and user page
sources are merged inside `site.pages`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 03 May 2015 18:47:10 -0700 |
parents | 422052d2e978 |
children | d4321317beae |
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 |
316
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
3 from piecrust.uriutil import UriInfo, parse_uri, split_sub_uri |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 @pytest.mark.parametrize('routes, uri, expected', [ |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 ({}, '/foo', None), |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 ( |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 {'/articles/%slug%': {'source': 'dummy'}}, |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 '/articles/foo', |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 UriInfo('', 'dummy', {'slug': 'foo'})), |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 ( |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 {'/foo/%bar%': {'source': 'foo'}, |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 '/other/%one%-%two%': {'source': 'other'}}, |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 '/other/some-thing', |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 UriInfo('', 'other', {'one': 'some', 'two': 'thing'})) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 ]) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 def test_parse_uri(routes, uri, expected): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 if expected is not None: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 expected.uri = uri |
5 | 21 for pattern, args in routes.items(): |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 if 'taxonomy' not in args: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 args['taxonomy'] = None |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 actual = parse_uri(routes, uri) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 assert actual == expected |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 |
33
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
28 |
62c7a97c8340
Get the un-paginated URL of a page early and pass that around.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
29 @pytest.mark.parametrize('uri, expected, pretty_urls', [ |
316
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
30 ('foo/bar', ('foo/bar', 1), True), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
31 ('foo/bar/2', ('foo/bar', 2), True), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
32 ('foo/bar.ext', ('foo/bar.ext', 1), True), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
33 ('foo/bar.ext/2', ('foo/bar.ext', 2), True), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
34 ('foo/bar.html', ('foo/bar.html', 1), False), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
35 ('foo/bar/2.html', ('foo/bar.html', 2), False), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
36 ('foo/bar.ext', ('foo/bar.ext', 1), False), |
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
37 ('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
|
38 ]) |
316
eb958151c8dc
tests: Bad me, the tests were broken. Now they're fixed.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
39 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
|
40 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
|
41 app.config = { |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
316
diff
changeset
|
42 '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
|
43 '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
|
44 '__cache/pagination_suffix_re': '/(?P<num>\\d+)$'} |
329
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
316
diff
changeset
|
45 actual = split_sub_uri(app, '/whatever/' + uri) |
422052d2e978
internal: Try handling URLs in a consistent way.
Ludovic Chabant <ludovic@chabant.com>
parents:
316
diff
changeset
|
46 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
|
47 |