Mercurial > piecrust2
annotate tests/test_sources_autoconfig.py @ 1145:e94737572542
serve: Fix an issue where false positive matches were rendered as the requested page.
Now we try to render the page, but also try to detect for the most common "empty" pages.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 05 Jun 2018 22:08:51 -0700 |
parents | 2323f0788170 |
children |
rev | line source |
---|---|
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
1 import os.path |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import pytest |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from .mockutil import mock_fs, mock_fs_scope |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
267
diff
changeset
|
4 from .pathutil import slashfix |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 @pytest.mark.parametrize( |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
8 'fs_fac, src_config, expected_path, expected_slug, expected_foos', |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
9 [ |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
10 (lambda: mock_fs(), |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
11 {}, |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
12 None, '', []), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
13 (lambda: mock_fs().withPage('test/_index.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
14 {}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
15 '_index.md', '', []), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
16 (lambda: mock_fs().withPage('test/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
17 {}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
18 'something.md', 'something', []), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
19 (lambda: mock_fs().withPage('test/bar/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
20 {}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
21 'bar/something.md', 'something', ['bar']), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
22 (lambda: mock_fs().withPage('test/bar1/bar2/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
23 {}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
24 'bar1/bar2/something.md', 'something', ['bar1', 'bar2']), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
26 (lambda: mock_fs().withPage('test/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
27 {'collapse_single_values': True}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
28 'something.md', 'something', None), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
29 (lambda: mock_fs().withPage('test/bar/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
30 {'collapse_single_values': True}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
31 'bar/something.md', 'something', 'bar'), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
32 (lambda: mock_fs().withPage('test/bar1/bar2/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
33 {'collapse_single_values': True}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
34 'bar1/bar2/something.md', 'something', ['bar1', 'bar2']), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
36 (lambda: mock_fs().withPage('test/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
37 {'only_single_values': True}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
38 'something.md', 'something', None), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
39 (lambda: mock_fs().withPage('test/bar/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
40 {'only_single_values': True}, |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
41 'bar/something.md', 'something', 'bar') |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
42 ]) |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
43 def test_autoconfig_source_items( |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
44 fs_fac, src_config, expected_path, expected_slug, expected_foos): |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
45 site_config = { |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
46 'sources': { |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
47 'test': {'type': 'autoconfig', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
48 'setting_name': 'foo'} |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
49 }, |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
50 'routes': [ |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
51 {'url': '/%slug%', 'source': 'test'}] |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
52 } |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
53 site_config['sources']['test'].update(src_config) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
54 fs = fs_fac() |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
55 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
56 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
57 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
58 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
59 s = app.getSource('test') |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
60 items = list(s.getAllContents()) |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
61 |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
62 if expected_path is None: |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
63 assert len(items) == 0 |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
64 else: |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
65 assert len(items) == 1 |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
66 path = os.path.relpath(items[0].spec, s.fs_endpoint_path) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
67 assert path == slashfix(expected_path) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
68 slug = items[0].metadata['route_params']['slug'] |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
69 assert slug == expected_slug |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
70 foos = items[0].metadata['config']['foo'] |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
71 assert foos == expected_foos |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
72 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
73 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
74 def test_autoconfig_fails_if_multiple_folders(): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
75 site_config = { |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
76 'sources': { |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
77 'test': {'type': 'autoconfig', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
78 'setting_name': 'foo', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
79 'only_single_values': True} |
1098
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
80 }, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
81 'routes': [ |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
82 {'url': '/blah', 'source': 'test'} |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
83 ] |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
84 } |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
85 fs = mock_fs().withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 fs.withPage('test/bar1/bar2/something.md') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
88 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 s = app.getSource('test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 with pytest.raises(Exception): |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
91 list(s.getAllContents()) |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
92 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
93 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
94 @pytest.mark.parametrize( |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
95 'fs_fac, expected_paths, expected_route_params, expected_configs', |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
96 [ |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
97 (lambda: mock_fs(), [], [], []), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
98 (lambda: mock_fs().withPage('test/_index.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
99 ['_index.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
100 [{'slug': ''}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
101 [{'foo': 0, 'foo_trail': [0]}]), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
102 (lambda: mock_fs().withPage('test/something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
103 ['something.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
104 [{'slug': 'something'}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
105 [{'foo': 0, 'foo_trail': [0]}]), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
106 (lambda: mock_fs().withPage('test/08_something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
107 ['08_something.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
108 [{'slug': 'something'}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
109 [{'foo': 8, 'foo_trail': [8]}]), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
110 (lambda: mock_fs().withPage('test/02_there/08_something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
111 ['02_there/08_something.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
112 [{'slug': 'there/something'}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
113 [{'foo': 8, 'foo_trail': [2, 8]}]), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
114 ]) |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
115 def test_ordered_source_items(fs_fac, expected_paths, expected_route_params, |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
116 expected_configs): |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
117 site_config = { |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
118 'sources': { |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
119 'test': {'type': 'ordered', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
120 'setting_name': 'foo'} |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
121 }, |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
122 'routes': [ |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
123 {'url': '/%slug%', 'source': 'test'}] |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
124 } |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
125 fs = fs_fac() |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
128 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
129 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
130 s = app.getSource('test') |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
131 items = list(s.getAllContents()) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
132 |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
133 paths = [os.path.relpath(f.spec, s.fs_endpoint_path) for f in items] |
286
a2d283d1033d
tests: Fixes for running on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
267
diff
changeset
|
134 assert paths == slashfix(expected_paths) |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
135 metadata = [f.metadata['route_params'] for f in items] |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
136 assert metadata == expected_route_params |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
137 configs = [f.metadata['config'] for f in items] |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
138 for c in configs: |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
139 c.pop('format') |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
140 assert configs == expected_configs |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
141 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
142 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
143 @pytest.mark.parametrize( |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
144 'fs_fac, route_path, expected_path, expected_metadata', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
145 [ |
1098
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
146 ( |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
147 lambda: mock_fs(), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
148 'missing', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
149 None, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
150 None), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
151 ( |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
152 lambda: mock_fs().withPage('test/something.html'), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
153 'something', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
154 'something.html', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
155 {'route_params': {'slug': 'something'}, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
156 'config': {'foo': 0, 'foo_trail': [0]}}), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
157 ( |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
158 lambda: mock_fs().withPage('test/bar/something.html'), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
159 'bar/something', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
160 'bar/something.html', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
161 {'route_params': {'slug': 'bar/something'}, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
162 'config': {'foo': 0, 'foo_trail': [0]}}), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
163 ( |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
164 lambda: mock_fs().withPage('test/42_something.html'), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
165 'something', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
166 '42_something.html', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
167 {'route_params': {'slug': 'something'}, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
168 'config': {'foo': 42, 'foo_trail': [42]}}), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
169 ( |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
170 lambda: mock_fs().withPage('test/bar/42_something.html'), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
171 'bar/something', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
172 'bar/42_something.html', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
173 {'route_params': {'slug': 'bar/something'}, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
174 'config': {'foo': 42, 'foo_trail': [42]}}), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
175 ( |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
176 (lambda: mock_fs() |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
177 .withPage('test/42_something.html') |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
178 .withPage('test/43_other_something.html')), |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
179 'something', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
180 '42_something.html', |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
181 {'route_params': {'slug': 'something'}, |
2323f0788170
config: Report error if a non-asset source has no URL route.
Ludovic Chabant <ludovic@chabant.com>
parents:
989
diff
changeset
|
182 'config': {'foo': 42, 'foo_trail': [42]}}), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
183 ]) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
184 def test_ordered_source_find(fs_fac, route_path, expected_path, |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
185 expected_metadata): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
186 site_config = { |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
187 'sources': { |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
188 'test': {'type': 'ordered', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
189 'setting_name': 'foo'} |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
190 }, |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
191 'routes': [ |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
192 {'url': '/%slug%', 'source': 'test'}] |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
193 } |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
194 fs = fs_fac() |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
195 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
196 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
197 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
198 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
199 s = app.getSource('test') |
242
f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Ludovic Chabant <ludovic@chabant.com>
parents:
239
diff
changeset
|
200 route_metadata = {'slug': route_path} |
989
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
979
diff
changeset
|
201 item = s.findContentFromRoute(route_metadata) |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
202 if item is None: |
363
dd25bd3ce1f9
serve: Refactoring and fixes to be able to serve taxonomy pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
286
diff
changeset
|
203 assert expected_path is None and expected_metadata is None |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
204 else: |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
205 assert os.path.relpath(item.spec, s.fs_endpoint_path) == \ |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
206 slashfix(expected_path) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
207 assert item.metadata == expected_metadata |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
208 |