diff options
| author | Simon Pantzare | 2012-12-13 17:57:27 +0100 | 
|---|---|---|
| committer | Tom Christie | 2012-12-14 19:59:29 +0000 | 
| commit | 9eaf8e4330e0c6a4485dba650481a2578a3979b4 (patch) | |
| tree | 455850416eccf05b81c467e6f7ed2d83caba8ad6 /rest_framework | |
| parent | 50f4612404ca8dc3f5a2812a5788101ef2a4d77d (diff) | |
| download | django-rest-framework-9eaf8e4330e0c6a4485dba650481a2578a3979b4.tar.bz2 | |
Test to verify that context is passed on
The paginator and its object serializer should share the same context.
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/tests/pagination.py | 14 | 
1 files changed, 13 insertions, 1 deletions
diff --git a/rest_framework/tests/pagination.py b/rest_framework/tests/pagination.py index 3062007d..7bc23f1d 100644 --- a/rest_framework/tests/pagination.py +++ b/rest_framework/tests/pagination.py @@ -4,7 +4,7 @@ from django.core.paginator import Paginator  from django.test import TestCase  from django.test.client import RequestFactory  from django.utils import unittest -from rest_framework import generics, status, pagination, filters +from rest_framework import generics, status, pagination, filters, serializers  from rest_framework.compat import django_filters  from rest_framework.tests.models import BasicModel, FilterableItem @@ -148,6 +148,12 @@ class IntegrationTestPaginationAndFiltering(TestCase):          self.assertEquals(response.data['previous'], None) +class PassOnContextPaginationSerializer(pagination.PaginationSerializer): + +    class Meta: +        object_serializer_class = serializers.Serializer + +  class UnitTestPagination(TestCase):      """      Unit tests for pagination of primitive objects. @@ -172,6 +178,12 @@ class UnitTestPagination(TestCase):          self.assertEquals(serializer.data['previous'], '?page=2')          self.assertEquals(serializer.data['results'], self.objects[20:]) +    def test_context_available_in_result(self): +        serializer = PassOnContextPaginationSerializer(self.first_page) +        results = serializer.fields[serializer.results_field] +        # assertIs is available in Python 2.7 +        self.assertTrue(serializer.context is results.context) +  class TestUnpaginated(TestCase):      """  | 
