summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Finucane <stephen@that.guru>2016-11-19 14:02:28 +0000
committerStephen Finucane <stephen@that.guru>2016-12-18 22:41:59 +0000
commited5e93242b9774b16da0a37232325d526c8dfdbd (patch)
tree6edfbd8702097db42a823740d130e33a25a5d216
parenta5f17c49e0b264590061280d307e297fadacbfc7 (diff)
downloadpatchwork-ed5e93242b9774b16da0a37232325d526c8dfdbd.tar
patchwork-ed5e93242b9774b16da0a37232325d526c8dfdbd.tar.gz
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 <stephen@that.guru>
-rw-r--r--patchwork/paginator.py7
-rw-r--r--patchwork/templates/patchwork/pagination.html10
-rw-r--r--patchwork/tests/test_paginator.py72
3 files changed, 77 insertions, 12 deletions
diff --git a/patchwork/paginator.py b/patchwork/paginator.py
index 3da2cd0..526a328 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 b8b76b3..04f4d16 100644
--- a/patchwork/templates/patchwork/pagination.html
+++ b/patchwork/templates/patchwork/pagination.html
@@ -9,14 +9,14 @@
{% else %}
<span class="prev-na">&laquo;</span>
{% endif %}
-
+
{% if page.paginator.trailing_set %}
{% for p in page.paginator.trailing_set %}
<span class="page"><a href="{% listurl page=p %}" >{{ p }}</a></span>
{% endfor %}
...
{% endif %}
-
+
{% for p in page.paginator.adjacent_set %}
{% ifequal p page.number %}
<span class="curr" title="Current Page">{{ p }}</span>
@@ -25,14 +25,14 @@
title="Page {{ p }}">{{ p }}</a></span>
{% endifequal %}
{% endfor %}
-
+
{% if page.paginator.leading_set %}
{% for p in page.paginator.leading_set %}
<span class="page"><a href="{% listurl page=p %}">{{ p }}</a></span>
{% endfor %}
{% endif %}
-
+
{% if page.has_next %}
<span class="next">
<a href="{% listurl page=page.next_page_number %}"
@@ -41,5 +41,5 @@
{% else %}
<span class="next-na">&raquo;</span>
{% endif %}
-</div>
+</div>
{% endifnotequal %}
diff --git a/patchwork/tests/test_paginator.py b/patchwork/tests/test_paginator.py
new file mode 100644
index 0000000..b25ae1f
--- /dev/null
+++ b/patchwork/tests/test_paginator.py
@@ -0,0 +1,72 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2016 Stephen Finucane <stephen@that.guru>
+#
+# 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)