Skip to content

Remove global ignore of serializer warnings #816

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 2 commits into from
Aug 25, 2020
Merged
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
6 changes: 3 additions & 3 deletions example/serializers.py
Original file line number Diff line number Diff line change
@@ -40,9 +40,9 @@ class Meta:

class BlogSerializer(serializers.ModelSerializer):
copyright = serializers.SerializerMethodField()
tags = TaggedItemSerializer(many=True, read_only=True)
tags = relations.ResourceRelatedField(many=True, read_only=True)

include_serializers = {
included_serializers = {
'tags': 'example.serializers.TaggedItemSerializer',
}

@@ -147,7 +147,7 @@ def __init__(self, *args, **kwargs):
model=Entry,
read_only=True
)
tags = TaggedItemSerializer(many=True, read_only=True)
tags = relations.ResourceRelatedField(many=True, read_only=True)

def get_suggested(self, obj):
return Entry.objects.exclude(pk=obj.pk)
1 change: 1 addition & 0 deletions example/settings/dev.py
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@

JSON_API_FORMAT_FIELD_NAMES = 'camelize'
JSON_API_FORMAT_TYPES = 'camelize'
JSON_API_SERIALIZE_NESTED_SERIALIZERS_AS_ATTRIBUTE = True
REST_FRAMEWORK = {
'PAGE_SIZE': 5,
'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
12 changes: 2 additions & 10 deletions example/tests/integration/test_meta.py
Original file line number Diff line number Diff line change
@@ -18,11 +18,7 @@ def test_top_level_meta_for_list_view(blog, client):
"links": {
"self": 'http://testserver/blogs/1'
},
"relationships": {
"tags": {
"data": []
}
},
'relationships': {'tags': {'data': [], 'meta': {'count': 0}}},
"meta": {
"copyright": datetime.now().year
},
@@ -53,11 +49,7 @@ def test_top_level_meta_for_detail_view(blog, client):
"attributes": {
"name": blog.name
},
"relationships": {
"tags": {
"data": []
}
},
'relationships': {'tags': {'data': [], 'meta': {'count': 0}}},
"links": {
"self": "http://testserver/blogs/1"
},
8 changes: 2 additions & 6 deletions example/tests/integration/test_non_paginated_responses.py
Original file line number Diff line number Diff line change
@@ -72,9 +72,7 @@ def test_multiple_entries_no_pagination(multiple_entries, client):
"self": "http://testserver/entries/1/relationships/featured_hyperlinked"
}
},
"tags": {
"data": []
}
'tags': {'data': [], 'meta': {'count': 0}},
}
},
{
@@ -135,9 +133,7 @@ def test_multiple_entries_no_pagination(multiple_entries, client):
"self": "http://testserver/entries/2/relationships/featured_hyperlinked"
}
},
"tags": {
"data": []
}
'tags': {'data': [], 'meta': {'count': 0}},
}
},
]
1 change: 1 addition & 0 deletions example/tests/integration/test_pagination.py
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ def test_pagination_with_single_entry(single_entry, client):
}
},
"tags": {
'meta': {'count': 1},
"data": [
{
"id": "1",
4 changes: 1 addition & 3 deletions example/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -461,9 +461,7 @@ def test_search_keywords(self):
'self': 'http://testserver/entries/7/relationships/suggested_hyperlinked', # noqa: E501
'related': 'http://testserver/entries/7/suggested/'}
},
'tags': {
'data': []
},
'tags': {'data': [], 'meta': {'count': 0}},
'featuredHyperlinked': {
'links': {
'self': 'http://testserver/entries/7/relationships/featured_hyperlinked', # noqa: E501
9 changes: 7 additions & 2 deletions example/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ def setUp(self):
)

def test_forward_relationship_not_loaded_when_not_included(self):
to_representation_method = 'example.serializers.BlogSerializer.to_representation'
to_representation_method = 'example.serializers.TaggedItemSerializer.to_representation'
with mock.patch(to_representation_method) as mocked_serializer:
class EntrySerializer(ModelSerializer):
blog = BlogSerializer()
@@ -79,7 +79,12 @@ class Meta:
expected = dict(
[
('id', 1),
('blog', dict([('type', 'blogs'), ('id', 1)])),
('blog', dict([
('name', 'Some Blog'),
('tags', []),
('copyright', 2020),
('url', 'http://testserver/blogs/1')
])),
('headline', 'headline'),
('body_text', 'body_text'),
('pub_date', DateField().to_representation(self.entry.pub_date)),
4 changes: 2 additions & 2 deletions example/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -538,7 +538,7 @@ def test_get_object_gives_correct_blog(self):
'id': '{}'.format(self.blog.id),
'links': {'self': 'http://testserver/blogs/{}'.format(self.blog.id)},
'meta': {'copyright': datetime.now().year},
'relationships': {'tags': {'data': []}},
'relationships': {'tags': {'data': [], 'meta': {'count': 0}}},
'type': 'blogs'
},
'meta': {'apiDocs': '/docs/api/blogs'}
@@ -632,7 +632,7 @@ def test_get_object_gives_correct_entry(self):
'/suggested_hyperlinked'.format(self.second_entry.id)
}
},
'tags': {'data': []}},
'tags': {'data': [], 'meta': {'count': 0}}},
'type': 'posts'
}
}
18 changes: 6 additions & 12 deletions example/tests/unit/test_default_drf_serializers.py
Original file line number Diff line number Diff line change
@@ -95,11 +95,10 @@ def test_blog_create(client):

