a1d23f0e2bc29596f8c2775306d6d45613c7504f
[django-pagination.git] / pagination / tests.py
1 """
2 >>> from django.core.paginator import Paginator
3 >>> from pagination.templatetags.pagination_tags import paginate
4 >>> from django.template import Template, Context
5
6 >>> p = Paginator(range(15), 2)
7 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
8 [1, 2, 3, 4, 5, 6, 7, 8]
9
10 >>> p = Paginator(range(17), 2)
11 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
12 [1, 2, 3, 4, 5, 6, 7, 8, 9]
13
14 >>> p = Paginator(range(19), 2)
15 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
16 [1, 2, 3, 4, None, 7, 8, 9, 10]
17
18 >>> p = Paginator(range(21), 2)
19 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
20 [1, 2, 3, 4, None, 8, 9, 10, 11]
21
22 >>> t = Template("{% load pagination_tags %}{% autopaginate var 2 %}{% paginate %}")
23
24 # WARNING: Please, please nobody read this portion of the code!
25 >>> class GetProxy(object):
26 ...     def __iter__(self): yield self.__dict__.__iter__
27 ...     def copy(self): return self
28 ...     def urlencode(self): return u''
29 >>> class RequestProxy(object):
30 ...     page = 1
31 ...     GET = GetProxy()
32 >>>
33 # ENDWARNING
34
35 >>> t.render(Context({'var': range(21), 'request': RequestProxy()}))
36 u'\\n<div class="pagination">...
37 >>>
38 >>> t = Template("{% load pagination_tags %}{% autopaginate var %}{% paginate %}")
39 >>> t.render(Context({'var': range(21), 'request': RequestProxy()}))
40 u'\\n<div class="pagination">...
41 >>>
42 """