comparison tests/test_baking_baker.py @ 329:422052d2e978

internal: Try handling URLs in a consistent way. * Now URLs passed to, and returned from, routes will always be absolute URLs, i.e. URLs including the site root. * Validate the site root at config loading time to make sure it starts and ends with a slash. * Get rid of unused stuff. * Add tests.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 31 Mar 2015 23:03:28 -0700
parents 65e6d72f3877
children 76c838453dbe
comparison
equal deleted inserted replaced
328:2a5996e0d3ec 329:422052d2e978
38 app = get_mock_app() 38 app = get_mock_app()
39 if pretty: 39 if pretty:
40 app.config.set('site/pretty_urls', True) 40 app.config.set('site/pretty_urls', True)
41 assert app.config.get('site/pretty_urls') == pretty 41 assert app.config.get('site/pretty_urls') == pretty
42 42
43 baker = PageBaker(app, '/destination') 43 for site_root in ['/', '/whatever/']:
44 path = baker.getOutputPath(uri) 44 app.config.set('site/root', site_root)
45 expected = os.path.normpath( 45 baker = PageBaker(app, '/destination')
46 os.path.join('/destination', expected)) 46 path = baker.getOutputPath(site_root + uri)
47 assert expected == path 47 expected = os.path.normpath(
48 os.path.join('/destination', expected))
49 assert expected == path
48 50
49 51
50 def test_empty_bake(): 52 def test_empty_bake():
51 fs = mock_fs() 53 fs = mock_fs()
52 with mock_fs_scope(fs): 54 with mock_fs_scope(fs):
58 assert os.path.isdir(out_dir) 60 assert os.path.isdir(out_dir)
59 structure = fs.getStructure('kitchen/_counter') 61 structure = fs.getStructure('kitchen/_counter')
60 assert list(structure.keys()) == ['index.html'] 62 assert list(structure.keys()) == ['index.html']
61 63
62 64
63 def test_simple_bake(): 65 @pytest.mark.parametrize(
66 'site_root',
67 [
68 ('/'), ('/whatever')
69 ])
70 def test_simple_bake(site_root):
71 pconf = {'layout': 'none', 'format': 'none'}
64 fs = (mock_fs() 72 fs = (mock_fs()
65 .withPage('posts/2010-01-01_post1.md', {'layout': 'none', 'format': 'none'}, 'post one') 73 .withConfig({'site': {'root': site_root}})
66 .withPage('pages/_index.md', {'layout': 'none', 'format': 'none'}, "something")) 74 .withPage('posts/2010-01-01_post1.md', pconf, 'post one')
75 .withPage('pages/about.md', pconf, 'URL: {{page.url}}')
76 .withPage('pages/_index.md', pconf, "something"))
67 with mock_fs_scope(fs): 77 with mock_fs_scope(fs):
68 out_dir = fs.path('kitchen/_counter') 78 out_dir = fs.path('kitchen/_counter')
69 app = fs.getApp() 79 app = fs.getApp()
70 baker = Baker(app, out_dir) 80 baker = Baker(app, out_dir)
71 baker.bake() 81 baker.bake()
72 structure = fs.getStructure('kitchen/_counter') 82 structure = fs.getStructure('kitchen/_counter')
73 assert structure == { 83 assert structure == {
74 '2010': {'01': {'01': {'post1.html': 'post one'}}}, 84 '2010': {'01': {'01': {'post1.html': 'post one'}}},
85 'about.html': 'URL: %s' % (
86 site_root.rstrip('/') + '/about.html'),
75 'index.html': 'something'} 87 'index.html': 'something'}
76 88
77 89
78 def test_removed(): 90 def test_removed():
79 fs = (mock_fs() 91 fs = (mock_fs()
145 "{%endfor%}")) 157 "{%endfor%}"))
146 with mock_fs_scope(fs): 158 with mock_fs_scope(fs):
147 out_dir = fs.path('kitchen/_counter') 159 out_dir = fs.path('kitchen/_counter')
148 app = fs.getApp() 160 app = fs.getApp()
149 baker = Baker(app, out_dir) 161 baker = Baker(app, out_dir)
150 baker.bake() 162 r = baker.bake()
163 assert r.success is True
151 164
152 s = fs.getStructure('kitchen/_counter/tag') 165 s = fs.getStructure('kitchen/_counter/tag')
153 assert s['foo.html'] == "Pages in foo\nPost 3\nPost 1\n" 166 assert s['foo.html'] == "Pages in foo\nPost 3\nPost 1\n"
154 assert s['bar.html'] == "Pages in bar\nPost 3\nPost 2\n" 167 assert s['bar.html'] == "Pages in bar\nPost 3\nPost 2\n"
155 assert s['whatever.html'] == "Pages in whatever\nPost 2\n" 168 assert s['whatever.html'] == "Pages in whatever\nPost 2\n"