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
8136a94e
Commit
8136a94e
authored
Jul 19, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert pagination stuff
This reverts commit
d1af0496
.
parent
d1af0496
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 additions
and
124 deletions
+1
-124
djangorestframework/tests/mixins.py
+1
-124
No files found.
djangorestframework/tests/mixins.py
View file @
8136a94e
"""Tests for the status module"""
from
django.test
import
TestCase
from
django.utils
import
simplejson
as
json
from
djangorestframework
import
status
from
djangorestframework.compat
import
RequestFactory
from
django.contrib.auth.models
import
Group
,
User
from
djangorestframework.mixins
import
CreateModelMixin
,
PaginatorMixin
from
djangorestframework.mixins
import
CreateModelMixin
from
djangorestframework.resources
import
ModelResource
from
djangorestframework.response
import
Response
from
djangorestframework.tests.models
import
CustomUser
from
djangorestframework.views
import
View
class
TestModelCreation
(
TestCase
):
...
...
@@ -112,125 +109,5 @@ class TestModelCreation(TestCase):
self
.
assertEquals
(
2
,
response
.
cleaned_content
.
groups
.
count
())
self
.
assertEquals
(
'foo1'
,
response
.
cleaned_content
.
groups
.
all
()[
0
]
.
name
)
self
.
assertEquals
(
'foo2'
,
response
.
cleaned_content
.
groups
.
all
()[
1
]
.
name
)
class
MockPaginatorView
(
PaginatorMixin
,
View
):
total
=
60
def
get
(
self
,
request
):
return
range
(
0
,
self
.
total
)
def
post
(
self
,
request
):
return
Response
(
status
.
CREATED
,
{
'status'
:
'OK'
})
class
TestPagination
(
TestCase
):
def
setUp
(
self
):
self
.
req
=
RequestFactory
()
def
test_default_limit
(
self
):
""" Tests if pagination works without overwriting the limit """
request
=
self
.
req
.
get
(
'/paginator'
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertEqual
(
MockPaginatorView
.
total
,
content
[
'total'
])
self
.
assertEqual
(
MockPaginatorView
.
limit
,
content
[
'per_page'
])
self
.
assertEqual
(
range
(
0
,
MockPaginatorView
.
limit
),
content
[
'results'
])
def
test_overwriting_limit
(
self
):
""" Tests if the limit can be overwritten """
limit
=
10
request
=
self
.
req
.
get
(
'/paginator'
)
response
=
MockPaginatorView
.
as_view
(
limit
=
limit
)(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertEqual
(
content
[
'per_page'
],
limit
)
self
.
assertEqual
(
range
(
0
,
limit
),
content
[
'results'
])
def
test_limit_param
(
self
):
""" Tests if the client can set the limit """
from
math
import
ceil
limit
=
5
num_pages
=
int
(
ceil
(
MockPaginatorView
.
total
/
float
(
limit
)))
request
=
self
.
req
.
get
(
'/paginator/?limit=
%
d'
%
limit
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertEqual
(
MockPaginatorView
.
total
,
content
[
'total'
])
self
.
assertEqual
(
limit
,
content
[
'per_page'
])
self
.
assertEqual
(
num_pages
,
content
[
'pages'
])
def
test_exceeding_limit
(
self
):
""" Makes sure the client cannot exceed the default limit """
from
math
import
ceil
limit
=
MockPaginatorView
.
limit
+
10
num_pages
=
int
(
ceil
(
MockPaginatorView
.
total
/
float
(
limit
)))
request
=
self
.
req
.
get
(
'/paginator/?limit=
%
d'
%
limit
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertEqual
(
MockPaginatorView
.
total
,
content
[
'total'
])
self
.
assertNotEqual
(
limit
,
content
[
'per_page'
])
self
.
assertNotEqual
(
num_pages
,
content
[
'pages'
])
self
.
assertEqual
(
MockPaginatorView
.
limit
,
content
[
'per_page'
])
def
test_only_works_for_get
(
self
):
""" Pagination should only work for GET requests """
request
=
self
.
req
.
post
(
'/paginator'
,
data
=
{
'content'
:
'spam'
})
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
CREATED
)
self
.
assertEqual
(
None
,
content
.
get
(
'per_page'
))
self
.
assertEqual
(
'OK'
,
content
[
'status'
])
def
test_non_int_page
(
self
):
""" Tests that it can handle invalid values """
request
=
self
.
req
.
get
(
'/paginator/?page=spam'
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
NOT_FOUND
)
def
test_page_range
(
self
):
""" Tests that the page range is handle correctly """
request
=
self
.
req
.
get
(
'/paginator/?page=0'
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
NOT_FOUND
)
request
=
self
.
req
.
get
(
'/paginator/'
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertEqual
(
range
(
0
,
MockPaginatorView
.
limit
),
content
[
'results'
])
num_pages
=
content
[
'pages'
]
request
=
self
.
req
.
get
(
'/paginator/?page=
%
d'
%
num_pages
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertEqual
(
range
(
MockPaginatorView
.
limit
*
(
num_pages
-
1
),
MockPaginatorView
.
total
),
content
[
'results'
])
request
=
self
.
req
.
get
(
'/paginator/?page=
%
d'
%
(
num_pages
+
1
,))
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
NOT_FOUND
)
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