Mercurial > piecrust2
view tests/test_serving.py @ 242:f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Interfaces that sources can implement are in `sources.interfaces`. The default
page source is in `sources.default`. The `SimplePageSource` is gone since most
subclasses only wanted to do *some* stuff the same, but *lots* of stuff
slightly different. I may have to revisit the code to extract exactly the code
that's in common.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 18 Feb 2015 18:35:03 -0800 |
parents | d47d9493bb0a |
children | 65e6d72f3877 |
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']) m.matchUri = lambda u: m.uri_re.match(u).groupdict() 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