view tests/test_uriutil.py @ 196:154b8df04829

processing: Add Compass and Sass processors. The Sass processor is similar to the Less processor, i.e. it tries to be part of the structured pipeline processing by using the mapfile produced by the Sass compiler in order to provide a list of dependencies. The Compass processor is completely acting outside of the pipeline, so the server won't know what's up to date and what's not. It's expected that the user will run `compass watch` to keep things up to date. However, it will require to pass the server's cache directory to put things in, so we'll need to add some easy way to get that path for the user.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 11 Jan 2015 23:08:49 -0800
parents 62c7a97c8340
children eb958151c8dc
line wrap: on
line source

import mock
import pytest
from piecrust.uriutil import UriInfo, parse_uri, get_first_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', True),
    ('foo/bar/2', 'foo/bar', True),
    ('foo/bar.ext', 'foo/bar.ext', True),
    ('foo/bar.ext/2', 'foo/bar.ext', True),
    ('foo/bar.html', 'foo/bar.html', False),
    ('foo/bar/2.html', 'foo/bar.html', False),
    ('foo/bar.ext', 'foo/bar.ext', False),
    ('foo/bar/2.ext', 'foo/bar.ext', False)
    ])
def test_get_first_sub_uri(uri, expected, pretty_urls):
    app = mock.MagicMock()
    app.config = {
            'site/pretty_urls': pretty_urls,
            '__cache/pagination_suffix_re': '/(\\d+)$'}
    actual = get_first_sub_uri(app, uri)
    assert actual == expected