Skip to content

Commit

Permalink
Merge branch 'master' into 38
Browse files Browse the repository at this point in the history
  • Loading branch information
auvipy authored Jan 25, 2020
2 parents c85d7b7 + 46673dc commit 7c6f017
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 42 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python:
- 3.8
- 3.6
- 3.7
- 3.8

install:
- pip install tox tox-travis
Expand Down
9 changes: 3 additions & 6 deletions docs/backdoc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
Backdoc is a tool for backbone-like documentation generation.
Expand All @@ -9,8 +8,6 @@
import sys
import argparse

# -*- coding: utf-8 -*-
#!/usr/bin/env python
# Copyright (c) 2012 Trent Mick.
# Copyright (c) 2007-2008 ActiveState Corp.
# License: MIT (http://www.opensource.org/licenses/mit-license.php)
Expand Down Expand Up @@ -185,7 +182,7 @@ def markdown(text, html4tags=False, tab_width=DEFAULT_TAB_WIDTH,
link_patterns=link_patterns,
use_file_vars=use_file_vars).convert(text)

class Markdown(object):
class Markdown:
# The dict of "extras" to enable in processing -- a mapping of
# extra name to argument for the extra. Most extras do not have an
# argument, in which case the value is None.
Expand Down Expand Up @@ -2095,7 +2092,7 @@ def _dedent(text, tabsize=8, skip_first_line=False):
return ''.join(lines)


class _memoized(object):
class _memoized:
"""Decorator that caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned, and
not re-evaluated.
Expand Down Expand Up @@ -2660,7 +2657,7 @@ def force_text(text):
return text.decode('utf-8')


class BackDoc(object):
class BackDoc:
def __init__(self, markdown_converter, template_html, stdin, stdout):
self.markdown_converter = markdown_converter
self.template_html = force_text(template_html)
Expand Down
12 changes: 11 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2213,9 +2213,19 @@ You can read about versioning, deprecation policy and upgrading from
[Django REST framework documentation](https://www.django-rest-framework.org/community/release-notes/).


#### Development version

* Added support for Django 3.0 (#276)
* Dropped support for Django 2.0
* Added support for DRF 3.10 and 3.11 (#261, #279)
* Added support for Python 3.8 (#282)
* Added paginate decorator (#266)
* Added limit/offset and cursor pagination to PaginationKeyBit (#204)


#### 0.5.0

* Maay 10, 2019 *
*May 10, 2019*

* Dropped python 2.7 and 3.4
* Fix possible header mutation issue
Expand Down
5 changes: 2 additions & 3 deletions rest_framework_extensions/cache/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from functools import wraps
from functools import wraps, WRAPPER_ASSIGNMENTS

from django.http.response import HttpResponse
from django.utils.decorators import available_attrs


from rest_framework_extensions.settings import extensions_api_settings
Expand Down Expand Up @@ -50,7 +49,7 @@ def __init__(self,
def __call__(self, func):
this = self

@wraps(func, assigned=available_attrs(func))
@wraps(func, assigned=WRAPPER_ASSIGNMENTS)
def inner(self, request, *args, **kwargs):
return this.process_cache_response(
view_instance=self,
Expand Down
9 changes: 4 additions & 5 deletions rest_framework_extensions/etag/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from functools import wraps
from functools import wraps, WRAPPER_ASSIGNMENTS

from django.utils.decorators import available_attrs
from django.utils.http import parse_etags, quote_etag

from rest_framework import status
Expand All @@ -27,7 +26,7 @@ def __init__(self, etag_func=None, rebuild_after_method_evaluation=False):
def __call__(self, func):
this = self

@wraps(func, assigned=available_attrs(func))
@wraps(func, assigned=WRAPPER_ASSIGNMENTS)
def inner(self, request, *args, **kwargs):
return this.process_conditional_request(
view_instance=self,
Expand Down Expand Up @@ -168,15 +167,15 @@ def __init__(self, etag_func=None, rebuild_after_method_evaluation=False, precon
'the key is the HTTP verb, and the value is a list of '
'HTTP headers that must all be present for that request.')

super(APIETAGProcessor, self).__init__(etag_func=etag_func,
super().__init__(etag_func=etag_func,
rebuild_after_method_evaluation=rebuild_after_method_evaluation)

def get_etags_and_matchers(self, request):
"""Get the etags from the header and perform a validation against the required preconditions."""
# evaluate the preconditions, raises 428 if condition is not met
self.evaluate_preconditions(request)
# alright, headers are present, extract the values and match the conditions
return super(APIETAGProcessor, self).get_etags_and_matchers(request)
return super().get_etags_and_matchers(request)

def evaluate_preconditions(self, request):
"""Evaluate whether the precondition for the request is met."""
Expand Down
2 changes: 1 addition & 1 deletion rest_framework_extensions/etag/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BaseETAGMixin:
class ListETAGMixin(BaseETAGMixin):
@etag(etag_func='list_etag_func')
def list(self, request, *args, **kwargs):
return super(ListETAGMixin, self).list(request, *args, **kwargs)
return super().list(request, *args, **kwargs)


class RetrieveETAGMixin(BaseETAGMixin):
Expand Down
4 changes: 2 additions & 2 deletions rest_framework_extensions/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def options(self, path, data=None, format=None, content_type=None, **extra):
return self.generic('OPTIONS', path, data, content_type, **extra)

def request(self, **kwargs):
request = super(APIRequestFactory, self).request(**kwargs)
request = super().request(**kwargs)
request._dont_enforce_csrf_checks = not self.enforce_csrf_checks
return request

Expand All @@ -128,7 +128,7 @@ def get_response(self, request):

class APIClient(APIRequestFactory, DjangoClient):
def __init__(self, enforce_csrf_checks=False, **defaults):
super(APIClient, self).__init__(**defaults)
super().__init__(**defaults)
self.handler = ForceAuthClientHandler(enforce_csrf_checks)
self._credentials = {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.test import TestCase, override_settings


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.conf.urls import url

from .views import MyView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.views import View
from django.http import HttpResponse

Expand Down
1 change: 0 additions & 1 deletion tests_app/tests/functional/key_constructor/bits/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from rest_framework import routers

from .views import UserModelViewSet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from rest_framework import routers

from .views import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class CommentWithDetailSerializerAndNoArgsForGetQuerySetViewSet(DetailSerializer
queryset_detail = Comment.objects.filter(id=1)

def get_queryset(self):
return super(CommentWithDetailSerializerAndNoArgsForGetQuerySetViewSet, self).get_queryset()
return super().get_queryset()
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest

import django
from django.test import override_settings

from rest_framework_extensions.test import APITestCase
Expand Down Expand Up @@ -155,9 +156,14 @@ def test_invalid_for_db_data(self):
self.fail('Errors with invalid for DB data should be caught')
else:
self.assertEqual(resp.status_code, 400)
expected_message = {
'detail': "invalid literal for int() with base 10: 'Not integer value'"
}
if django.VERSION < (3, 0, 0):
expected_message = {
'detail': "invalid literal for int() with base 10: 'Not integer value'"
}
else:
expected_message = {
'detail': "Field 'age' expected a number but got 'Not integer value'."
}
self.assertEqual(resp.data, expected_message)

def test_should_use_source_if_it_set_in_serializer(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ class CommentViewSet(NestedViewSetMixin, ModelViewSet):

class TaskCommentViewSet(CommentViewSet):
def get_queryset(self):
return super(TaskCommentViewSet, self).get_queryset().filter(
return super().get_queryset().filter(
content_type=ContentType.objects.get_for_model(TaskModel)
)


class BookCommentViewSet(CommentViewSet):
def get_queryset(self):
return super(BookCommentViewSet, self).get_queryset().filter(
return super().get_queryset().filter(
content_type=ContentType.objects.get_for_model(BookModel)
)

Expand Down
12 changes: 6 additions & 6 deletions tests_app/tests/unit/_etag/decorators/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def run_for_methods(self, methods, condition_failed_status):

class ETAGProcessorTestBehavior_if_none_match(ETAGProcessorTestBehaviorMixin, TestCase):
def setUp(self):
super(ETAGProcessorTestBehavior_if_none_match, self).setUp()
super().setUp()
self.header_name = 'if-none-match'
self.experiments = [
{
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_for_unsafe_methods(self):

class ETAGProcessorTestBehavior_if_match(ETAGProcessorTestBehaviorMixin, TestCase):
def setUp(self):
super(ETAGProcessorTestBehavior_if_match, self).setUp()
super().setUp()
self.header_name = 'if-match'
self.experiments = [
{
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_should_raise_assertion_error_if_etag_func_not_specified_decorator(self)
class View(views.APIView):
@api_etag()
def get(self, request, *args, **kwargs):
return super(View, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)

def test_should_raise_assertion_error_if_precondition_map_not_a_dict(self):
with self.assertRaises(AssertionError):
Expand All @@ -353,7 +353,7 @@ def test_should_raise_assertion_error_if_precondition_map_not_a_dict_decorator(s
class View(views.APIView):
@api_etag(dummy_api_etag_func, precondition_map=['header-name'])
def get(self, request, *args, **kwargs):
return super(View, self).get(request, *args, **kwargs)
return super().get(request, *args, **kwargs)

def test_should_add_object_etag_value(self):
class TestView(views.APIView):
Expand Down Expand Up @@ -608,7 +608,7 @@ def run_for_methods(self, methods, condition_failed_status, experiments=None):

class APIETAGProcessorTestBehavior_if_match(APIETAGProcessorTestBehaviorMixin, TestCase):
def setUp(self):
super(APIETAGProcessorTestBehavior_if_match, self).setUp()
super().setUp()
self.header_name = 'if-match'
self.experiments = [
{
Expand Down Expand Up @@ -662,7 +662,7 @@ def test_for_all_methods(self):

class APIETAGProcessorTestBehavior_if_none_match(APIETAGProcessorTestBehaviorMixin, TestCase):
def setUp(self):
super(APIETAGProcessorTestBehavior_if_none_match, self).setUp()
super().setUp()
self.header_name = 'if-none-match'
self.experiments = [
{
Expand Down
6 changes: 3 additions & 3 deletions tests_app/tests/unit/cache/decorators/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class CacheResponseTest(TestCase):
def setUp(self):
super(CacheResponseTest, self).setUp()
super().setUp()
self.request = factory.get('')
self.cache = caches[extensions_api_settings.DEFAULT_USE_CACHE]

Expand Down Expand Up @@ -253,7 +253,7 @@ class TestView(views.APIView):

def __init__(self, status, *args, **kwargs):
self.status = status
super(TestView, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

@cache_response_decorator
def get(self, request, *args, **kwargs):
Expand All @@ -273,7 +273,7 @@ class TestView(views.APIView):

def __init__(self, status, *args, **kwargs):
self.status = status
super(TestView, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

@cache_response_decorator
def get(self, request, *args, **kwargs):
Expand Down
11 changes: 8 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[tox]
envlist = py{36,37}-django{111}-drf39,
py{36,37}-django{21,22}-drf39
py{38,36,37}-django{21,22}-drf310
envlist = py{35,36,37}-django{111}-drf39,
py{35,36,37}-django{21}-drf{39,310,311}
py{35,36,37,38}-django{22}-drf{39,310,311}
py{36,37,38}-django{30}-drf{310,311}


[testenv]
deps=
Expand All @@ -11,9 +13,12 @@ deps=
djangorestframework-guardian
drf310: djangorestframework>=3.10,<3.11
djangorestframework-guardian
drf311: djangorestframework>=3.11,<3.12
djangorestframework-guardian
django111: Django>=1.11,<2.0
django21: Django>=2.1,<2.2
django22: Django>=2.2,<3.0
django30: Django>=3.0,<3.1
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/tests_app
commands =
Expand Down

0 comments on commit 7c6f017

Please sign in to comment.