Mercurial > piecrust2
annotate tests/test_sources_posts.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 | 22e767899e52 |
children |
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 |
1021
22e767899e52
tests: Fix path comparison in a test on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
979
diff
changeset
|
4 from .pathutil import slashfix |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 |
979
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
7 @pytest.mark.parametrize( |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
8 '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
|
9 [ |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
10 (lambda: mock_fs(), 'flat', [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
11 (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
|
12 'flat', |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 ['2014-01-01_foo.md'], |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 [(2014, 1, 1, 'foo')]), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
15 (lambda: mock_fs(), 'shallow', [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
16 (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
|
17 'shallow', |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 ['2014/01-01_foo.md'], |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 [(2014, 1, 1, 'foo')]), |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
20 (lambda: mock_fs(), 'hierarchy', [], []), |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
21 (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
|
22 'hierarchy', |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 ['2014/01/01_foo.md'], |
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 [(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
|
25 ]) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
26 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
|
27 expected_metadata): |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
28 fs = fs_fac() |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
29 fs.withConfig({ |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
30 'site': { |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
31 'sources': { |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
32 'test': {'type': 'posts/%s' % src_type}}, |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
33 'routes': [ |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
34 {'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
|
35 } |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
36 }) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
37 fs.withDir('kitchen/test') |
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
38 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
|
39 app = fs.getApp() |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
40 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
|
41 items = list(s.getAllContents()) |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
42 paths = [os.path.relpath(f.spec, s.fs_endpoint_path) for f in items] |
1021
22e767899e52
tests: Fix path comparison in a test on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
979
diff
changeset
|
43 assert paths == slashfix(expected_paths) |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
44 metadata = [ |
979
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']['year'], |
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']['month'], |
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']['day'], |
45ad976712ec
tests: Big push to get the tests to pass again.
Ludovic Chabant <ludovic@chabant.com>
parents:
411
diff
changeset
|
48 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
|
49 for f in items] |
411
e7b865f8f335
bake: Enable multiprocess baking.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
50 assert metadata == expected_metadata |
95
cb6eadea0845
Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
51 |