view tests/test_uriutil.py @ 317:6c5de6edacf7

internal: Be more forgiving about building `Taxonomy` objects. Add `setting_name`. The setting name of a taxonomy is whatever name is used to assign terms of that taxonomy to a page. If the taxonomy is "multiple", this is the name of the taxonomy. If not, it's the term name (a singular name).
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 28 Mar 2015 14:17:50 -0700
parents eb958151c8dc
children 422052d2e978
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/pretty_urls': pretty_urls,
            '__cache/pagination_suffix_re': '/(?P<num>\\d+)$'}
    actual = split_sub_uri(app, uri)
    assert actual == expected