comparison tests/test_serving.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 d8c28e496bb3
children b45322924d18
comparison
equal deleted inserted replaced
368:2408eb6f4da8 369:4b1019bb2533
2 import pytest 2 import pytest
3 import mock 3 import mock
4 from piecrust.data.filters import ( 4 from piecrust.data.filters import (
5 PaginationFilter, HasFilterClause, IsFilterClause, 5 PaginationFilter, HasFilterClause, IsFilterClause,
6 page_value_accessor) 6 page_value_accessor)
7 from piecrust.rendering import PageRenderingContext, render_page 7 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page
8 from piecrust.serving import find_routes 8 from piecrust.serving import find_routes
9 from piecrust.sources.base import REALM_USER, REALM_THEME 9 from piecrust.sources.base import REALM_USER, REALM_THEME
10 from .mockutil import mock_fs, mock_fs_scope 10 from .mockutil import mock_fs, mock_fs_scope
11 11
12 12
72 "{%for p in pagination.posts -%}\n" 72 "{%for p in pagination.posts -%}\n"
73 "{{p.title}}\n" 73 "{{p.title}}\n"
74 "{%endfor%}")) 74 "{%endfor%}"))
75 with mock_fs_scope(fs): 75 with mock_fs_scope(fs):
76 app = fs.getApp() 76 app = fs.getApp()
77 page = app.getSource('pages').getPage({'slug': '_tag'}) 77 page = app.getSource('pages').getPage({'slug': '_tag', 'tag': tag})
78 route = app.getTaxonomyRoute('tags', 'posts')
79 route_metadata = {'slug': '_tag', 'tag': tag}
78 taxonomy = app.getTaxonomy('tags') 80 taxonomy = app.getTaxonomy('tags')
79 81
80 ctx = PageRenderingContext(page, '/tag/' + tag) 82 qp = QualifiedPage(page, route, route_metadata)
83 ctx = PageRenderingContext(qp)
81 ctx.setTaxonomyFilter(taxonomy, tag) 84 ctx.setTaxonomyFilter(taxonomy, tag)
82 rp = render_page(ctx) 85 rp = render_page(ctx)
83 86
84 expected = "Pages in %s\n" % tag 87 expected = "Pages in %s\n" % tag
85 if expected_indices: 88 if expected_indices:
113 "{%for p in pagination.posts -%}\n" 116 "{%for p in pagination.posts -%}\n"
114 "{{p.title}}\n" 117 "{{p.title}}\n"
115 "{%endfor%}")) 118 "{%endfor%}"))
116 with mock_fs_scope(fs): 119 with mock_fs_scope(fs):
117 app = fs.getApp() 120 app = fs.getApp()
118 page = app.getSource('pages').getPage({'slug': '_category'}) 121 page = app.getSource('pages').getPage({'slug': '_category',
122 'category': category})
123 route = app.getTaxonomyRoute('categories', 'posts')
124 route_metadata = {'slug': '_category', 'category': category}
119 taxonomy = app.getTaxonomy('categories') 125 taxonomy = app.getTaxonomy('categories')
120 126
121 ctx = PageRenderingContext(page, '/' + category) 127 qp = QualifiedPage(page, route, route_metadata)
128 ctx = PageRenderingContext(qp)
122 ctx.setTaxonomyFilter(taxonomy, category) 129 ctx.setTaxonomyFilter(taxonomy, category)
123 rp = render_page(ctx) 130 rp = render_page(ctx)
124 131
125 expected = "Pages in %s\n" % category 132 expected = "Pages in %s\n" % category
126 if expected_indices: 133 if expected_indices: