Mercurial > piecrust2
comparison tests/test_data_provider.py @ 974:72f17534d58e
tests: First pass on making unit tests work again.
- Fix all imports
- Add more helper functions to work with mock file-systems
- Simplify some code by running chef directly on the mock FS
- Fix a couple tests
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 17 Oct 2017 01:07:30 -0700 |
parents | ab5c6a8ae90a |
children |
comparison
equal
deleted
inserted
replaced
973:8419daaa7a0e | 974:72f17534d58e |
---|---|
1 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page | |
2 from .mockutil import mock_fs, mock_fs_scope | 1 from .mockutil import mock_fs, mock_fs_scope |
2 from .rdrutil import render_simple_page | |
3 | 3 |
4 | 4 |
5 def test_blog_provider(): | 5 def test_blog_provider(): |
6 fs = (mock_fs() | 6 fs = (mock_fs() |
7 .withConfig() | 7 .withConfig() |
16 "{%for c in blog.tags%}\n" | 16 "{%for c in blog.tags%}\n" |
17 "{{c.name}} ({{c.post_count}})\n" | 17 "{{c.name}} ({{c.post_count}})\n" |
18 "{%endfor%}\n")) | 18 "{%endfor%}\n")) |
19 with mock_fs_scope(fs): | 19 with mock_fs_scope(fs): |
20 app = fs.getApp() | 20 app = fs.getApp() |
21 page = app.getSource('pages').getPage({'slug': 'tags'}) | 21 page = app.getSimplePage('tags.md') |
22 route = app.getSourceRoute('pages', None) | 22 actual = render_simple_page(page) |
23 route_metadata = {'slug': 'tags'} | |
24 qp = QualifiedPage(page, route, route_metadata) | |
25 ctx = PageRenderingContext(qp) | |
26 rp = render_page(ctx) | |
27 expected = "\nBar (1)\n\nFoo (2)\n" | 23 expected = "\nBar (1)\n\nFoo (2)\n" |
28 assert rp.content == expected | 24 assert actual == expected |
29 | 25 |