mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-03-26 21:04:27 +03:00
Add test to ensure that pk is readonly in PUT requests
This commit is contained in:
parent
ab173fd8f9
commit
f010a9553e
|
@ -191,3 +191,15 @@ class TestInstanceView(TestCase):
|
||||||
}
|
}
|
||||||
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEquals(response.data, expected)
|
self.assertEquals(response.data, expected)
|
||||||
|
|
||||||
|
def test_put_cannot_set_id(self):
|
||||||
|
"""
|
||||||
|
POST requests to create a new object should not be able to set the id.
|
||||||
|
"""
|
||||||
|
content = {'id': 999, 'text': 'foobar'}
|
||||||
|
request = factory.put('/1', json.dumps(content), content_type='application/json')
|
||||||
|
response = self.view(request, pk=1).render()
|
||||||
|
self.assertEquals(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEquals(response.data, {'id': 1, 'text': 'foobar'})
|
||||||
|
updated = self.objects.get(id=1)
|
||||||
|
self.assertEquals(updated.text, 'foobar')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user