view tests/test_data_provider.py @ 363:dd25bd3ce1f9

serve: Refactoring and fixes to be able to serve taxonomy pages. * Page sources' `findPagePath` is renamed to `findPageFactory`, so that it also returns source metadata. * Page refs now store possible hits more properly, and use the previous point to also store metadata. As a result, they can also return a proper factory. * Implement `findPageFactory` correctly in all built-in sources. * When the Chef server matches a taxonomy page, get the source metadata from the page ref in order to make a more proper page. * Make the `getRoute(s)` functions explicitely say if they want taxonomy routes or not.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Apr 2015 15:07:40 -0700
parents 59d65654184e
children 4b1019bb2533
line wrap: on
line source

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