Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
4d43e9f7
Commit
4d43e9f7
authored
Jan 26, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test for custom pagination serializers. Also refs #604.
parent
a51bca32
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
rest_framework/tests/pagination.py
+39
-0
No files found.
rest_framework/tests/pagination.py
View file @
4d43e9f7
...
...
@@ -252,6 +252,8 @@ class TestCustomPaginateByParam(TestCase):
self
.
assertEquals
(
response
.
data
[
'results'
],
self
.
data
[:
5
])
### Tests for context in pagination serializers
class
CustomField
(
serializers
.
Field
):
def
to_native
(
self
,
value
):
if
not
'view'
in
self
.
context
:
...
...
@@ -283,3 +285,40 @@ class TestContextPassedToCustomField(TestCase):
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
### Tests for custom pagination serializers
class
LinksSerializer
(
serializers
.
Serializer
):
next
=
pagination
.
NextPageField
(
source
=
'*'
)
prev
=
pagination
.
PreviousPageField
(
source
=
'*'
)
class
CustomPaginationSerializer
(
pagination
.
BasePaginationSerializer
):
links
=
LinksSerializer
(
source
=
'*'
)
# Takes the page object as the source
total_results
=
serializers
.
Field
(
source
=
'paginator.count'
)
results_field
=
'objects'
class
TestCustomPaginationSerializer
(
TestCase
):
def
setUp
(
self
):
objects
=
[
'john'
,
'paul'
,
'george'
,
'ringo'
]
paginator
=
Paginator
(
objects
,
2
)
self
.
page
=
paginator
.
page
(
1
)
def
test_custom_pagination_serializer
(
self
):
request
=
RequestFactory
()
.
get
(
'/foobar'
)
serializer
=
CustomPaginationSerializer
(
instance
=
self
.
page
,
context
=
{
'request'
:
request
}
)
expected
=
{
'links'
:
{
'next'
:
'http://testserver/foobar?page=2'
,
'prev'
:
None
},
'total_results'
:
4
,
'objects'
:
[
'john'
,
'paul'
]
}
self
.
assertEquals
(
serializer
.
data
,
expected
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment