aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/tests/pagination.py
diff options
context:
space:
mode:
authorTom Christie2012-10-01 15:49:19 +0100
committerTom Christie2012-10-01 15:49:19 +0100
commitb16fb5777168246b1e217640b818a82eb6e2141b (patch)
treed45a059c40ee2be8c77f6da0c7092a1a57a00ad1 /rest_framework/tests/pagination.py
parent6fa589fefd48d98e4f0a11548b6c3e5ced58e31e (diff)
downloaddjango-rest-framework-b16fb5777168246b1e217640b818a82eb6e2141b.tar.bz2
Expand pagination support, add docs
Diffstat (limited to 'rest_framework/tests/pagination.py')
-rw-r--r--rest_framework/tests/pagination.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/rest_framework/tests/pagination.py b/rest_framework/tests/pagination.py
index 4ddfc915..9e424cc5 100644
--- a/rest_framework/tests/pagination.py
+++ b/rest_framework/tests/pagination.py
@@ -1,6 +1,7 @@
+from django.core.paginator import Paginator
from django.test import TestCase
from django.test.client import RequestFactory
-from rest_framework import generics, status
+from rest_framework import generics, status, pagination
from rest_framework.tests.models import BasicModel
factory = RequestFactory()
@@ -14,7 +15,11 @@ class RootView(generics.RootAPIView):
paginate_by = 10
-class TestPaginatedView(TestCase):
+class IntegrationTestPagination(TestCase):
+ """
+ Integration tests for paginated list views.
+ """
+
def setUp(self):
"""
Create 26 BasicModel intances.
@@ -55,3 +60,28 @@ class TestPaginatedView(TestCase):
self.assertEquals(response.data['results'], self.data[20:])
self.assertEquals(response.data['next'], None)
self.assertNotEquals(response.data['previous'], None)
+
+
+class UnitTestPagination(TestCase):
+ """
+ Unit tests for pagination of primative objects.
+ """
+
+ def setUp(self):
+ self.objects = [char * 3 for char in 'abcdefghijklmnopqrstuvwxyz']
+ paginator = Paginator(self.objects, 10)
+ self.first_page = paginator.page(1)
+ self.last_page = paginator.page(3)
+
+ def test_native_pagination(self):
+ serializer = pagination.PaginationSerializer(instance=self.first_page)
+ self.assertEquals(serializer.data['count'], 26)
+ self.assertEquals(serializer.data['next'], '?page=2')
+ self.assertEquals(serializer.data['previous'], None)
+ self.assertEquals(serializer.data['results'], self.objects[:10])
+
+ serializer = pagination.PaginationSerializer(instance=self.last_page)
+ self.assertEquals(serializer.data['count'], 26)
+ self.assertEquals(serializer.data['next'], None)
+ self.assertEquals(serializer.data['previous'], '?page=2')
+ self.assertEquals(serializer.data['results'], self.objects[20:])