Mercurial > piecrust2
comparison tests/mockutil.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 | fd694f1297c7 |
children | 8adc27285d93 |
comparison
equal
deleted
inserted
replaced
973:8419daaa7a0e | 974:72f17534d58e |
---|---|
1 import os.path | |
2 import mock | 1 import mock |
3 from piecrust.app import PieCrust, PieCrustConfiguration | 2 from piecrust.app import PieCrust |
4 from piecrust.page import Page | 3 from piecrust.appconfig import PieCrustConfiguration |
5 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page | |
6 | 4 |
7 | 5 |
8 def get_mock_app(config=None): | 6 def get_mock_app(config=None): |
9 app = mock.MagicMock(spec=PieCrust) | 7 app = mock.MagicMock(spec=PieCrust) |
10 app.config = PieCrustConfiguration(values={}) | 8 app.config = PieCrustConfiguration(values={}) |
11 return app | 9 return app |
12 | 10 |
13 | 11 |
14 def get_simple_page(app, rel_path): | 12 def get_simple_content_item(app, slug): |
15 source = app.getSource('pages') | 13 src = app.getSource('pages') |
16 metadata = {'slug': os.path.splitext(rel_path)[0]} | 14 assert src is not None |
17 return Page(source, metadata, rel_path) | 15 |
16 item = src.findContent({'slug': slug}) | |
17 assert item is not None | |
18 return item | |
18 | 19 |
19 | 20 |
20 def render_simple_page(page, route, route_metadata): | 21 def get_simple_page(app, slug): |
21 qp = QualifiedPage(page, route, route_metadata) | 22 src = app.getSource('pages') |
22 ctx = PageRenderingContext(qp) | 23 item = get_simple_content_item(app, slug) |
23 rp = render_page(ctx) | 24 return app.getPage(src, item) |
24 return rp.content | |
25 | 25 |
26 | 26 |
27 from .tmpfs import ( | 27 from .tmpfs import ( # NOQA |
28 TempDirFileSystem as mock_fs, | 28 TempDirFileSystem as mock_fs, |
29 TempDirScope as mock_fs_scope) | 29 TempDirScope as mock_fs_scope) |
30 |