diff options
| author | Tom Christie | 2013-08-27 20:58:30 +0100 | 
|---|---|---|
| committer | Tom Christie | 2013-08-27 20:58:30 +0100 | 
| commit | e1b54f2a2a078b3f1f9ba67f216d127b8182b100 (patch) | |
| tree | 24563d2badbe0bf3df2b84bc211bc1f4894a0572 /rest_framework/tests | |
| parent | ea6eee304c230a9277fdc76f4ac91654e0019b7a (diff) | |
| parent | 7fb3f078f0973acc1d108d8c617b26b6845599f7 (diff) | |
| download | django-rest-framework-e1b54f2a2a078b3f1f9ba67f216d127b8182b100.tar.bz2 | |
Merge branch 'max_paginate_by' of git://github.com/alexander-akhmetov/django-rest-framework into alexander-akhmetov-max_paginate_by
Diffstat (limited to 'rest_framework/tests')
| -rw-r--r-- | rest_framework/tests/test_pagination.py | 46 | 
1 files changed, 46 insertions, 0 deletions
diff --git a/rest_framework/tests/test_pagination.py b/rest_framework/tests/test_pagination.py index 85d4640e..cbed1604 100644 --- a/rest_framework/tests/test_pagination.py +++ b/rest_framework/tests/test_pagination.py @@ -42,6 +42,16 @@ class PaginateByParamView(generics.ListAPIView):      paginate_by_param = 'page_size' +class MaxPaginateByView(generics.ListAPIView): +    """ +    View for testing custom max_paginate_by usage +    """ +    model = BasicModel +    paginate_by = 5 +    max_paginate_by = 3 +    paginate_by_param = 'page_size' + +  class IntegrationTestPagination(TestCase):      """      Integration tests for paginated list views. @@ -313,6 +323,42 @@ class TestCustomPaginateByParam(TestCase):          self.assertEqual(response.data['results'], self.data[:5]) +class TestMaxPaginateByParam(TestCase): +    """ +    Tests for list views with max_paginate_by kwarg +    """ + +    def setUp(self): +        """ +        Create 13 BasicModel instances. +        """ +        for i in range(13): +            BasicModel(text=i).save() +        self.objects = BasicModel.objects +        self.data = [ +            {'id': obj.id, 'text': obj.text} +            for obj in self.objects.all() +        ] +        self.view = MaxPaginateByView.as_view() + +    def test_max_paginate_by(self): +        """ +        If max_paginate_by is set and it less than paginate_by, new kwarg should limit requests for review. +        """ +        request = factory.get('/?page_size=10') +        response = self.view(request).render() +        self.assertEqual(response.data['count'], 13) +        self.assertEqual(response.data['results'], self.data[:3]) + +    def test_max_paginate_by_without_page_size_param(self): +        """ +        If max_paginate_by is set, new kwarg should limit requests for review. +        """ +        request = factory.get('/') +        response = self.view(request).render() +        self.assertEqual(response.data['results'], self.data[:3]) + +  ### Tests for context in pagination serializers  class CustomField(serializers.Field):  | 
