diff tests/test_server.py @ 3:f485ba500df3

Gigantic change to basically make PieCrust 2 vaguely functional. - Serving works, with debug window. - Baking works, multi-threading, with dependency handling. - Various things not implemented yet.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 10 Aug 2014 23:43:16 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_server.py	Sun Aug 10 23:43:16 2014 -0700
@@ -0,0 +1,34 @@
+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'])
+        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
+