comparison tests/test_serving.py @ 711:ab5c6a8ae90a

bake: Replace hard-coded taxonomy support with "generator" system. * Taxonomies are now implemented one or more `TaxonomyGenerator`s. * A `BlogArchivesGenerator` stub is there but non-functional.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 26 May 2016 19:52:47 -0700
parents f987b29d6fab
children 606f6d57b5df
comparison
equal deleted inserted replaced
710:e85f29b28b84 711:ab5c6a8ae90a
74 "{{p.title}}\n" 74 "{{p.title}}\n"
75 "{%endfor%}")) 75 "{%endfor%}"))
76 with mock_fs_scope(fs): 76 with mock_fs_scope(fs):
77 app = fs.getApp() 77 app = fs.getApp()
78 page = app.getSource('pages').getPage({'slug': '_tag', 'tag': tag}) 78 page = app.getSource('pages').getPage({'slug': '_tag', 'tag': tag})
79 route = app.getTaxonomyRoute('tags', 'posts') 79 route = app.getGeneratorRoute('posts_tags')
80 assert route is not None
81
80 route_metadata = {'slug': '_tag', 'tag': tag} 82 route_metadata = {'slug': '_tag', 'tag': tag}
81
82 qp = QualifiedPage(page, route, route_metadata) 83 qp = QualifiedPage(page, route, route_metadata)
83 ctx = PageRenderingContext(qp) 84 ctx = PageRenderingContext(qp)
84 ctx.setTaxonomyFilter(tag) 85 route.generator.prepareRenderContext(ctx)
85 rp = render_page(ctx) 86 rp = render_page(ctx)
86 87
87 expected = "Pages in %s\n" % tag 88 expected = "Pages in %s\n" % tag
88 if expected_indices: 89 if expected_indices:
89 for i in reversed(expected_indices): 90 for i in reversed(expected_indices):
107 if categories[i]: 108 if categories[i]:
108 c['category'] = categories[i] 109 c['category'] = categories[i]
109 return c 110 return c
110 111
111 fs = (mock_fs() 112 fs = (mock_fs()
112 .withConfig() 113 .withConfig({
114 'site': {
115 'taxonomies': {
116 'categories': {'term': 'category'}
117 }
118 }
119 })
113 .withPages(6, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', 120 .withPages(6, 'posts/2015-03-{idx1:02}_post{idx1:02}.md',
114 config_factory) 121 config_factory)
115 .withPage('pages/_category.md', {'layout': 'none', 'format': 'none'}, 122 .withPage('pages/_category.md', {'layout': 'none', 'format': 'none'},
116 "Pages in {{category}}\n" 123 "Pages in {{category}}\n"
117 "{%for p in pagination.posts -%}\n" 124 "{%for p in pagination.posts -%}\n"
119 "{%endfor%}")) 126 "{%endfor%}"))
120 with mock_fs_scope(fs): 127 with mock_fs_scope(fs):
121 app = fs.getApp() 128 app = fs.getApp()
122 page = app.getSource('pages').getPage({'slug': '_category', 129 page = app.getSource('pages').getPage({'slug': '_category',
123 'category': category}) 130 'category': category})
124 route = app.getTaxonomyRoute('categories', 'posts') 131 route = app.getGeneratorRoute('posts_categories')
132 assert route is not None
133
125 route_metadata = {'slug': '_category', 'category': category} 134 route_metadata = {'slug': '_category', 'category': category}
126
127 qp = QualifiedPage(page, route, route_metadata) 135 qp = QualifiedPage(page, route, route_metadata)
128 ctx = PageRenderingContext(qp) 136 ctx = PageRenderingContext(qp)
129 ctx.setTaxonomyFilter(category) 137 route.generator.prepareRenderContext(ctx)
130 rp = render_page(ctx) 138 rp = render_page(ctx)
131 139
132 expected = "Pages in %s\n" % category 140 expected = "Pages in %s\n" % category
133 if expected_indices: 141 if expected_indices:
134 for i in reversed(expected_indices): 142 for i in reversed(expected_indices):