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
e677f3ee
Commit
e677f3ee
authored
Aug 13, 2013
by
Krzysztof Jurewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PATCH requests should not be able to create objects.
parent
999056cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
rest_framework/mixins.py
+8
-5
rest_framework/tests/test_generics.py
+11
-0
No files found.
rest_framework/mixins.py
View file @
e677f3ee
...
@@ -142,11 +142,14 @@ class UpdateModelMixin(object):
...
@@ -142,11 +142,14 @@ class UpdateModelMixin(object):
try
:
try
:
return
self
.
get_object
()
return
self
.
get_object
()
except
Http404
:
except
Http404
:
# If this is a PUT-as-create operation, we need to ensure that
if
self
.
request
.
method
==
'PUT'
:
# we have relevant permissions, as if this was a POST request.
# For PUT-as-create operation, we need to ensure that we have
# This will either raise a PermissionDenied exception,
# relevant permissions, as if this was a POST request. This
# or simply return None
# will either raise a PermissionDenied exception, or simply
self
.
check_permissions
(
clone_request
(
self
.
request
,
'POST'
))
# return None.
self
.
check_permissions
(
clone_request
(
self
.
request
,
'POST'
))
else
:
raise
def
pre_save
(
self
,
obj
):
def
pre_save
(
self
,
obj
):
"""
"""
...
...
rest_framework/tests/test_generics.py
View file @
e677f3ee
...
@@ -338,6 +338,17 @@ class TestInstanceView(TestCase):
...
@@ -338,6 +338,17 @@ class TestInstanceView(TestCase):
new_obj
=
SlugBasedModel
.
objects
.
get
(
slug
=
'test_slug'
)
new_obj
=
SlugBasedModel
.
objects
.
get
(
slug
=
'test_slug'
)
self
.
assertEqual
(
new_obj
.
text
,
'foobar'
)
self
.
assertEqual
(
new_obj
.
text
,
'foobar'
)
def
test_patch_cannot_create_an_object
(
self
):
"""
PATCH requests should not be able to create objects.
"""
data
=
{
'text'
:
'foobar'
}
request
=
factory
.
patch
(
'/999'
,
data
,
format
=
'json'
)
with
self
.
assertNumQueries
(
1
):
response
=
self
.
view
(
request
,
pk
=
999
)
.
render
()
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
self
.
assertFalse
(
self
.
objects
.
filter
(
id
=
999
)
.
exists
())
class
TestOverriddenGetObject
(
TestCase
):
class
TestOverriddenGetObject
(
TestCase
):
"""
"""
...
...
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