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
224bc027
Commit
224bc027
authored
Sep 28, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for generic views
parent
08533165
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
4 deletions
+55
-4
rest_framework/tests/generics.py
+53
-3
rest_framework/views.py
+2
-1
No files found.
rest_framework/tests/generics.py
View file @
224bc027
...
...
@@ -9,10 +9,16 @@ factory = RequestFactory()
class
RootView
(
generics
.
RootAPIView
):
"""
Example description for OPTIONS.
"""
model
=
BasicModel
class
InstanceView
(
generics
.
InstanceAPIView
):
"""
Example description for OPTIONS.
"""
model
=
BasicModel
...
...
@@ -60,7 +66,7 @@ class TestRootView(TestCase):
request
=
factory
.
put
(
'/'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
self
.
assertEquals
(
response
.
content
,
'{"detail": "Method
\'
PUT
\'
not allowed."}'
)
self
.
assertEquals
(
response
.
data
,
{
"detail"
:
"Method 'PUT' not allowed."
}
)
def
test_delete_root_view
(
self
):
"""
...
...
@@ -69,7 +75,29 @@ class TestRootView(TestCase):
request
=
factory
.
delete
(
'/'
)
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
self
.
assertEquals
(
response
.
content
,
'{"detail": "Method
\'
DELETE
\'
not allowed."}'
)
self
.
assertEquals
(
response
.
data
,
{
"detail"
:
"Method 'DELETE' not allowed."
})
def
test_options_root_view
(
self
):
"""
OPTIONS requests to RootAPIView should return metadata
"""
request
=
factory
.
options
(
'/'
)
response
=
self
.
view
(
request
)
.
render
()
expected
=
{
'parses'
:
[
'application/json'
,
'application/x-www-form-urlencoded'
,
'multipart/form-data'
],
'renders'
:
[
'application/json'
,
'text/html'
],
'name'
:
'Root'
,
'description'
:
'Example description for OPTIONS.'
}
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
data
,
expected
)
class
TestInstanceView
(
TestCase
):
...
...
@@ -104,7 +132,7 @@ class TestInstanceView(TestCase):
request
=
factory
.
post
(
'/'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
self
.
assertEquals
(
response
.
content
,
'{"detail": "Method
\'
POST
\'
not allowed."}'
)
self
.
assertEquals
(
response
.
data
,
{
"detail"
:
"Method 'POST' not allowed."
}
)
def
test_put_instance_view
(
self
):
"""
...
...
@@ -128,3 +156,25 @@ class TestInstanceView(TestCase):
self
.
assertEquals
(
response
.
content
,
''
)
ids
=
[
obj
.
id
for
obj
in
self
.
objects
.
all
()]
self
.
assertEquals
(
ids
,
[
2
,
3
])
def
test_options_instance_view
(
self
):
"""
OPTIONS requests to InstanceAPIView should return metadata
"""
request
=
factory
.
options
(
'/'
)
response
=
self
.
view
(
request
)
.
render
()
expected
=
{
'parses'
:
[
'application/json'
,
'application/x-www-form-urlencoded'
,
'multipart/form-data'
],
'renders'
:
[
'application/json'
,
'text/html'
],
'name'
:
'Instance'
,
'description'
:
'Example description for OPTIONS.'
}
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
data
,
expected
)
rest_framework/views.py
View file @
224bc027
...
...
@@ -39,7 +39,8 @@ def _remove_leading_indent(content):
# unindent the content if needed
if
whitespace_counts
:
whitespace_pattern
=
'^'
+
(
' '
*
min
(
whitespace_counts
))
return
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
content
=
re
.
sub
(
re
.
compile
(
whitespace_pattern
,
re
.
MULTILINE
),
''
,
content
)
content
=
content
.
strip
(
'
\n
'
)
return
content
...
...
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