# HG changeset patch # User Ludovic Chabant # Date 1427577974 25200 # Node ID 59d65654184e76cad15398f8d73a019dc69c7d7b # Parent edcc9dc17b371b98c4f26958e7613b34df37a45d tests: Add a blog data provider test. diff -r edcc9dc17b37 -r 59d65654184e tests/test_data_provider.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_data_provider.py Sat Mar 28 14:26:14 2015 -0700 @@ -0,0 +1,25 @@ +from piecrust.rendering import PageRenderingContext, render_page +from .mockutil import mock_fs, mock_fs_scope + + +def test_blog_provider(): + fs = (mock_fs() + .withPage('posts/2015-03-01_one.md', + {'title': 'One', 'category': 'Foo'}) + .withPage('posts/2015-03-02_two.md', + {'title': 'Two', 'category': 'Foo'}) + .withPage('posts/2015-03-03_three.md', + {'title': 'Three', 'category': 'Bar'}) + .withPage('pages/categories.md', + {'format': 'none', 'layout': 'none'}, + "{%for c in blog.categories%}\n" + "{{c.name}} ({{c.post_count}})\n" + "{%endfor%}\n")) + with mock_fs_scope(fs): + app = fs.getApp() + page = app.getSource('pages').getPage({'slug': 'categories'}) + ctx = PageRenderingContext(page, '/categories') + rp = render_page(ctx) + expected = "\nBar (1)\n\nFoo (2)\n" + assert rp.content == expected +