Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions example/tests/test_model_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,25 @@ def test_key_in_detail_result(self):

assert expected_dump == content_dump

def test_patch_requires_id(self):
"""
Verify that 'id' is required to be passed in an update request.
"""
data = {
'data': {
'type': 'users',
'attributes': {
'first-name': 'DifferentName'
}
}
}

response = self.client.patch(self.detail_url,
content_type='application/vnd.api+json',
data=dump_json(data))

self.assertEqual(response.status_code, 400)

def test_key_in_post(self):
"""
Ensure a key is in the post.
Expand Down
1 change: 1 addition & 0 deletions example/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_delete_relationship_overriding_with_none(self):
request_data = {
'data': {
'type': 'comments',
'id': self.second_comment.id,
'relationships': {
'author': {
'data': None
Expand Down
2 changes: 2 additions & 0 deletions rest_framework_json_api/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def parse(self, stream, media_type=None, parser_context=None):
resource_type=resource_name
)
)
if not data.get('id') and request.method in ('PATCH', 'PUT'):
raise ParseError("The resource identifier object must contain an 'id' member")

# Construct the return data
parsed_data = {'id': data.get('id')}
Expand Down