comparison tests/test_data_paginator.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 498a917cd2d4
children 72f17534d58e
comparison
equal deleted inserted replaced
368:2408eb6f4da8 369:4b1019bb2533
1 import math 1 import math
2 import mock
2 import pytest 3 import pytest
3 from piecrust.data.paginator import Paginator 4 from piecrust.data.paginator import Paginator
4 from piecrust.sources.interfaces import IPaginationSource 5 from piecrust.sources.interfaces import IPaginationSource
5 6
6 7
42 ('blog', 2, 8), 43 ('blog', 2, 8),
43 ('blog', 2, 14), 44 ('blog', 2, 14),
44 ('blog', 3, 14) 45 ('blog', 3, 14)
45 ]) 46 ])
46 def test_paginator(uri, page_num, count): 47 def test_paginator(uri, page_num, count):
47 def _mock_get_uri(index): 48 def _get_mock_uri(sub_num):
48 res = uri 49 res = uri
49 if index > 1: 50 if sub_num > 1:
50 if res != '' and not res.endswith('/'): 51 if res != '' and not res.endswith('/'):
51 res += '/' 52 res += '/'
52 res += '%d' % index 53 res += '%d' % sub_num
53 return res 54 return res
54 55
55 source = MockSource(count) 56 source = MockSource(count)
56 p = Paginator(None, source, page_num) 57 p = Paginator(None, source, page_num=page_num)
57 p._getPageUri = _mock_get_uri 58 p._getPageUri = _get_mock_uri
58 59
59 if count <= 5: 60 if count <= 5:
60 # All posts fit on the page 61 # All posts fit on the page
61 assert p.prev_page_number is None 62 assert p.prev_page_number is None
62 assert p.prev_page is None 63 assert p.prev_page is None