Mercurial > piecrust2
view tests/test_serving.py @ 173:0a86a7a6b284
routes: Actually match metadata when finding routes, fix problems with paths.
When we look for a route that matches a given page, we now look at the
source metadata that comes with that page, and compare it to the metadata
we need to build URIs.
Also, when matching URIs, we handle the case where a 'path'-component in
our pattern may be completely empty, and thus we may be missing some trailing
slashes in the URI.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 03 Jan 2015 21:10:44 -0800 |
parents | f5ca5c5bed85 |
children | 7aa5f7880f71 |
line wrap: on
line source
import re import pytest import mock from piecrust.serving import find_routes from piecrust.sources.base import REALM_USER, REALM_THEME @pytest.mark.parametrize('uri, route_specs, expected', [ ('/', [{'src': 'pages', 'pat': '(?P<path>.*)'}], [('pages', {'path': ''})]), ('/', [{'src': 'pages', 'pat': '(?P<path>.*)'}, {'src': 'theme', 'pat': '(?P<path>.*)', 'realm': REALM_THEME}], [('pages', {'path': ''}), ('theme', {'path': ''})]) ]) def test_find_routes(uri, route_specs, expected): routes = [] for rs in route_specs: m = mock.Mock() m.source_name = rs['src'] m.source_realm = rs.setdefault('realm', REALM_USER) m.uri_re = re.compile(rs['pat']) routes.append(m) matching = find_routes(routes, uri) assert len(matching) == len(expected) for i in range(len(matching)): route, metadata = matching[i] exp_source, exp_md = expected[i] assert route.source_name == exp_source assert metadata == exp_md