Mercurial > piecrust2
view tests/test_uriutil.py @ 334:b034f6f15e22
bake: Several bug taxonomy-related fixes for incorrect incremental bakes.
* Improve how the baker processes taxonomy terms and figures out what needs
to be re-baked or not.
* Create bake entries for clean taxnomy terms so they're not deleted by an
incremental bake.
* Add more information to bake records.
* Slugify taxonomy terms is now done by the route in one place.
* Fix a bug where the cache key for invalidating rendered segments was not
computed the same way as when the caching was done.
* Fix how term combinations are passed around, rendered, printed, parsed, etc.
(TODO: more word needed in the routing functions)
* Expose to the template whether a taxonomy term is a combination or not.
* Display term combinations better in the built-in theme.
* Rename `route.taxonomy` to `route.taxonomy_name` to prevent confusion.
* Add options to show bake records for previous bakes.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 03 Apr 2015 10:59:50 -0700 |
parents | 422052d2e978 |
children | d4321317beae |
line wrap: on
line source
import mock import pytest from piecrust.uriutil import UriInfo, parse_uri, split_sub_uri @pytest.mark.parametrize('routes, uri, expected', [ ({}, '/foo', None), ( {'/articles/%slug%': {'source': 'dummy'}}, '/articles/foo', UriInfo('', 'dummy', {'slug': 'foo'})), ( {'/foo/%bar%': {'source': 'foo'}, '/other/%one%-%two%': {'source': 'other'}}, '/other/some-thing', UriInfo('', 'other', {'one': 'some', 'two': 'thing'})) ]) def test_parse_uri(routes, uri, expected): if expected is not None: expected.uri = uri for pattern, args in routes.items(): if 'taxonomy' not in args: args['taxonomy'] = None actual = parse_uri(routes, uri) assert actual == expected @pytest.mark.parametrize('uri, expected, pretty_urls', [ ('foo/bar', ('foo/bar', 1), True), ('foo/bar/2', ('foo/bar', 2), True), ('foo/bar.ext', ('foo/bar.ext', 1), True), ('foo/bar.ext/2', ('foo/bar.ext', 2), True), ('foo/bar.html', ('foo/bar.html', 1), False), ('foo/bar/2.html', ('foo/bar.html', 2), False), ('foo/bar.ext', ('foo/bar.ext', 1), False), ('foo/bar/2.ext', ('foo/bar.ext', 2), False) ]) def test_split_sub_uri(uri, expected, pretty_urls): app = mock.MagicMock() app.config = { 'site/root': '/whatever/', 'site/pretty_urls': pretty_urls, '__cache/pagination_suffix_re': '/(?P<num>\\d+)$'} actual = split_sub_uri(app, '/whatever/' + uri) assert actual == ('/whatever/' + expected[0], expected[1])