mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-17 03:51:03 +03:00
Merge branch 'master' of https://github.com/tomchristie/django-rest-framework
This commit is contained in:
commit
f54fc3a76b
|
@ -160,6 +160,7 @@ The following people have helped make REST framework great.
|
|||
* Christopher Paolini - [chrispaolini]
|
||||
* Filipe A Ximenes - [filipeximenes]
|
||||
* Ramiro Morales - [ramiro]
|
||||
* Krzysztof Jurewicz - [krzysiekj]
|
||||
|
||||
Many thanks to everyone who's contributed to the project.
|
||||
|
||||
|
@ -356,3 +357,4 @@ You can also contact [@_tomchristie][twitter] directly on twitter.
|
|||
[chrispaolini]: https://github.com/chrispaolini
|
||||
[filipeximenes]: https://github.com/filipeximenes
|
||||
[ramiro]: https://github.com/ramiro
|
||||
[krzysiekj]: https://github.com/krzysiekj
|
||||
|
|
|
@ -142,11 +142,16 @@ class UpdateModelMixin(object):
|
|||
try:
|
||||
return self.get_object()
|
||||
except Http404:
|
||||
# If this is a PUT-as-create operation, we need to ensure that
|
||||
# we have relevant permissions, as if this was a POST request.
|
||||
# This will either raise a PermissionDenied exception,
|
||||
# or simply return None
|
||||
self.check_permissions(clone_request(self.request, 'POST'))
|
||||
if self.request.method == 'PUT':
|
||||
# For PUT-as-create operation, we need to ensure that we have
|
||||
# relevant permissions, as if this was a POST request. This
|
||||
# will either raise a PermissionDenied exception, or simply
|
||||
# return None.
|
||||
self.check_permissions(clone_request(self.request, 'POST'))
|
||||
else:
|
||||
# PATCH requests where the object does not exist should still
|
||||
# return a 404 response.
|
||||
raise
|
||||
|
||||
def pre_save(self, obj):
|
||||
"""
|
||||
|
|
|
@ -338,6 +338,17 @@ class TestInstanceView(TestCase):
|
|||
new_obj = SlugBasedModel.objects.get(slug='test_slug')
|
||||
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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user