Mercurial > piecrust2
annotate tests/test_data_provider.py @ 415:0e9a94b7fdfa
bake: Improve bake record information.
* Store things in the bake record that require less interaction between the
master process and the workers. For instance, don't store the paginator
object in the render pass info -- instead, just store whether pagination
was used, and whether it had more items.
* Simplify information passing between workers and bake passes by saving the
rendering info to the JSON cache. This means the "render first sub" job
doesn't have to return anything except errors now.
* Add more performance counter info.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 20 Jun 2015 19:23:16 -0700 |
parents | 4b1019bb2533 |
children | f987b29d6fab |
rev | line source |
---|---|
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
321
diff
changeset
|
1 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page |
321
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 from .mockutil import mock_fs, mock_fs_scope |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 def test_blog_provider(): |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 fs = (mock_fs() |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 .withPage('posts/2015-03-01_one.md', |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 {'title': 'One', 'category': 'Foo'}) |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 .withPage('posts/2015-03-02_two.md', |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 {'title': 'Two', 'category': 'Foo'}) |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 .withPage('posts/2015-03-03_three.md', |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 {'title': 'Three', 'category': 'Bar'}) |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 .withPage('pages/categories.md', |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 {'format': 'none', 'layout': 'none'}, |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 "{%for c in blog.categories%}\n" |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 "{{c.name}} ({{c.post_count}})\n" |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 "{%endfor%}\n")) |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 with mock_fs_scope(fs): |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 app = fs.getApp() |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 page = app.getSource('pages').getPage({'slug': 'categories'}) |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
321
diff
changeset
|
21 route = app.getRoute('pages', None) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
321
diff
changeset
|
22 route_metadata = {'slug': 'categories'} |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
321
diff
changeset
|
23 qp = QualifiedPage(page, route, route_metadata) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
321
diff
changeset
|
24 ctx = PageRenderingContext(qp) |
321
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 rp = render_page(ctx) |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 expected = "\nBar (1)\n\nFoo (2)\n" |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 assert rp.content == expected |
59d65654184e
tests: Add a blog data provider test.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 |