diff tests/test_uriutil.py @ 33:62c7a97c8340

Get the un-paginated URL of a page early and pass that around.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Aug 2014 15:36:28 -0700
parents 474c9882decf
children eb958151c8dc
line wrap: on
line diff
--- a/tests/test_uriutil.py	Tue Aug 19 14:30:19 2014 -0700
+++ b/tests/test_uriutil.py	Tue Aug 19 15:36:28 2014 -0700
@@ -1,5 +1,6 @@
+import mock
 import pytest
-from piecrust.uriutil import UriInfo, parse_uri
+from piecrust.uriutil import UriInfo, parse_uri, get_first_sub_uri
 
 
 @pytest.mark.parametrize('routes, uri, expected', [
@@ -24,3 +25,22 @@
     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
+