Skip to content

Remove all deprecated code #688

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 1 commit into from
Aug 11, 2019
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ any parts of the framework not mentioned in the documentation should generally b

## [Unreleased]

This release is not backwards compatible. For easy migration best upgrade first to version
2.8.0 and resolve all deprecation warnings before updating to 3.0.0

### Added

* Add support for Django REST framework 3.10.
Expand All @@ -21,6 +24,11 @@ any parts of the framework not mentioned in the documentation should generally b
* Removed obsolete dependency six.
* Removed support for Django REST Framework <=3.8.
* Removed support for Django 2.0.
* Removed obsolete mixins `MultipleIDMixin` and `PrefetchForIncludesHelperMixin`
* Removed obsolete settings `JSON_API_FORMAT_KEYS`, `JSON_API_FORMAT_RELATION_KEYS` and
`JSON_API_PLURALIZE_RELATION_TYPE`
* Removed obsolete util methods `format_keys` and `format_relation_name`
* Removed obsolete pagination classes `PageNumberPagination` and `LimitOffsetPagination`

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions example/api/resources/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from rest_framework.decorators import action
from rest_framework.response import Response

from rest_framework_json_api import mixins, utils
from rest_framework_json_api import utils

from ..serializers.identity import IdentitySerializer
from ..serializers.post import PostSerializer


class Identity(mixins.MultipleIDMixin, viewsets.ModelViewSet):
class Identity(viewsets.ModelViewSet):
queryset = auth_models.User.objects.all().order_by('pk')
serializer_class = IdentitySerializer

Expand Down
82 changes: 0 additions & 82 deletions example/tests/test_multiple_id_mixin.py

This file was deleted.

12 changes: 0 additions & 12 deletions example/tests/test_parsers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from io import BytesIO

import pytest
from django.test import TestCase, override_settings
from rest_framework.exceptions import ParseError

Expand Down Expand Up @@ -35,17 +34,6 @@ def __init__(self):

self.string = json.dumps(data)

@pytest.mark.filterwarnings("ignore:`format_keys` function and `JSON_API_FORMAT_KEYS`")
@override_settings(JSON_API_FORMAT_KEYS='camelize')
def test_parse_include_metadata_format_keys(self):
parser = JSONParser()

stream = BytesIO(self.string.encode('utf-8'))
data = parser.parse(stream, None, self.parser_context)

self.assertEqual(data['_meta'], {'random_key': 'random_value'})
self.assertEqual(data['json_value'], {'json_key': 'JsonValue'})

@override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize')
def test_parse_include_metadata_format_field_names(self):
parser = JSONParser()
Expand Down
11 changes: 0 additions & 11 deletions example/tests/unit/test_default_drf_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ def test_render_format_field_names(settings):
assert result['data']['attributes']['json-field'] == {'JsonKey': 'JsonValue'}


@pytest.mark.filterwarnings("ignore:`format_keys` function and `JSON_API_FORMAT_KEYS`")
def test_render_format_keys(settings):
"""Test that json field value keys are formated."""
delattr(settings, 'JSON_API_FORMAT_FILED_NAMES')
settings.JSON_API_FORMAT_KEYS = 'dasherize'
rendered = render_dummy_test_serialized_view(DummyTestViewSet)

result = json.loads(rendered.decode())
assert result['data']['attributes']['json-field'] == {'json-key': 'JsonValue'}


@pytest.mark.django_db
def test_blog_create(client):

Expand Down
71 changes: 0 additions & 71 deletions example/tests/unit/test_pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import sys
from collections import OrderedDict

import pytest
from rest_framework.request import Request
from rest_framework.test import APIRequestFactory
from rest_framework.utils.urls import replace_query_param
Expand Down Expand Up @@ -78,72 +76,3 @@ def test_valid_offset_limit(self):

assert queryset == list(range(offset + 1, next_offset + 1))
assert content == expected_content

@pytest.mark.xfail((sys.version_info.major, sys.version_info.minor) == (2, 7),
reason="python2.7 fails to generate DeprecationWarrning for unknown reason")
def test_limit_offset_deprecation(self):
with pytest.warns(DeprecationWarning) as record:
pagination.LimitOffsetPagination()
assert len(record) == 1
assert 'LimitOffsetPagination is deprecated' in str(record[0].message)

class MyInheritedLimitOffsetPagination(pagination.LimitOffsetPagination):
"""
Inherit the default values
"""
pass

