Skip to content

Relationship deletion #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
16 changes: 16 additions & 0 deletions example/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ def test_delete_to_one_relationship_should_fail(self):
response = self.client.delete(url, data=json.dumps(request_data), content_type='application/vnd.api+json')
assert response.status_code == 405, response.content.decode()

def test_delete_relationship_overriding_with_none(self):
url = '/comments/{}'.format(self.second_comment.id)
request_data = {
'data': {
'type': 'comments',
'relationships': {
'author': {
'data': None
}
}
}
}
response = self.client.patch(url, data=json.dumps(request_data), content_type='application/vnd.api+json')
assert response.status_code == 200, response.content.decode()
assert response.data['author'] == None

def test_delete_to_many_relationship_with_no_change(self):
url = '/entries/{}/relationships/comment_set'.format(self.first_entry.id)
request_data = {
Expand Down
3 changes: 2 additions & 1 deletion example/urls_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls import include, url
from rest_framework import routers

from example.views import BlogViewSet, EntryViewSet, AuthorViewSet, EntryRelationshipView, BlogRelationshipView, \
from example.views import BlogViewSet, EntryViewSet, AuthorViewSet, CommentViewSet, EntryRelationshipView, BlogRelationshipView, \
CommentRelationshipView, AuthorRelationshipView
from .api.resources.identity import Identity, GenericIdentity

Expand All @@ -10,6 +10,7 @@
router.register(r'blogs', BlogViewSet)
router.register(r'entries', EntryViewSet)
router.register(r'authors', AuthorViewSet)
router.register(r'comments', CommentViewSet)

# for the old tests
router.register(r'identities', Identity)
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def parse_relationships(data):
parsed_relationships = dict()
for field_name, field_data in relationships.items():
field_data = field_data.get('data')
if isinstance(field_data, dict):
if isinstance(field_data, dict) or field_data is None:
parsed_relationships[field_name] = field_data
elif isinstance(field_data, list):
parsed_relationships[field_name] = list(relation for relation in field_data)
Expand Down