expected = {
'data': {
'attributes': {'name': blog.name},
'attributes': {'name': blog.name, 'tags': []},
'id': '{}'.format(blog.id),
'links': {'self': 'http://testserver/blogs/{}'.format(blog.id)},
'meta': {'copyright': datetime.now().year},
'relationships': {'tags': {'data': []}},
'type': 'blogs'
},
'meta': {'apiDocs': '/docs/api/blogs'}
@@ -116,11 +115,10 @@ def test_get_object_gives_correct_blog(client, blog, entry):
resp = client.get(url)
expected = {
'data': {
'attributes': {'name': blog.name},
'attributes': {'name': blog.name, 'tags': []},
'id': '{}'.format(blog.id),
'links': {'self': 'http://testserver/blogs/{}'.format(blog.id)},
'meta': {'copyright': datetime.now().year},
'relationships': {'tags': {'data': []}},
'type': 'blogs'
},
'meta': {'apiDocs': '/docs/api/blogs'}
@@ -154,11 +152,10 @@ def test_get_object_patches_correct_blog(client, blog, entry):

expected = {
'data': {
'attributes': {'name': new_name},
'attributes': {'name': new_name, 'tags': []},
'id': '{}'.format(blog.id),
'links': {'self': 'http://testserver/blogs/{}'.format(blog.id)},
'meta': {'copyright': datetime.now().year},
'relationships': {'tags': {'data': []}},
'type': 'blogs'
},
'meta': {'apiDocs': '/docs/api/blogs'}
@@ -189,17 +186,14 @@ def test_get_entry_list_with_blogs(client, entry):
'first': 'http://testserver/drf-entries/1/suggested/?page%5Bnumber%5D=1',
'last': 'http://testserver/drf-entries/1/suggested/?page%5Bnumber%5D=1',
'next': None,
'prev': None
'prev': None,
},
'data': [
{
'type': 'entries',
'id': '1',
'attributes': {},
'relationships': {
'tags': {
'data': []
}
'attributes': {
'tags': [],
},
'links': {
'self': 'http://testserver/drf-blogs/1'
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -3,4 +3,3 @@ DJANGO_SETTINGS_MODULE=example.settings.test
filterwarnings =
error::DeprecationWarning
error::PendingDeprecationWarning
ignore::DeprecationWarning:rest_framework_json_api.serializers