class MyOverridenLimitOffsetPagination(pagination.LimitOffsetPagination):
"""
Explicitly set max_limit to the "old" values.
"""
max_limit = None

def test_my_limit_offset_deprecation(self):
with pytest.warns(DeprecationWarning) as record:
self.MyInheritedLimitOffsetPagination()
assert len(record) == 1
assert 'LimitOffsetPagination is deprecated' in str(record[0].message)

with pytest.warns(None) as record:
self.MyOverridenLimitOffsetPagination()
assert len(record) == 0


class TestPageNumber:
"""
Unit tests for `pagination.JsonApiPageNumberPagination`.
"""

@pytest.mark.xfail((sys.version_info.major, sys.version_info.minor) == (2, 7),
reason="python2.7 fails to generate DeprecationWarrning for unknown reason")
def test_page_number_deprecation(self):
with pytest.warns(DeprecationWarning) as record:
pagination.PageNumberPagination()
assert len(record) == 1
assert 'PageNumberPagination is deprecated' in str(record[0].message)

class MyInheritedPageNumberPagination(pagination.PageNumberPagination):
"""
Inherit the default values
"""
pass

class MyOverridenPageNumberPagination(pagination.PageNumberPagination):
"""
Explicitly set page_query_param and page_size_query_param to the "old" values.
"""
page_query_param = "page"
page_size_query_param = "page_size"

@pytest.mark.xfail((sys.version_info.major, sys.version_info.minor) == (2, 7),
reason="python2.7 fails to generate DeprecationWarrning for unknown reason")
def test_my_page_number_deprecation(self):
with pytest.warns(DeprecationWarning) as record:
self.MyInheritedPageNumberPagination()
assert len(record) == 1
assert 'PageNumberPagination is deprecated' in str(record[0].message)

with pytest.warns(None) as record:
self.MyOverridenPageNumberPagination()
assert len(record) == 0
11 changes: 0 additions & 11 deletions example/tests/unit/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,6 @@ def test_render_format_field_names(settings):
assert result['data']['attributes']['json-field'] == {'JsonKey': 'JsonValue'}


@pytest.mark.filterwarnings("ignore:`format_keys` function and `JSON_API_FORMAT_KEYS`")
def test_render_format_keys(settings):
"""Test that json field value keys are formated."""
delattr(settings, 'JSON_API_FORMAT_FILED_NAMES')
settings.JSON_API_FORMAT_KEYS = 'dasherize'
rendered = render_dummy_test_serialized_view(DummyTestViewSet, Entry())

result = json.loads(rendered.decode())
assert result['data']['attributes']['json-field'] == {'json-key': 'JsonValue'}


def test_writeonly_not_in_response():
"""Test that writeonly fields are not shown in list response"""

Expand Down
24 changes: 0 additions & 24 deletions example/tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,6 @@ def test_get_resource_name():
assert 'users' == utils.get_resource_name(context), 'derived from non-model serializer'


@pytest.mark.filterwarnings("ignore:`format_keys` function and `JSON_API_FORMAT_KEYS`")
def test_format_keys():
underscored = {
'first_name': 'a',
'last_name': 'b',
}

output = {'firstName': 'a', 'lastName': 'b'}
result = pytest.deprecated_call(utils.format_keys, underscored, 'camelize')
assert result == output

output = {'FirstName': 'a', 'LastName': 'b'}
assert utils.format_keys(underscored, 'capitalize') == output

output = {'first-name': 'a', 'last-name': 'b'}
assert utils.format_keys(underscored, 'dasherize') == output

new_input = {'firstName': 'a', 'lastName': 'b'}
assert utils.format_keys(new_input, 'underscore') == underscored

output = [{'first-name': 'a', 'last-name': 'b'}]
assert utils.format_keys([underscored], 'dasherize') == output


@pytest.mark.parametrize("format_type,output", [
('camelize', {'fullName': {'last-name': 'a', 'first-name': 'b'}}),
('capitalize', {'FullName': {'last-name': 'a', 'first-name': 'b'}}),
Expand Down
2 changes: 0 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ DJANGO_SETTINGS_MODULE=example.settings.test
filterwarnings =
error::DeprecationWarning
error::PendingDeprecationWarning
# TODO: restructure tests so this can be ignored on a test level
ignore:MultipleIDMixin is deprecated
38 changes: 0 additions & 38 deletions rest_framework_json_api/mixins.py

This file was deleted.

Loading