-
Notifications
You must be signed in to change notification settings - Fork 300
support nested structures #776
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
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
314ea5a
support nested structures
01e399d
Merge pull request #1 from django-json-api/master
bpleshakov aa0d7b9
Merge remote-tracking branch 'origin/master' into patch-3
49c479e
f code style
0b099c2
f ignore deprecation warning
5ddcf69
f cover settings file with test
5a9f1e5
f add changelog
db139e0
+ tests for relations strategy
cf31527
f codestyle
387500a
f included
9071b4f
f wrong check
ab9a1ae
f tests
65f9b15
f pep
67442ab
f rewrite complex drf errors structures into JSON-API format
177bfbc
f move DeprecationWarning from settings to metaclass, which ensures t…
fdc8166
f pep8
72df66f
requested changes
874bd9c
Merge master
873b48e
f unused import
82d2002
Merge branch 'master' into patch-3
bpleshakov f5f68d4
f remove error handling part
deec195
Update CHANGELOG.md
sliverc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from __future__ import absolute_import | ||
|
||
import pytest | ||
from django.utils import timezone | ||
from rest_framework.reverse import reverse | ||
|
||
from rest_framework_json_api.settings import JSONAPISettings | ||
from . import TestBase | ||
from example.models import Author, Blog, Comment, Entry | ||
from django.test import override_settings | ||
|
||
|
||
class TestRenderingStrategy(TestBase): | ||
list_url = reverse('authors-nested-list') | ||
|
||
def setUp(self): | ||
super(TestRenderingStrategy, self).setUp() | ||
self.blog = Blog.objects.create(name='Some Blog', tagline="It's a blog") | ||
self.entry = Entry.objects.create( | ||
blog=self.blog, | ||
headline='headline', | ||
body_text='body_text', | ||
pub_date=timezone.now(), | ||
mod_date=timezone.now(), | ||
n_comments=0, | ||
n_pingbacks=0, | ||
rating=3 | ||
) | ||
for i in range(1, 6): | ||
name = 'some_author{}'.format(i) | ||
self.entry.authors.add( | ||
Author.objects.create(name=name, email='{}@example.org'.format(name)) | ||
) | ||
|
||
self.comment = Comment.objects.create( | ||
entry=self.entry, | ||
body='testing one two three', | ||
author=Author.objects.first() | ||
) | ||
|
||
def test_attribute_rendering_strategy(self): | ||
with override_settings(JSON_API_NESTED_SERIALIZERS_RENDERING_STRATEGY='ATTRIBUTE'): | ||
response = self.client.get(self.list_url) | ||
|
||
expected = { | ||
"links": { | ||
"first": "http://testserver/authors-nested?page%5Bnumber%5D=1", | ||
"last": "http://testserver/authors-nested?page%5Bnumber%5D=5", | ||
"next": "http://testserver/authors-nested?page%5Bnumber%5D=2", | ||
"prev": None | ||
}, | ||
"data": [ | ||
{ | ||
"type": "authors", | ||
"id": "1", | ||
"attributes": { | ||
"name": "some_author1", | ||
"email": "[email protected]", | ||
"comments": [ | ||
{ | ||
"id": 1, | ||
"entry": { | ||
"tags": [], | ||
"url": "http://testserver/drf-blogs/1" | ||
}, | ||
"body": "testing one two three" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"meta": { | ||
"pagination": { | ||
"page": 1, | ||
"pages": 5, | ||
"count": 5 | ||
} | ||
} | ||
} | ||
assert expected == response.json() | ||
|
||
|
||
class TestRenderingStrategySettings(TestBase): | ||
|
||
def test_deprecation(self): | ||
with pytest.deprecated_call(): | ||
JSONAPISettings() | ||
|
||
def test_invalid_strategy(self): | ||
class Settings: | ||
JSON_API_NESTED_SERIALIZERS_RENDERING_STRATEGY = 'SOME_INVALID_STRATEGY' | ||
with pytest.raises(AttributeError): | ||
JSONAPISettings(user_settings=Settings()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE=example.settings.test | ||
filterwarnings = | ||
error::DeprecationWarning | ||
error::PendingDeprecationWarning | ||
ignore::DeprecationWarning | ||
bpleshakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ignore::PendingDeprecationWarning |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.