Mercurial > piecrust2
annotate tests/test_serving.py @ 411:e7b865f8f335
bake: Enable multiprocess baking.
Baking is now done by running a worker per CPU, and sending jobs to them.
This changes several things across the codebase:
* Ability to not cache things related to pages other than the 'main' page
(i.e. the page at the bottom of the execution stack).
* Decouple the baking process from the bake records, so only the main process
keeps track (and modifies) the bake record.
* Remove the need for 'batch page getters' and loading a page directly from
the page factories.
There are various smaller changes too included here, including support for
scope performance timers that are saved with the bake record and can be
printed out to the console. Yes I got carried away.
For testing, the in-memory 'mock' file-system doesn't work anymore, since
we're spawning processes, so this is replaced by a 'tmpfs' file-system which
is saved in temporary files on disk and deleted after tests have run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 12 Jun 2015 17:09:19 -0700 |
parents | b45322924d18 |
children | 16e705c58cae |
rev | line source |
---|---|
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import re |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import pytest |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 import mock |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
4 from piecrust.data.filters import ( |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
5 PaginationFilter, HasFilterClause, IsFilterClause, |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
6 page_value_accessor) |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
7 from piecrust.rendering import QualifiedPage, PageRenderingContext, render_page |
377
b45322924d18
tests: Fix serving unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
369
diff
changeset
|
8 from piecrust.serving.server import find_routes |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 from piecrust.sources.base import REALM_USER, REALM_THEME |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
10 from .mockutil import mock_fs, mock_fs_scope |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 @pytest.mark.parametrize('uri, route_specs, expected', |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 [ |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 ('/', |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 [{'src': 'pages', 'pat': '(?P<path>.*)'}], |
332 | 17 [('pages', {'path': '/'})]), |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 ('/', |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 [{'src': 'pages', 'pat': '(?P<path>.*)'}, |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
20 {'src': 'theme', 'pat': '(?P<path>.*)', 'realm': REALM_THEME}], |
332 | 21 [('pages', {'path': '/'}), ('theme', {'path': '/'})]) |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
22 ]) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
23 def test_find_routes(uri, route_specs, expected): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
24 routes = [] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
25 for rs in route_specs: |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
26 m = mock.Mock() |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
27 m.source_name = rs['src'] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
28 m.source_realm = rs.setdefault('realm', REALM_USER) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
29 m.uri_re = re.compile(rs['pat']) |
176
d47d9493bb0a
routes: When matching URIs, return metadata directly instead of the match object.
Ludovic Chabant <ludovic@chabant.com>
parents:
175
diff
changeset
|
30 m.matchUri = lambda u: m.uri_re.match(u).groupdict() |
3
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
31 routes.append(m) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
32 matching = find_routes(routes, uri) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
33 |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
34 assert len(matching) == len(expected) |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
35 for i in range(len(matching)): |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
36 route, metadata = matching[i] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
37 exp_source, exp_md = expected[i] |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
38 assert route.source_name == exp_source |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
39 assert metadata == exp_md |
f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
40 |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
41 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
42 @pytest.mark.parametrize( |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
43 'tag, expected_indices', |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
44 [ |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
45 ('foo', [1, 2, 4, 5, 6]), |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
46 ('bar', [2, 3, 4, 6, 8]), |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
47 ('whatever', [5, 8]), |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
48 ('unique', [7]), |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
49 ('missing', None) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
50 ]) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
51 def test_serve_tag_page(tag, expected_indices): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
52 tags = [ |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
53 ['foo'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
54 ['foo', 'bar'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
55 ['bar'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
56 ['bar', 'foo'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
57 ['foo', 'whatever'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
58 ['foo', 'bar'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
59 ['unique'], |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
60 ['whatever', 'bar']] |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
61 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
62 def config_factory(i): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
63 c = {'title': 'Post %d' % (i + 1)} |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
64 c['tags'] = list(tags[i]) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
65 return c |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
66 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
67 fs = (mock_fs() |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
68 .withPages(8, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
69 config_factory) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
70 .withPage('pages/_tag.md', {'layout': 'none', 'format': 'none'}, |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
71 "Pages in {{tag}}\n" |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
72 "{%for p in pagination.posts -%}\n" |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
73 "{{p.title}}\n" |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
74 "{%endfor%}")) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
75 with mock_fs_scope(fs): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
76 app = fs.getApp() |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
77 page = app.getSource('pages').getPage({'slug': '_tag', 'tag': tag}) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
78 route = app.getTaxonomyRoute('tags', 'posts') |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
79 route_metadata = {'slug': '_tag', 'tag': tag} |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
80 taxonomy = app.getTaxonomy('tags') |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
81 |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
82 qp = QualifiedPage(page, route, route_metadata) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
83 ctx = PageRenderingContext(qp) |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
84 ctx.setTaxonomyFilter(taxonomy, tag) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
85 rp = render_page(ctx) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
86 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
87 expected = "Pages in %s\n" % tag |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
88 if expected_indices: |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
89 for i in reversed(expected_indices): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
90 expected += "Post %d\n" % i |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
91 assert expected == rp.content |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
92 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
93 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
94 @pytest.mark.parametrize( |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
95 'category, expected_indices', |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
96 [ |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
97 ('foo', [1, 2, 4]), |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
98 ('bar', [3, 6]), |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
99 ('missing', None) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
100 ]) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
101 def test_serve_category_page(category, expected_indices): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
102 categories = [ |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
103 'foo', 'foo', 'bar', 'foo', None, 'bar'] |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
104 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
105 def config_factory(i): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
106 c = {'title': 'Post %d' % (i + 1)} |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
107 if categories[i]: |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
108 c['category'] = categories[i] |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
109 return c |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
110 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
111 fs = (mock_fs() |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
112 .withPages(6, 'posts/2015-03-{idx1:02}_post{idx1:02}.md', |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
113 config_factory) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
114 .withPage('pages/_category.md', {'layout': 'none', 'format': 'none'}, |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
115 "Pages in {{category}}\n" |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
116 "{%for p in pagination.posts -%}\n" |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
117 "{{p.title}}\n" |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
118 "{%endfor%}")) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
119 with mock_fs_scope(fs): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
120 app = fs.getApp() |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
121 page = app.getSource('pages').getPage({'slug': '_category', |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
122 'category': category}) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
123 route = app.getTaxonomyRoute('categories', 'posts') |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
124 route_metadata = {'slug': '_category', 'category': category} |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
125 taxonomy = app.getTaxonomy('categories') |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
126 |
369
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
127 qp = QualifiedPage(page, route, route_metadata) |
4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
Ludovic Chabant <ludovic@chabant.com>
parents:
332
diff
changeset
|
128 ctx = PageRenderingContext(qp) |
324
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
129 ctx.setTaxonomyFilter(taxonomy, category) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
130 rp = render_page(ctx) |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
131 |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
132 expected = "Pages in %s\n" % category |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
133 if expected_indices: |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
134 for i in reversed(expected_indices): |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
135 expected += "Post %d\n" % i |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
136 assert expected == rp.content |
65e6d72f3877
bake/serve: Fix how taxonomy index pages are setup and rendered.
Ludovic Chabant <ludovic@chabant.com>
parents:
176
diff
changeset
|
137 |