From: Stephen Finucane Date: Sat, 19 Nov 2016 14:02:28 +0000 (+0000) Subject: tests: Add rudimentary pagination tests X-Git-Tag: v2.0.0-rc1~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed5e93242b9774b16da0a37232325d526c8dfdbd;p=thirdparty%2Fpatchwork.git tests: Add rudimentary pagination tests This should improve coverage and prevent regressions. The 'ppp' header is removed as this is a non-standard header and not accessible from a browser. Signed-off-by: Stephen Finucane --- diff --git a/patchwork/paginator.py b/patchwork/paginator.py index 3da2cd0f..526a3285 100644 --- a/patchwork/paginator.py +++ b/patchwork/paginator.py @@ -45,13 +45,6 @@ class Paginator(paginator.Paginator): if request.user.is_authenticated(): items_per_page = request.user.profile.items_per_page - ppp = request.META.get('ppp') - if ppp: - try: - items_per_page = int(ppp) - except ValueError: - pass - super(Paginator, self).__init__(objects, items_per_page) try: diff --git a/patchwork/templates/patchwork/pagination.html b/patchwork/templates/patchwork/pagination.html index b8b76b39..04f4d166 100644 --- a/patchwork/templates/patchwork/pagination.html +++ b/patchwork/templates/patchwork/pagination.html @@ -9,14 +9,14 @@ {% else %} « {% endif %} - + {% if page.paginator.trailing_set %} {% for p in page.paginator.trailing_set %} {{ p }} {% endfor %} ... {% endif %} - + {% for p in page.paginator.adjacent_set %} {% ifequal p page.number %} {{ p }} @@ -25,14 +25,14 @@ title="Page {{ p }}">{{ p }} {% endifequal %} {% endfor %} - + {% if page.paginator.leading_set %} … {% for p in page.paginator.leading_set %} {{ p }} {% endfor %} {% endif %} - + {% if page.has_next %} » {% endif %} - + {% endifnotequal %} diff --git a/patchwork/tests/test_paginator.py b/patchwork/tests/test_paginator.py new file mode 100644 index 00000000..b25ae1fc --- /dev/null +++ b/patchwork/tests/test_paginator.py @@ -0,0 +1,72 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2016 Stephen Finucane +# +# This file is part of the Patchwork package. +# +# Patchwork 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. +# +# Patchwork 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 Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from django.core.urlresolvers import reverse +from django.test import TestCase + +from patchwork.tests.utils import create_patches +from patchwork.tests.utils import create_project +from patchwork.tests.utils import create_user + +ITEMS_PER_PAGE = 1 + + +class PaginatorTest(TestCase): + + def setUp(self): + self.user = create_user() + self.user.profile.items_per_page = ITEMS_PER_PAGE + self.user.profile.save() + self.project = create_project() + self.patches = create_patches(10, project=self.project) + + def _get_patches(self, params): + return self.client.get( + reverse('patch-list', kwargs={ + 'project_id': self.project.linkname}), + params) + + def test_items_per_page(self): + response = self._get_patches({}) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context['page'].object_list), + len(self.patches)) + + self.client.force_login(self.user) + response = self._get_patches({}) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context['page'].object_list), + ITEMS_PER_PAGE) + + def test_page_valid(self): + page = 2 + self.client.force_login(self.user) + + for page_ in [2, str(2)]: + response = self._get_patches({'page': page_}) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['page'].object_list[0].id, + self.patches[-page].id) + + def test_page_invalid(self): + self.client.force_login(self.user) + response = self._get_patches({'page': 'foo'}) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['page'].object_list[0].id, + self.patches[-1].id)