comparison tests/test_sources_base.py @ 363:dd25bd3ce1f9

serve: Refactoring and fixes to be able to serve taxonomy pages. * Page sources' `findPagePath` is renamed to `findPageFactory`, so that it also returns source metadata. * Page refs now store possible hits more properly, and use the previous point to also store metadata. As a result, they can also return a proper factory. * Implement `findPageFactory` correctly in all built-in sources. * When the Chef server matches a taxonomy page, get the source metadata from the page ref in order to make a more proper page. * Make the `getRoute(s)` functions explicitely say if they want taxonomy routes or not.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Apr 2015 15:07:40 -0700
parents a2d283d1033d
children e7b865f8f335
comparison
equal deleted inserted replaced
362:ff595828a364 363:dd25bd3ce1f9
39 assert paths == expected_paths 39 assert paths == expected_paths
40 slugs = [f.metadata['slug'] for f in facs] 40 slugs = [f.metadata['slug'] for f in facs]
41 assert slugs == expected_slugs 41 assert slugs == expected_slugs
42 42
43 43
44 44 @pytest.mark.parametrize(
45 @pytest.mark.parametrize('ref_path, expected', [ 45 'ref_path, expected_path, expected_metadata',
46 ('foo.html', '/kitchen/test/foo.html'), 46 [
47 ('foo/bar.html', '/kitchen/test/foo/bar.html'), 47 ('foo.html', '/kitchen/test/foo.html', {'slug': 'foo'}),
48 ('foo/bar.html', '/kitchen/test/foo/bar.html',
49 {'slug': 'foo/bar'}),
48 ]) 50 ])
49 def test_default_source_resolve_ref(ref_path, expected): 51 def test_default_source_resolve_ref(ref_path, expected_path,
52 expected_metadata):
50 fs = mock_fs() 53 fs = mock_fs()
51 fs.withConfig({ 54 fs.withConfig({
52 'site': { 55 'site': {
53 'sources': { 56 'sources': {
54 'test': {}}, 57 'test': {}},
55 'routes': [ 58 'routes': [
56 {'url': '/%path%', 'source': 'test'}] 59 {'url': '/%path%', 'source': 'test'}]
57 } 60 }
58 }) 61 })
59 expected = fs.path(expected).replace('/', os.sep) 62 expected_path = fs.path(expected_path).replace('/', os.sep)
60 with mock_fs_scope(fs): 63 with mock_fs_scope(fs):
61 app = PieCrust(fs.path('kitchen'), cache=False) 64 app = PieCrust(fs.path('kitchen'), cache=False)
62 s = app.getSource('test') 65 s = app.getSource('test')
63 actual = s.resolveRef(ref_path) 66 actual_path, actual_metadata = s.resolveRef(ref_path)
64 assert actual == expected 67 assert actual_path == expected_path
68 assert actual_metadata == expected_metadata
65 69
66 70
67 @pytest.mark.parametrize('page_ref, expected_source_name, expected_rel_path, ' 71 @pytest.mark.parametrize('page_ref, expected_source_name, expected_rel_path, '
68 'expected_possible_paths', [ 72 'expected_possible_paths', [
69 ('foo:one.md', 'foo', 'one.md', 73 ('foo:one.md', 'foo', 'one.md',