Mercurial > piecrust2
diff tests/test_baking_baker.py @ 324:65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
* Properly use the taxonomy's setting name where appropriate.
* Delete duplicated (and sometimes incorrect) code in 2 places to setup
filtering on an index page and consolidate it on the `PageRenderingContext`.
* Add unit tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Mar 2015 23:08:37 -0700 |
parents | a2d283d1033d |
children | 422052d2e978 |
line wrap: on
line diff
--- a/tests/test_baking_baker.py Sun Mar 29 23:05:03 2015 -0700 +++ b/tests/test_baking_baker.py Sun Mar 29 23:08:37 2015 -0700 @@ -3,7 +3,6 @@ import pytest from piecrust.baking.baker import PageBaker, Baker from piecrust.baking.records import BakeRecord -from piecrust.routing import Route from .mockutil import get_mock_app, mock_fs, mock_fs_scope @@ -75,6 +74,7 @@ '2010': {'01': {'01': {'post1.html': 'post one'}}}, 'index.html': 'something'} + def test_removed(): fs = (mock_fs() .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page') @@ -97,6 +97,7 @@ assert structure == { 'index.html': 'something'} + def test_record_version_change(): fs = (mock_fs() .withPage('pages/foo.md', {'layout': 'none', 'format': 'none'}, 'a foo page')) @@ -122,3 +123,64 @@ finally: BakeRecord.RECORD_VERSION -= 1 + +def test_bake_tags(): + tags = [ + ['foo'], + ['bar', 'whatever'], + ['foo', 'bar']] + + def config_factory(i): + c = {'title': 'Post %d' % (i + 1)} + c['tags'] = tags[i] + return c + + fs = (mock_fs() + .withPages(3, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', + config_factory) + .withPage('pages/_tag.md', {'layout': 'none', 'format': 'none'}, + "Pages in {{tag}}\n" + "{%for p in pagination.posts -%}\n" + "{{p.title}}\n" + "{%endfor%}")) + with mock_fs_scope(fs): + out_dir = fs.path('kitchen/_counter') + app = fs.getApp() + baker = Baker(app, out_dir) + baker.bake() + + s = fs.getStructure('kitchen/_counter/tag') + assert s['foo.html'] == "Pages in foo\nPost 3\nPost 1\n" + assert s['bar.html'] == "Pages in bar\nPost 3\nPost 2\n" + assert s['whatever.html'] == "Pages in whatever\nPost 2\n" + + +def test_bake_categories(): + categories = [ + 'foo', 'bar', 'foo'] + + def config_factory(i): + c = {'title': 'Post %d' % (i + 1)} + c['category'] = categories[i] + return c + + fs = (mock_fs() + .withConfig({'site': {'category_url': 'cat/%category%'}}) + .withPages(3, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', + config_factory) + .withPage('pages/_category.md', {'layout': 'none', 'format': 'none'}, + "Pages in {{category}}\n" + "{%for p in pagination.posts -%}\n" + "{{p.title}}\n" + "{%endfor%}")) + with mock_fs_scope(fs): + out_dir = fs.path('kitchen/_counter') + app = fs.getApp() + baker = Baker(app, out_dir) + baker.bake() + + print(fs.getStructure('kitchen/_counter').keys()) + s = fs.getStructure('kitchen/_counter/cat') + assert s['foo.html'] == "Pages in foo\nPost 3\nPost 1\n" + assert s['bar.html'] == "Pages in bar\nPost 2\n" +