view tests/test_routing.py @ 191:308d5180bf81

processing: Add more information to the pipeline record. We now save whether an asset was processed by an external tool that bypasses the pipeline, and the tree of processor names involved.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 11 Jan 2015 23:01:21 -0800
parents 4b0c87e7df73
children 61145dcd56e0
line wrap: on
line source

import mock
import pytest
from piecrust.routing import Route


@pytest.mark.parametrize(
        'config, metadata, expected',
        [
            ({'url': '/%foo%'},
                {'foo': 'bar'}, True),
            ({'url': '/%foo%'},
                {'zoo': 'zar', 'foo': 'bar'}, True),
            ({'url': '/%foo%'},
                {'zoo': 'zar'}, False),
            ({'url': '/%foo%/%zoo%'},
                {'zoo': 'zar'}, False)
            ])
def test_matches_metadata(config, metadata, expected):
    app = mock.Mock()
    app.config = {'site/root': '/'}
    config.setdefault('source', 'blah')
    route = Route(app, config)
    m = route.matchesMetadata(metadata)
    assert m == expected


@pytest.mark.parametrize(
        'config, uri, expected_match',
        [
            ({'url': '/%foo%'},
                'something',
                {'foo': 'something'}),
            ({'url': '/%foo%'},
                'something/other',
                None),
            ({'url': '/%path:foo%'},
                'something/other',
                {'foo': 'something/other'}),
            ({'url': '/%path:foo%'},
                '',
                {'foo': ''}),
            ({'url': '/prefix/%path:foo%'},
                'prefix/something/other',
                {'foo': 'something/other'}),
            ({'url': '/prefix/%path:foo%'},
                'prefix/',
                {'foo': ''}),
            ({'url': '/prefix/%path:foo%'},
                'prefix',
                {}),
            ])
def test_match_uri(config, uri, expected_match):
    app = mock.Mock()
    app.config = {'site/root': '/'}
    config.setdefault('source', 'blah')
    route = Route(app, config)
    assert route.uri_pattern == config['url'].lstrip('/')
    m = route.matchUri(uri)
    assert m == expected_match