Mercurial > piecrust2
annotate tests/test_sources_posts.py @ 1014:071f30aa04bb
bake: Do template caching in a background job if possible.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 28 Nov 2017 21:28:15 -0800 |
parents | 45ad976712ec |
children | 22e767899e52 |
rev | line source |
---|---|
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
1 import os.path |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import pytest |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 from .mockutil import mock_fs, mock_fs_scope |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
6 @pytest.mark.parametrize( |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
7 'fs_fac, src_type, expected_paths, expected_metadata', |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
8 [ |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
9 (lambda: mock_fs(), 'flat', [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
10 (lambda: mock_fs().withPage('test/2014-01-01_foo.md'), |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 'flat', |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 ['2014-01-01_foo.md'], |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 [(2014, 1, 1, 'foo')]), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
14 (lambda: mock_fs(), 'shallow', [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
15 (lambda: mock_fs().withPage('test/2014/01-01_foo.md'), |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 'shallow', |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 ['2014/01-01_foo.md'], |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 [(2014, 1, 1, 'foo')]), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
19 (lambda: mock_fs(), 'hierarchy', [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
20 (lambda: mock_fs().withPage('test/2014/01/01_foo.md'), |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
21 'hierarchy', |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 ['2014/01/01_foo.md'], |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 [(2014, 1, 1, 'foo')]), |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
24 ]) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
25 def test_post_source_items(fs_fac, src_type, expected_paths, |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
26 expected_metadata): |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
27 fs = fs_fac() |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
28 fs.withConfig({ |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
29 'site': { |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
30 'sources': { |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
31 'test': {'type': 'posts/%s' % src_type}}, |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
32 'routes': [ |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
33 {'url': '/%slug%', 'source': 'test'}] |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
34 } |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
35 }) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
36 fs.withDir('kitchen/test') |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
37 with mock_fs_scope(fs): |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
38 app = fs.getApp() |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
39 s = app.getSource('test') |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
40 items = list(s.getAllContents()) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
41 paths = [os.path.relpath(f.spec, s.fs_endpoint_path) for f in items] |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
42 assert paths == expected_paths |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
43 metadata = [ |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
44 (f.metadata['route_params']['year'], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
45 f.metadata['route_params']['month'], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
46 f.metadata['route_params']['day'], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
47 f.metadata['route_params']['slug']) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
48 for f in items] |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
49 assert metadata == expected_metadata |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
50 |