]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Add rudimentary pagination tests
authorStephen Finucane <stephen@that.guru>
Sat, 19 Nov 2016 14:02:28 +0000 (14:02 +0000)
committerStephen Finucane <stephen@that.guru>
Sun, 18 Dec 2016 22:41:59 +0000 (22:41 +0000)
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>
patchwork/paginator.py
patchwork/templates/patchwork/pagination.html
patchwork/tests/test_paginator.py [new file with mode: 0644]

index 3da2cd0f25adcf3b2d8c41db4a0f52966bf95353..526a3285c417091e6c52477fb97ed82150fcce11 100644 (file)
@@ -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:
index b8b76b398aa05b4b30ffc77f45ea2defdcbcebb4..04f4d16671c20dfd120845097069e051271d7e54 100644 (file)
@@ -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>
      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 (file)
index 0000000..b25ae1f
--- /dev/null
@@ -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)