forked from inveniosoftware-attic/invenio-utils
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_utils_pagination.py
More file actions
65 lines (55 loc) · 2.13 KB
/
test_utils_pagination.py
File metadata and controls
65 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2013, 2015 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
Test unit for the miscutil/paginationutils module.
"""
from invenio_utils.pagination import Pagination
from invenio.testsuite import make_test_suite, run_test_suite, InvenioTestCase
class TestPaginationUtils(InvenioTestCase):
"""
PaginationUtils TestSuite.
"""
def test_first_page(self):
page = 1
per_page = 10
total_count = 98
pagination = Pagination(page, per_page, total_count)
self.assertFalse(pagination.has_prev)
self.assertTrue(pagination.has_next)
self.assertEqual(list(pagination.iter_pages()), [1, 2, 3, None, 10])
def test_last_page(self):
page = 10
per_page = 10
total_count = 98
pagination = Pagination(page, per_page, total_count)
self.assertTrue(pagination.has_prev)
self.assertFalse(pagination.has_next)
self.assertEqual(list(pagination.iter_pages()), [1, None, 9, 10])
def test_middle_page(self):
page = 5
per_page = 10
total_count = 98
pagination = Pagination(page, per_page, total_count)
self.assertTrue(pagination.has_prev)
self.assertTrue(pagination.has_next)
self.assertEqual(list(pagination.iter_pages()),
[1, None, 4, 5, 6, 7, None, 10])
TEST_SUITE = make_test_suite(TestPaginationUtils,)
if __name__ == "__main__":
run_test_suite(TEST_SUITE)