comparison tests/mockutil.py @ 369:4b1019bb2533

serve: Giant refactor to change how we handle data when serving pages. * We need a distinction between source metadata and route metadata. In most cases they're the same, but in cases like taxonomy pages, route metadata contains more things that can't be in source metadata if we want to re-use cached pages. * Create a new `QualifiedPage` type which is a page with a specific route and route metadata. Pass this around in many places. * Instead of passing an URL around, use the route in the `QualifiedPage` to generate URLs. This is better since it removes the guess-work from trying to generate URLs for sub-pages. * Deep-copy app and page configurations before passing them around to things that could modify them, like data builders and such. * Exclude taxonomy pages from iterator data providers. * Properly nest iterator data providers for when the theme and user page sources are merged inside `site.pages`.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 03 May 2015 18:47:10 -0700
parents c484e1ec9150
children 65db6df28120
comparison
equal deleted inserted replaced
368:2408eb6f4da8 369:4b1019bb2533
6 import os.path 6 import os.path
7 import mock 7 import mock
8 import yaml 8 import yaml
9 from piecrust.app import PieCrust, PieCrustConfiguration 9 from piecrust.app import PieCrust, PieCrustConfiguration
10 from piecrust.page import Page 10 from piecrust.page import Page
11 from piecrust.rendering import PageRenderingContext, render_page 11 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page
12 12
13 13
14 resources_path = os.path.abspath( 14 resources_path = os.path.abspath(
15 os.path.join( 15 os.path.join(
16 os.path.dirname(__file__), 16 os.path.dirname(__file__),
23 return app 23 return app
24 24
25 25
26 def get_simple_page(app, rel_path): 26 def get_simple_page(app, rel_path):
27 source = app.getSource('pages') 27 source = app.getSource('pages')
28 metadata = {'path': os.path.splitext(rel_path)[0]} 28 metadata = {'slug': os.path.splitext(rel_path)[0]}
29 return Page(source, metadata, rel_path) 29 return Page(source, metadata, rel_path)
30 30
31 31
32 def render_simple_page(page, uri): 32 def render_simple_page(page, route, route_metadata):
33 ctx = PageRenderingContext(page, uri) 33 qp = QualifiedPage(page, route, route_metadata)
34 ctx = PageRenderingContext(qp)
34 rp = render_page(ctx) 35 rp = render_page(ctx)
35 return rp.content 36 return rp.content
36 37
37 38
38 class _MockFsEntry(object): 39 class _MockFsEntry(object):