changeset 321:59d65654184e

tests: Add a blog data provider test.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 28 Mar 2015 14:26:14 -0700
parents edcc9dc17b37
children 7544c03b6bab
files tests/test_data_provider.py
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
+