annotate tests/test_routing.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 4b0c87e7df73
children 61145dcd56e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
177
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import mock
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import pytest
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from piecrust.routing import Route
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 @pytest.mark.parametrize(
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 'config, metadata, expected',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 [
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 ({'url': '/%foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 {'foo': 'bar'}, True),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 ({'url': '/%foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 {'zoo': 'zar', 'foo': 'bar'}, True),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 ({'url': '/%foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 {'zoo': 'zar'}, False),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 ({'url': '/%foo%/%zoo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 {'zoo': 'zar'}, False)
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 ])
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 def test_matches_metadata(config, metadata, expected):
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 app = mock.Mock()
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 app.config = {'site/root': '/'}
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 config.setdefault('source', 'blah')
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 route = Route(app, config)
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 m = route.matchesMetadata(metadata)
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 assert m == expected
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 @pytest.mark.parametrize(
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 'config, uri, expected_match',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 [
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 ({'url': '/%foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 'something',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 {'foo': 'something'}),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 ({'url': '/%foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 'something/other',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 None),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 ({'url': '/%path:foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 'something/other',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 {'foo': 'something/other'}),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 ({'url': '/%path:foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 '',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 {'foo': ''}),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 ({'url': '/prefix/%path:foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 'prefix/something/other',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 {'foo': 'something/other'}),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 ({'url': '/prefix/%path:foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 'prefix/',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 {'foo': ''}),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 ({'url': '/prefix/%path:foo%'},
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 'prefix',
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 {}),
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 ])
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 def test_match_uri(config, uri, expected_match):
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 app = mock.Mock()
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 app.config = {'site/root': '/'}
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 config.setdefault('source', 'blah')
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 route = Route(app, config)
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 assert route.uri_pattern == config['url'].lstrip('/')
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 m = route.matchUri(uri)
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 assert m == expected_match
4b0c87e7df73 tests: Add unit tests for routing classes.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60