comparison tests/test_sources_base.py @ 30:4bd840ae75cd

Fix stupid bug in default source, add some unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 19 Aug 2014 12:46:55 -0700
parents
children 485682a6de50
comparison
equal deleted inserted replaced
29:7e44f6092a1d 30:4bd840ae75cd
1 import os
2 import pytest
3 from piecrust.app import PieCrust
4 from piecrust.sources.base import DefaultPageSource
5 from .mockutil import mock_fs, mock_fs_scope
6
7
8 @pytest.mark.parametrize('fs, expected_paths, expected_slugs', [
9 (mock_fs(), [], []),
10 (mock_fs().withPage('test/foo.html'),
11 ['foo.html'], ['foo']),
12 (mock_fs().withPage('test/foo.md'),
13 ['foo.md'], ['foo']),
14 (mock_fs().withPage('test/foo.ext'),
15 ['foo.ext'], ['foo.ext']),
16 (mock_fs().withPage('test/foo/bar.html'),
17 ['foo/bar.html'], ['foo/bar']),
18 (mock_fs().withPage('test/foo/bar.md'),
19 ['foo/bar.md'], ['foo/bar']),
20 (mock_fs().withPage('test/foo/bar.ext'),
21 ['foo/bar.ext'], ['foo/bar.ext']),
22 ])
23 def test_default_source_factories(fs, expected_paths, expected_slugs):
24 fs.withConfig({
25 'site': {
26 'sources': {
27 'test': {}},
28 'routes': [
29 {'url': '/%path%', 'source': 'test'}]
30 }
31 })
32 fs.withDir('kitchen/_content/test')
33 with mock_fs_scope(fs):
34 app = PieCrust(fs.path('kitchen'), cache=False)
35 s = app.getSource('test')
36 facs = list(s.buildPageFactories())
37 paths = [f.rel_path for f in facs]
38 assert paths == expected_paths
39 slugs = [f.metadata['path'] for f in facs]
40 assert slugs == expected_slugs
41
42
43
44 @pytest.mark.parametrize('ref_path, expected', [
45 ('foo.html', '/kitchen/_content/test/foo.html'),
46 ('foo/bar.html', '/kitchen/_content/test/foo/bar.html'),
47 ])
48 def test_default_source_resolve_ref(ref_path, expected):
49 fs = mock_fs()
50 fs.withConfig({
51 'site': {
52 'sources': {
53 'test': {}},
54 'routes': [
55 {'url': '/%path%', 'source': 'test'}]
56 }
57 })
58 expected = fs.path(expected).replace('/', os.sep)
59 with mock_fs_scope(fs):
60 app = PieCrust(fs.path('kitchen'), cache=False)
61 s = app.getSource('test')
62 actual = s.resolveRef(ref_path)
63 assert actual == expected
64