Mercurial > piecrust2
annotate tests/test_routing.py @ 215:a47580a0955b
bake: Better error handling for the processing pipeline.
Pipeline jobs now keep track of whether they've seen any errors. This is
aggregated into an overall "success" flag for the processing record. Also, jobs
keep going as long as there's no critical (i.e. internal) failure happening.
Errors raised by processors are also better tracked: the actual processor that
failed, along with the input file, are tracks in the processing record.
The `bake` command returns a failure exit code if processing saw any error.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 31 Jan 2015 17:08:02 -0800 |
parents | 4b0c87e7df73 |
children | 61145dcd56e0 |
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 |