annotate tests/test_sources_posts.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 cb6eadea0845
children e7b865f8f335
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import os
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import pytest
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 from .mockutil import mock_fs, mock_fs_scope
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 @pytest.mark.parametrize('fs, src_type, expected_paths, expected_metadata', [
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 (mock_fs(), 'flat', [], []),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 (mock_fs().withPage('test/2014-01-01_foo.md'),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 'flat',
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 ['2014-01-01_foo.md'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 [(2014, 1, 1, 'foo')]),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 (mock_fs(), 'shallow', [], []),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 (mock_fs().withPage('test/2014/01-01_foo.md'),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 'shallow',
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 ['2014/01-01_foo.md'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 [(2014, 1, 1, 'foo')]),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 (mock_fs(), 'hierarchy', [], []),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 (mock_fs().withPage('test/2014/01/01_foo.md'),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 'hierarchy',
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 ['2014/01/01_foo.md'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 [(2014, 1, 1, 'foo')]),
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 ])
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 def test_post_source_factories(fs, src_type, expected_paths, expected_metadata):
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 fs.withConfig({
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 'site': {
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 'sources': {
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 'test': {'type': 'posts/%s' % src_type}},
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 'routes': [
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 {'url': '/%slug%', 'source': 'test'}]
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 }
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 })
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 fs.withDir('kitchen/test')
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 with mock_fs_scope(fs):
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 app = fs.getApp(cache=False)
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 s = app.getSource('test')
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 facs = list(s.buildPageFactories())
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 paths = [f.rel_path for f in facs]
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 assert paths == expected_paths
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 metadata = [
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 (f.metadata['year'], f.metadata['month'],
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 f.metadata['day'], f.metadata['slug'])
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 for f in facs]
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 assert metadata == expected_metadata
cb6eadea0845 Fixed a bug with the `shallow` source. Add unit tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44