mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-30 14:03:44 +03:00
Add custom pagination test that covers case with custom object serializer class
This commit is contained in:
parent
b40525d8e6
commit
deb19272b7
|
@ -412,6 +412,15 @@ class CustomPaginationSerializer(pagination.BasePaginationSerializer):
|
||||||
results_field = 'objects'
|
results_field = 'objects'
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFooSerializer(serializers.Serializer):
|
||||||
|
foo = serializers.CharField()
|
||||||
|
|
||||||
|
|
||||||
|
class CustomFooPaginationSerializer(pagination.PaginationSerializer):
|
||||||
|
class Meta:
|
||||||
|
object_serializer_class = CustomFooSerializer
|
||||||
|
|
||||||
|
|
||||||
class TestCustomPaginationSerializer(TestCase):
|
class TestCustomPaginationSerializer(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
objects = ['john', 'paul', 'george', 'ringo']
|
objects = ['john', 'paul', 'george', 'ringo']
|
||||||
|
@ -434,6 +443,16 @@ class TestCustomPaginationSerializer(TestCase):
|
||||||
}
|
}
|
||||||
self.assertEqual(serializer.data, expected)
|
self.assertEqual(serializer.data, expected)
|
||||||
|
|
||||||
|
def test_custom_pagination_serializer_with_custom_object_serializer(self):
|
||||||
|
objects = [
|
||||||
|
{'foo': 'bar'},
|
||||||
|
{'foo': 'spam'}
|
||||||
|
]
|
||||||
|
paginator = Paginator(objects, 1)
|
||||||
|
page = paginator.page(1)
|
||||||
|
serializer = CustomFooPaginationSerializer(page)
|
||||||
|
serializer.data
|
||||||
|
|
||||||
|
|
||||||
class NonIntegerPage(object):
|
class NonIntegerPage(object):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user