diff 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
line wrap: on
line diff
--- a/tests/test_serving.py	Sun May 03 18:43:28 2015 -0700
+++ b/tests/test_serving.py	Sun May 03 18:47:10 2015 -0700
@@ -4,7 +4,7 @@
 from piecrust.data.filters import (
         PaginationFilter, HasFilterClause, IsFilterClause,
         page_value_accessor)
-from piecrust.rendering import PageRenderingContext, render_page
+from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page
 from piecrust.serving import find_routes
 from piecrust.sources.base import REALM_USER, REALM_THEME
 from .mockutil import mock_fs, mock_fs_scope
@@ -74,10 +74,13 @@
                     "{%endfor%}"))
     with mock_fs_scope(fs):
         app = fs.getApp()
-        page = app.getSource('pages').getPage({'slug': '_tag'})
+        page = app.getSource('pages').getPage({'slug': '_tag', 'tag': tag})
+        route = app.getTaxonomyRoute('tags', 'posts')
+        route_metadata = {'slug': '_tag', 'tag': tag}
         taxonomy = app.getTaxonomy('tags')
 
-        ctx = PageRenderingContext(page, '/tag/' + tag)
+        qp = QualifiedPage(page, route, route_metadata)
+        ctx = PageRenderingContext(qp)
         ctx.setTaxonomyFilter(taxonomy, tag)
         rp = render_page(ctx)
 
@@ -115,10 +118,14 @@
                     "{%endfor%}"))
     with mock_fs_scope(fs):
         app = fs.getApp()
-        page = app.getSource('pages').getPage({'slug': '_category'})
+        page = app.getSource('pages').getPage({'slug': '_category',
+                                               'category': category})
+        route = app.getTaxonomyRoute('categories', 'posts')
+        route_metadata = {'slug': '_category', 'category': category}
         taxonomy = app.getTaxonomy('categories')
 
-        ctx = PageRenderingContext(page, '/' + category)
+        qp = QualifiedPage(page, route, route_metadata)
+        ctx = PageRenderingContext(qp)
         ctx.setTaxonomyFilter(taxonomy, category)
         rp = render_page(ctx)