-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:django-json-api/django-rest-fram…
…ework-json-api
- Loading branch information
Showing
12 changed files
with
127 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ var/ | |
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
.eggs/ | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
This file contains 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 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 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,31 @@ | ||
""" | ||
Test rest_framework_json_api's utils functions. | ||
""" | ||
from rest_framework_json_api import utils | ||
|
||
from ..serializers import EntrySerializer | ||
from ..tests import TestBase | ||
|
||
|
||
class GetRelatedResourceTests(TestBase): | ||
""" | ||
Ensure the `get_related_resource_type` function returns correct types. | ||
""" | ||
|
||
def test_reverse_relation(self): | ||
""" | ||
Ensure reverse foreign keys have their types identified correctly. | ||
""" | ||
serializer = EntrySerializer() | ||
field = serializer.fields['comments'] | ||
|
||
self.assertEqual(utils.get_related_resource_type(field), 'comments') | ||
|
||
def test_m2m_relation(self): | ||
""" | ||
Ensure m2ms have their types identified correctly. | ||
""" | ||
serializer = EntrySerializer() | ||
field = serializer.fields['authors'] | ||
|
||
self.assertEqual(utils.get_related_resource_type(field), 'authors') |
This file contains 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,45 @@ | ||
from example.models import Entry, Comment | ||
from rest_framework_json_api import serializers, views | ||
from rest_framework_json_api.renderers import JSONRenderer | ||
|
||
|
||
# serializers | ||
class RelatedModelSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Comment | ||
fields = ('id',) | ||
|
||
|
||
class DummyTestSerializer(serializers.ModelSerializer): | ||
''' | ||
This serializer is a simple compound document serializer which includes only | ||
a single embedded relation | ||
''' | ||
related_models = RelatedModelSerializer( | ||
source='comment_set', many=True, read_only=True) | ||
|
||
class Meta: | ||
model = Entry | ||
fields = ('related_models',) | ||
|
||
class JSONAPIMeta: | ||
included_resources = ('related_models',) | ||
|
||
|
||
# views | ||
class DummyTestViewSet(views.ModelViewSet): | ||
queryset = Entry.objects.all() | ||
serializer_class = DummyTestSerializer | ||
|
||
|
||
def test_simple_reverse_relation_included_renderer(): | ||
''' | ||
Test renderer when a single reverse fk relation is passed. | ||
''' | ||
serializer = DummyTestSerializer(instance=Entry()) | ||
renderer = JSONRenderer() | ||
rendered = renderer.render( | ||
serializer.data, | ||
renderer_context={'view': DummyTestViewSet()}) | ||
|
||
assert rendered |
This file contains 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 @@ | ||
-e . | ||
pytest==2.8.2 | ||
pytest>=2.9.0,<3.0 | ||
pytest-django | ||
pytest-factoryboy | ||
fake-factory | ||
|
This file contains 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 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 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 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 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 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