Mercurial > piecrust2
annotate tests/test_sources_autoconfig.py @ 1051:971b4d67e82a
serve: Fix problems with assets disappearing between servings.
When an asset file changes, its source's pipeline is re-run. But that created
a bake record that only had that pipeline's output, so the other outputs were
incorrectly considered empty and therefore any stray files were removed. Now we
copy over bake records for the pipelines we don't run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 26 Jan 2018 18:05:02 -0800 |
parents | 8adc27285d93 |
children | 2323f0788170 |
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} |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
80 } |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
81 } |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
82 fs = mock_fs().withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
83 fs.withPage('test/bar1/bar2/something.md') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
84 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
85 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
86 s = app.getSource('test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
87 with pytest.raises(Exception): |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
88 list(s.getAllContents()) |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
89 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
90 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
91 @pytest.mark.parametrize( |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
92 '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
|
93 [ |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
94 (lambda: mock_fs(), [], [], []), |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
95 (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
|
96 ['_index.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
97 [{'slug': ''}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
98 [{'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
|
99 (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
|
100 ['something.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
101 [{'slug': 'something'}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
102 [{'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
|
103 (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
|
104 ['08_something.md'], |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
105 [{'slug': 'something'}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
106 [{'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
|
107 (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
|
108 ['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
|
109 [{'slug': 'there/something'}], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
110 [{'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
|
111 ]) |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
112 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
|
113 expected_configs): |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
114 site_config = { |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
115 'sources': { |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
116 'test': {'type': 'ordered', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
117 'setting_name': 'foo'} |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
118 }, |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
119 'routes': [ |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
120 {'url': '/%slug%', 'source': 'test'}] |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
121 } |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
122 fs = fs_fac() |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
123 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
124 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
125 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
126 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
127 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
|
128 items = list(s.getAllContents()) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
129 |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 for c in configs: |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
136 c.pop('format') |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
137 assert configs == expected_configs |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
138 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
139 |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
140 @pytest.mark.parametrize( |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
141 '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
|
142 [ |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
143 (lambda: mock_fs(), 'missing', None, None), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
144 (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
|
145 'something', 'something.md', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
146 {'slug': 'something', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
147 'config': {'foo': 0, 'foo_trail': [0]}}), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
148 (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
|
149 'bar/something', 'bar/something.md', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
150 {'slug': 'bar/something', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
151 'config': {'foo': 0, 'foo_trail': [0]}}), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
152 (lambda: mock_fs().withPage('test/42_something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
153 'something', '42_something.md', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
154 {'slug': 'something', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
155 'config': {'foo': 42, 'foo_trail': [42]}}), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
156 (lambda: mock_fs().withPage('test/bar/42_something.md'), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
157 'bar/something', 'bar/42_something.md', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
158 {'slug': 'bar/something', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
159 'config': {'foo': 42, 'foo_trail': [42]}}), |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
160 |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
161 ((lambda: mock_fs() |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
162 .withPage('test/42_something.md') |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
163 .withPage('test/43_other_something.md')), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
164 'something', '42_something.md', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
165 {'slug': 'something', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
166 'config': {'foo': 42, 'foo_trail': [42]}}), |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
167 ]) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
168 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
|
169 expected_metadata): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
170 site_config = { |
974
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
171 'sources': { |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
172 'test': {'type': 'ordered', |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
173 'setting_name': 'foo'} |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
174 }, |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
175 'routes': [ |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
176 {'url': '/%slug%', 'source': 'test'}] |
72f17534d58e
tests: First pass on making unit tests work again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
177 } |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
363
diff
changeset
|
178 fs = fs_fac() |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
179 fs.withConfig({'site': site_config}) |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
180 fs.withDir('kitchen/test') |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
181 with mock_fs_scope(fs): |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
182 app = fs.getApp() |
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
183 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
|
184 route_metadata = {'slug': route_path} |
989
8adc27285d93
bake: Big pass on bake performance.
Ludovic Chabant <ludovic@chabant.com>
parents:
979
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 else: |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
189 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
|
190 slashfix(expected_path) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
974
diff
changeset
|
191 assert item.metadata == expected_metadata |
239
f43f19975671
sources: Refactor `autoconfig` source, add `OrderedPageSource`.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
192 |