Merge pull request #3048 from jpadilla/import-cleanup

Cleanup import following PEP 8 style guide
This commit is contained in:
Tom Christie 2015-06-26 14:55:28 +01:00
commit 3e1687282b
98 changed files with 462 additions and 266 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ MANIFEST
!.gitignore !.gitignore
!.travis.yml !.travis.yml
!.isort.cfg

6
.isort.cfg Normal file
View File

@ -0,0 +1,6 @@
[settings]
skip=.tox
atomic=true
multi_line_output=5
known_third_party=pytest,django
known_first_party=rest_framework

View File

@ -3,7 +3,7 @@ language: python
sudo: false sudo: false
env: env:
- TOX_ENV=py27-flake8 - TOX_ENV=py27-lint
- TOX_ENV=py27-docs - TOX_ENV=py27-docs
- TOX_ENV=py34-django18 - TOX_ENV=py34-django18
- TOX_ENV=py33-django18 - TOX_ENV=py33-django18

View File

@ -1,3 +1,6 @@
# PEP8 code linting, which we run on all commits. # PEP8 code linting, which we run on all commits.
flake8==2.4.0 flake8==2.4.0
pep8==1.5.7 pep8==1.5.7
# Sort and lint imports
isort==3.9.6

View File

@ -2,11 +2,14 @@
Provides various authentication policies. Provides various authentication policies.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import base64 import base64
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from django.middleware.csrf import CsrfViewMiddleware from django.middleware.csrf import CsrfViewMiddleware
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions, HTTP_HEADER_ENCODING
from rest_framework import HTTP_HEADER_ENCODING, exceptions
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.compat import get_user_model from rest_framework.compat import get_user_model

View File

@ -1,4 +1,5 @@
from django.contrib import admin from django.contrib import admin
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration): class Migration(migrations.Migration):

View File

@ -5,7 +5,6 @@ from django.conf import settings
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
# Prior to Django 1.5, the AUTH_USER_MODEL setting does not exist. # Prior to Django 1.5, the AUTH_USER_MODEL setting does not exist.
# Note that we don't perform this code in the compat module due to # Note that we don't perform this code in the compat module due to
# bug report #1297 # bug report #1297

View File

@ -1,9 +1,8 @@
from rest_framework.views import APIView from rest_framework import parsers, renderers
from rest_framework import parsers
from rest_framework import renderers
from rest_framework.response import Response
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer from rest_framework.authtoken.serializers import AuthTokenSerializer
from rest_framework.response import Response
from rest_framework.views import APIView
class ObtainAuthToken(APIView): class ObtainAuthToken(APIView):

View File

@ -5,14 +5,18 @@ versions of django/python, and compatibility wrappers around optional packages.
# flake8: noqa # flake8: noqa
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.exceptions import ImproperlyConfigured
import inspect
import django
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, transaction from django.db import connection, transaction
from django.test.client import FakePayload
from django.utils import six
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.six.moves.urllib.parse import urlparse as _urlparse from django.utils.six.moves.urllib.parse import urlparse as _urlparse
from django.utils import six
import django
import inspect
try: try:
import importlib import importlib
except ImportError: except ImportError:
@ -199,7 +203,6 @@ if 'patch' not in View.http_method_names:
View.http_method_names = View.http_method_names + ['patch'] View.http_method_names = View.http_method_names + ['patch']
from django.test.client import FakePayload
try: try:
# In 1.5 the test client uses force_bytes # In 1.5 the test client uses force_bytes

View File

@ -7,10 +7,13 @@ based views, as well as the `@detail_route` and `@list_route` decorators, which
used to annotate methods on viewsets that should be included by routers. used to annotate methods on viewsets that should be included by routers.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils import six
from rest_framework.views import APIView
import types import types
from django.utils import six
from rest_framework.views import APIView
def api_view(http_method_names=None): def api_view(http_method_names=None):

View File

@ -5,11 +5,15 @@ In addition Django's built in 403 and 404 exceptions are handled.
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`) (`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import math
from django.utils import six from django.utils import six
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _, ungettext from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext
from rest_framework import status from rest_framework import status
import math
def _force_text_recursive(data): def _force_text_recursive(data):

View File

@ -1,23 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ValidationError as DjangoValidationError
from django.core.validators import RegexValidator, ip_address_validators
from django.forms import ImageField as DjangoImageField
from django.utils import six, timezone
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.encoding import is_protected_type, smart_text
from django.utils.translation import ugettext_lazy as _
from django.utils.ipv6 import clean_ipv6_address
from rest_framework import ISO_8601
from rest_framework.compat import (
EmailValidator, MinValueValidator, MaxValueValidator,
MinLengthValidator, MaxLengthValidator, URLValidator, OrderedDict,
unicode_repr, unicode_to_repr, parse_duration, duration_string,
)
from rest_framework.exceptions import ValidationError
from rest_framework.settings import api_settings
from rest_framework.utils import html, representation, humanize_datetime
import collections import collections
import copy import copy
import datetime import datetime
@ -26,6 +8,27 @@ import inspect
import re import re
import uuid import uuid
from django.conf import settings
from django.core.exceptions import ValidationError as DjangoValidationError
from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import RegexValidator, ip_address_validators
from django.forms import ImageField as DjangoImageField
from django.utils import six, timezone
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.encoding import is_protected_type, smart_text
from django.utils.ipv6 import clean_ipv6_address
from django.utils.translation import ugettext_lazy as _
from rest_framework import ISO_8601
from rest_framework.compat import (
EmailValidator, MaxLengthValidator, MaxValueValidator, MinLengthValidator,
MinValueValidator, OrderedDict, URLValidator, duration_string,
parse_duration, unicode_repr, unicode_to_repr
)
from rest_framework.exceptions import ValidationError
from rest_framework.settings import api_settings
from rest_framework.utils import html, humanize_datetime, representation
class empty: class empty:
""" """

View File

@ -4,13 +4,15 @@ returned by list views.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import operator
from functools import reduce
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.db import models from django.db import models
from django.utils import six from django.utils import six
from rest_framework.compat import django_filters, guardian, get_model_name
from rest_framework.compat import django_filters, get_model_name, guardian
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from functools import reduce
import operator
FilterSet = django_filters and django_filters.FilterSet or None FilterSet = django_filters and django_filters.FilterSet or None

View File

@ -2,10 +2,12 @@
Generic views that provide commonly needed behaviour. Generic views that provide commonly needed behaviour.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404 as _get_object_or_404 from django.shortcuts import get_object_or_404 as _get_object_or_404
from rest_framework import views, mixins
from rest_framework import mixins, views
from rest_framework.settings import api_settings from rest_framework.settings import api_settings

View File

@ -11,6 +11,7 @@ from __future__ import unicode_literals
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.http import Http404 from django.http import Http404
from django.utils.encoding import force_text from django.utils.encoding import force_text
from rest_framework import exceptions, serializers from rest_framework import exceptions, serializers
from rest_framework.compat import OrderedDict from rest_framework.compat import OrderedDict
from rest_framework.request import clone_request from rest_framework.request import clone_request

View File

@ -5,6 +5,7 @@ We don't bind behaviour to http method handlers yet,
which allows mixin classes to be composed in interesting ways. which allows mixin classes to be composed in interesting ways.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings

View File

@ -3,11 +3,14 @@ Content negotiation deals with selecting an appropriate renderer given the
incoming request. Typically this will be based on the request's Accept header. incoming request. Typically this will be based on the request's Accept header.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.http import Http404 from django.http import Http404
from rest_framework import HTTP_HEADER_ENCODING, exceptions from rest_framework import HTTP_HEADER_ENCODING, exceptions
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.utils.mediatypes import order_by_precedence, media_type_matches from rest_framework.utils.mediatypes import (
from rest_framework.utils.mediatypes import _MediaType _MediaType, media_type_matches, order_by_precedence
)
class BaseContentNegotiation(object): class BaseContentNegotiation(object):

View File

@ -4,21 +4,23 @@ Pagination serializers determine the structure of the output that should
be used for paginated responses. be used for paginated responses.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from base64 import b64encode, b64decode
import warnings
from base64 import b64decode, b64encode
from collections import namedtuple from collections import namedtuple
from django.core.paginator import InvalidPage, Paginator as DjangoPaginator
from django.core.paginator import Paginator as DjangoPaginator
from django.core.paginator import InvalidPage
from django.template import Context, loader from django.template import Context, loader
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import OrderedDict from rest_framework.compat import OrderedDict
from rest_framework.exceptions import NotFound from rest_framework.exceptions import NotFound
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.utils.urls import ( from rest_framework.utils.urls import remove_query_param, replace_query_param
replace_query_param, remove_query_param
)
import warnings
def _positive_int(integer_string, strict=False, cutoff=None): def _positive_int(integer_string, strict=False, cutoff=None):

View File

@ -6,17 +6,22 @@ on the request, such as form content or json encoded data.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import json
from django.conf import settings from django.conf import settings
from django.core.files.uploadhandler import StopFutureHandlers from django.core.files.uploadhandler import StopFutureHandlers
from django.http import QueryDict from django.http import QueryDict
from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser from django.http.multipartparser import \
from django.http.multipartparser import MultiPartParserError, parse_header, ChunkIter MultiPartParser as DjangoMultiPartParser
from django.http.multipartparser import (
ChunkIter, MultiPartParserError, parse_header
)
from django.utils import six from django.utils import six
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.encoding import force_text from django.utils.encoding import force_text
from rest_framework.exceptions import ParseError from django.utils.six.moves.urllib import parse as urlparse
from rest_framework import renderers from rest_framework import renderers
import json from rest_framework.exceptions import ParseError
class DataAndFiles(object): class DataAndFiles(object):

View File

@ -2,7 +2,9 @@
Provides a set of pluggable permission policies. Provides a set of pluggable permission policies.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.http import Http404 from django.http import Http404
from rest_framework.compat import get_model_name from rest_framework.compat import get_model_name
SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS') SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')

View File

@ -1,14 +1,18 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
from django.core.urlresolvers import get_script_prefix, resolve, NoReverseMatch, Resolver404 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.core.urlresolvers import (
NoReverseMatch, Resolver404, get_script_prefix, resolve
)
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django.utils import six from django.utils import six
from django.utils.encoding import smart_text from django.utils.encoding import smart_text
from django.utils.six.moves.urllib import parse as urlparse from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import OrderedDict from rest_framework.compat import OrderedDict
from rest_framework.fields import get_attribute, empty, Field from rest_framework.fields import Field, empty, get_attribute
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.utils import html from rest_framework.utils import html

View File

@ -9,19 +9,23 @@ REST framework also provides an HTML renderer the renders the browsable API.
from __future__ import unicode_literals from __future__ import unicode_literals
import json import json
import django import django
from django import forms from django import forms
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.paginator import Page from django.core.paginator import Page
from django.http.multipartparser import parse_header from django.http.multipartparser import parse_header
from django.template import Context, RequestContext, loader, Template from django.template import Context, RequestContext, Template, loader
from django.test.client import encode_multipart from django.test.client import encode_multipart
from django.utils import six from django.utils import six
from rest_framework import exceptions, serializers, status, VERSION
from rest_framework.compat import SHORT_SEPARATORS, LONG_SEPARATORS, INDENT_SEPARATORS from rest_framework import VERSION, exceptions, serializers, status
from rest_framework.compat import (
INDENT_SEPARATORS, LONG_SEPARATORS, SHORT_SEPARATORS
)
from rest_framework.exceptions import ParseError from rest_framework.exceptions import ParseError
from rest_framework.settings import api_settings
from rest_framework.request import is_form_media_type, override_method from rest_framework.request import is_form_media_type, override_method
from rest_framework.settings import api_settings
from rest_framework.utils import encoders from rest_framework.utils import encoders
from rest_framework.utils.breadcrumbs import get_breadcrumbs from rest_framework.utils.breadcrumbs import get_breadcrumbs
from rest_framework.utils.field_mapping import ClassLookupDict from rest_framework.utils.field_mapping import ClassLookupDict

View File

@ -9,16 +9,18 @@ The wrapped request then offers a richer API, in particular :
- form overloading of HTTP method, content type and content - form overloading of HTTP method, content type and content
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import sys
import warnings
from django.conf import settings from django.conf import settings
from django.http import QueryDict from django.http import QueryDict
from django.http.multipartparser import parse_header from django.http.multipartparser import parse_header
from django.utils import six from django.utils import six
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from rest_framework import HTTP_HEADER_ENCODING
from rest_framework import exceptions from rest_framework import HTTP_HEADER_ENCODING, exceptions
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
import sys
import warnings
def is_form_media_type(media_type): def is_form_media_type(media_type):

View File

@ -5,9 +5,10 @@ it is initialized with unrendered data, instead of a pre-rendered string.
The appropriate renderer is called during Django's template response rendering. The appropriate renderer is called during Django's template response rendering.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils.six.moves.http_client import responses
from django.template.response import SimpleTemplateResponse from django.template.response import SimpleTemplateResponse
from django.utils import six from django.utils import six
from django.utils.six.moves.http_client import responses
class Response(SimpleTemplateResponse): class Response(SimpleTemplateResponse):

View File

@ -2,6 +2,7 @@
Provide urlresolver functions that return fully qualified URLs or view names Provide urlresolver functions that return fully qualified URLs or view names
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.urlresolvers import reverse as django_reverse from django.core.urlresolvers import reverse as django_reverse
from django.core.urlresolvers import NoReverseMatch from django.core.urlresolvers import NoReverseMatch
from django.utils import six from django.utils import six

View File

@ -17,16 +17,17 @@ from __future__ import unicode_literals
import itertools import itertools
from collections import namedtuple from collections import namedtuple
from django.conf.urls import url from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import NoReverseMatch from django.core.urlresolvers import NoReverseMatch
from rest_framework import views from rest_framework import views
from rest_framework.compat import get_resolver_match, OrderedDict from rest_framework.compat import OrderedDict, get_resolver_match
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns from rest_framework.urlpatterns import format_suffix_patterns
Route = namedtuple('Route', ['url', 'mapping', 'name', 'initkwargs']) Route = namedtuple('Route', ['url', 'mapping', 'name', 'initkwargs'])
DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs']) DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs'])
DynamicListRoute = namedtuple('DynamicListRoute', ['url', 'name', 'initkwargs']) DynamicListRoute = namedtuple('DynamicListRoute', ['url', 'name', 'initkwargs'])

View File

@ -11,30 +11,29 @@ python primitives.
response content is handled by parsers and renderers. response content is handled by parsers and renderers.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import warnings
from django.db import models from django.db import models
from django.db.models.fields import FieldDoesNotExist, Field as DjangoModelField from django.db.models.fields import Field as DjangoModelField
from django.db.models.fields import FieldDoesNotExist
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import (
postgres_fields, from rest_framework.compat import DurationField as ModelDurationField
unicode_to_repr, from rest_framework.compat import postgres_fields, unicode_to_repr
DurationField as ModelDurationField,
)
from rest_framework.utils import model_meta from rest_framework.utils import model_meta
from rest_framework.utils.field_mapping import ( from rest_framework.utils.field_mapping import (
get_url_kwargs, get_field_kwargs, ClassLookupDict, get_field_kwargs, get_nested_relation_kwargs,
get_relation_kwargs, get_nested_relation_kwargs, get_relation_kwargs, get_url_kwargs
ClassLookupDict
) )
from rest_framework.utils.serializer_helpers import ( from rest_framework.utils.serializer_helpers import (
ReturnDict, ReturnList, BoundField, NestedBoundField, BindingDict BindingDict, BoundField, NestedBoundField, ReturnDict, ReturnList
) )
from rest_framework.validators import ( from rest_framework.validators import (
UniqueForDateValidator, UniqueForMonthValidator, UniqueForYearValidator, UniqueForDateValidator, UniqueForMonthValidator, UniqueForYearValidator,
UniqueTogetherValidator UniqueTogetherValidator
) )
import warnings
# Note: We do the following so that users of the framework can use this style: # Note: We do the following so that users of the framework can use this style:
# #
@ -43,9 +42,8 @@ import warnings
# This helps keep the separation between model fields, form fields, and # This helps keep the separation between model fields, form fields, and
# serializer fields more explicit. # serializer fields more explicit.
from rest_framework.relations import * # NOQA from rest_framework.fields import * # NOQA # isort:skip
from rest_framework.fields import * # NOQA from rest_framework.relations import * # NOQA # isort:skip
# We assume that 'validators' are intended for the child serializer, # We assume that 'validators' are intended for the child serializer,
# rather than the parent serializer. # rather than the parent serializer.

View File

@ -18,9 +18,11 @@ REST framework settings, checking for user settings first, then falling
back to the defaults. back to the defaults.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test.signals import setting_changed
from django.conf import settings from django.conf import settings
from django.test.signals import setting_changed
from django.utils import six from django.utils import six
from rest_framework import ISO_8601 from rest_framework import ISO_8601
from rest_framework.compat import importlib from rest_framework.compat import importlib

View File

@ -1,14 +1,16 @@
from __future__ import unicode_literals, absolute_import from __future__ import absolute_import, unicode_literals
import re
from django import template from django import template
from django.core.urlresolvers import reverse, NoReverseMatch from django.core.urlresolvers import NoReverseMatch, reverse
from django.utils import six from django.utils import six
from django.utils.encoding import iri_to_uri, force_text from django.utils.encoding import force_text, iri_to_uri
from django.utils.html import escape from django.utils.html import escape, smart_urlquote
from django.utils.safestring import SafeData, mark_safe from django.utils.safestring import SafeData, mark_safe
from django.utils.html import smart_urlquote
from rest_framework.renderers import HTMLFormRenderer from rest_framework.renderers import HTMLFormRenderer
from rest_framework.utils.urls import replace_query_param from rest_framework.utils.urls import replace_query_param
import re
register = template.Library() register = template.Library()

View File

@ -3,16 +3,18 @@
# Note that we import as `DjangoRequestFactory` and `DjangoClient` in order # Note that we import as `DjangoRequestFactory` and `DjangoClient` in order
# to make it harder for the user to import the wrong thing without realizing. # to make it harder for the user to import the wrong thing without realizing.
from __future__ import unicode_literals from __future__ import unicode_literals
import django import django
from django.conf import settings from django.conf import settings
from django.test import testcases
from django.test.client import Client as DjangoClient from django.test.client import Client as DjangoClient
from django.test.client import ClientHandler from django.test.client import ClientHandler
from django.test import testcases
from django.utils import six from django.utils import six
from django.utils.http import urlencode from django.utils.http import urlencode
from rest_framework.settings import api_settings
from rest_framework.compat import RequestFactory as DjangoRequestFactory from rest_framework.compat import RequestFactory as DjangoRequestFactory
from rest_framework.compat import force_bytes_or_smart_bytes from rest_framework.compat import force_bytes_or_smart_bytes
from rest_framework.settings import api_settings
def force_authenticate(request, user=None, token=None): def force_authenticate(request, user=None, token=None):

View File

@ -2,10 +2,13 @@
Provides various throttling policies. Provides various throttling policies.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import time
from django.core.cache import cache as default_cache from django.core.cache import cache as default_cache
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
import time
class BaseThrottle(object): class BaseThrottle(object):

View File

@ -1,6 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, include
from django.conf.urls import include, url
from django.core.urlresolvers import RegexURLResolver from django.core.urlresolvers import RegexURLResolver
from rest_framework.settings import api_settings from rest_framework.settings import api_settings

View File

@ -13,10 +13,10 @@ The urls must be namespaced as 'rest_framework', and you should make sure
your authentication settings include `SessionAuthentication`. your authentication settings include `SessionAuthentication`.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth import views from django.contrib.auth import views
template_name = {'template_name': 'rest_framework/login.html'} template_name = {'template_name': 'rest_framework/login.html'}
urlpatterns = [ urlpatterns = [

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.urlresolvers import resolve, get_script_prefix
from django.core.urlresolvers import get_script_prefix, resolve
def get_breadcrumbs(url): def get_breadcrumbs(url):

View File

@ -2,16 +2,19 @@
Helper classes for parsers. Helper classes for parsers.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db.models.query import QuerySet
from django.utils import six, timezone
from django.utils.encoding import force_text
from django.utils.functional import Promise
from rest_framework.compat import total_seconds
import datetime import datetime
import decimal import decimal
import json import json
import uuid import uuid
from django.db.models.query import QuerySet
from django.utils import six, timezone
from django.utils.encoding import force_text
from django.utils.functional import Promise
from rest_framework.compat import total_seconds
class JSONEncoder(json.JSONEncoder): class JSONEncoder(json.JSONEncoder):
""" """

View File

@ -2,13 +2,14 @@
Helper functions for mapping model fields to a dictionary of default Helper functions for mapping model fields to a dictionary of default
keyword arguments that should be used for their equivelent serializer fields. keyword arguments that should be used for their equivelent serializer fields.
""" """
import inspect
from django.core import validators from django.core import validators
from django.db import models from django.db import models
from django.utils.text import capfirst from django.utils.text import capfirst
from rest_framework.compat import clean_manytomany_helptext from rest_framework.compat import clean_manytomany_helptext
from rest_framework.validators import UniqueValidator from rest_framework.validators import UniqueValidator
import inspect
NUMERIC_FIELD_TYPES = ( NUMERIC_FIELD_TYPES = (
models.IntegerField, models.FloatField, models.DecimalField models.IntegerField, models.FloatField, models.DecimalField

View File

@ -2,10 +2,13 @@
Utility functions to return a formatted name and description for a given view. Utility functions to return a formatted name and description for a given view.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from rest_framework.compat import apply_markdown, force_text from rest_framework.compat import apply_markdown, force_text
import re
def remove_trailing_string(content, trailing): def remove_trailing_string(content, trailing):

View File

@ -2,6 +2,7 @@
Helpers for dealing with HTML input. Helpers for dealing with HTML input.
""" """
import re import re
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict

View File

@ -4,8 +4,10 @@ Handling of media types, as found in HTTP Content-Type and Accept headers.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.http.multipartparser import parse_header from django.http.multipartparser import parse_header
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from rest_framework import HTTP_HEADER_ENCODING from rest_framework import HTTP_HEADER_ENCODING

View File

@ -5,13 +5,14 @@ relationships and their associated metadata.
Usage: `get_field_info(model)` returns a `FieldInfo` instance. Usage: `get_field_info(model)` returns a `FieldInfo` instance.
""" """
import inspect
from collections import namedtuple from collections import namedtuple
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.db import models from django.db import models
from django.utils import six from django.utils import six
from rest_framework.compat import OrderedDict
import inspect
from rest_framework.compat import OrderedDict
FieldInfo = namedtuple('FieldResult', [ FieldInfo = namedtuple('FieldResult', [
'pk', # Model field instance 'pk', # Model field instance

View File

@ -3,11 +3,14 @@ Helper functions for creating user-friendly representations
of serializer classes and serializer fields. of serializer classes and serializer fields.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from django.db import models from django.db import models
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.functional import Promise from django.utils.functional import Promise
from rest_framework.compat import unicode_repr from rest_framework.compat import unicode_repr
import re
def manager_repr(value): def manager_repr(value):

View File

@ -1,5 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import collections import collections
from rest_framework.compat import OrderedDict, unicode_to_repr from rest_framework.compat import OrderedDict, unicode_to_repr

View File

@ -7,7 +7,9 @@ object creation, and makes it possible to switch between using the implicit
`ModelSerializer` class and an equivalent explicit `Serializer` class. `ModelSerializer` class and an equivalent explicit `Serializer` class.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import unicode_to_repr from rest_framework.compat import unicode_to_repr
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from rest_framework.utils.representation import smart_repr from rest_framework.utils.representation import smart_repr

View File

@ -1,13 +1,16 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions from rest_framework import exceptions
from rest_framework.compat import unicode_http_header from rest_framework.compat import unicode_http_header
from rest_framework.reverse import _reverse from rest_framework.reverse import _reverse
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.templatetags.rest_framework import replace_query_param from rest_framework.templatetags.rest_framework import replace_query_param
from rest_framework.utils.mediatypes import _MediaType from rest_framework.utils.mediatypes import _MediaType
import re
class BaseVersioning(object): class BaseVersioning(object):

View File

@ -2,20 +2,23 @@
Provides an APIView class that is the base of all views in REST framework. Provides an APIView class that is the base of all views in REST framework.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import inspect
import warnings
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.http import Http404 from django.http import Http404
from django.utils import six from django.utils import six
from django.utils.encoding import smart_text from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from rest_framework import status, exceptions
from rest_framework import exceptions, status
from rest_framework.compat import HttpResponseBase, View, set_rollback from rest_framework.compat import HttpResponseBase, View, set_rollback
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.utils import formatting from rest_framework.utils import formatting
import inspect
import warnings
def get_view_name(view_cls, suffix=None): def get_view_name(view_cls, suffix=None):

View File

@ -19,9 +19,11 @@ automatically.
from __future__ import unicode_literals from __future__ import unicode_literals
from functools import update_wrapper from functools import update_wrapper
from django.utils.decorators import classonlymethod from django.utils.decorators import classonlymethod
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from rest_framework import views, generics, mixins
from rest_framework import generics, mixins, views
class ViewSetMixin(object): class ViewSetMixin(object):

View File

@ -1,11 +1,11 @@
#! /usr/bin/env python #! /usr/bin/env python
from __future__ import print_function from __future__ import print_function
import pytest
import sys
import os import os
import subprocess import subprocess
import sys
import pytest
PYTEST_ARGS = { PYTEST_ARGS = {
'default': ['tests', '--tb=short'], 'default': ['tests', '--tb=short'],
@ -14,6 +14,7 @@ PYTEST_ARGS = {
FLAKE8_ARGS = ['rest_framework', 'tests', '--ignore=E501'] FLAKE8_ARGS = ['rest_framework', 'tests', '--ignore=E501']
ISORT_ARGS = ['--recursive', '--check-only', '.']
sys.path.append(os.path.dirname(__file__)) sys.path.append(os.path.dirname(__file__))
@ -30,6 +31,13 @@ def flake8_main(args):
return ret return ret
def isort_main(args):
print('Running isort code checking')
ret = subprocess.call(['isort'] + args)
print('isort failed' if ret else 'isort passed')
return ret
def split_class_and_function(string): def split_class_and_function(string):
class_string, function_string = string.split('.', 1) class_string, function_string = string.split('.', 1)
return "%s and %s" % (class_string, function_string) return "%s and %s" % (class_string, function_string)
@ -50,8 +58,10 @@ if __name__ == "__main__":
sys.argv.remove('--nolint') sys.argv.remove('--nolint')
except ValueError: except ValueError:
run_flake8 = True run_flake8 = True
run_isort = True
else: else:
run_flake8 = False run_flake8 = False
run_isort = False
try: try:
sys.argv.remove('--lintonly') sys.argv.remove('--lintonly')
@ -67,6 +77,7 @@ if __name__ == "__main__":
else: else:
style = 'fast' style = 'fast'
run_flake8 = False run_flake8 = False
run_isort = False
if len(sys.argv) > 1: if len(sys.argv) > 1:
pytest_args = sys.argv[1:] pytest_args = sys.argv[1:]
@ -79,7 +90,7 @@ if __name__ == "__main__":
expression = split_class_and_function(first_arg) expression = split_class_and_function(first_arg)
pytest_args = ['tests', '-k', expression] + pytest_args[1:] pytest_args = ['tests', '-k', expression] + pytest_args[1:]
elif is_class(first_arg) or is_function(first_arg): elif is_class(first_arg) or is_function(first_arg):
# `runtests.py TestCase [flags]` # `runtests.py TestCase [flags]`
# `runtests.py test_function [flags]` # `runtests.py test_function [flags]`
pytest_args = ['tests', '-k', pytest_args[0]] + pytest_args[1:] pytest_args = ['tests', '-k', pytest_args[0]] + pytest_args[1:]
else: else:
@ -87,5 +98,9 @@ if __name__ == "__main__":
if run_tests: if run_tests:
exit_on_failure(pytest.main(pytest_args)) exit_on_failure(pytest.main(pytest_args))
if run_flake8: if run_flake8:
exit_on_failure(flake8_main(FLAKE8_ARGS)) exit_on_failure(flake8_main(FLAKE8_ARGS))
if run_isort:
exit_on_failure(isort_main(ISORT_ARGS))

View File

@ -1,11 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import re
import sys
from setuptools import setup from setuptools import setup
from setuptools.command.test import test as TestCommand
import re
import os
import sys
def get_version(package): def get_version(package):

View File

@ -1,9 +1,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, include
from django.conf.urls import include, url
from .views import MockView from .views import MockView
urlpatterns = [ urlpatterns = [
url(r'^$', MockView.as_view()), url(r'^$', MockView.as_view()),
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
from .views import MockView from .views import MockView
urlpatterns = [ urlpatterns = [

View File

@ -1,4 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import TestCase from django.test import TestCase

View File

@ -1,9 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from rest_framework.views import APIView from rest_framework import authentication, renderers
from rest_framework import authentication
from rest_framework import renderers
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView
class MockView(APIView): class MockView(APIView):

View File

@ -8,7 +8,6 @@
from rest_framework.views import APIView from rest_framework.views import APIView
# test strings snatched from http://www.columbia.edu/~fdc/utf8/, # test strings snatched from http://www.columbia.edu/~fdc/utf8/,
# http://winrus.com/utf8-jap.htm and memory # http://winrus.com/utf8-jap.htm and memory
UTF8_TEST_DOCSTRING = ( UTF8_TEST_DOCSTRING = (

View File

@ -1,4 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _

View File

@ -2,10 +2,11 @@ from __future__ import unicode_literals
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from django.db import connection, connections, transaction from django.db import connection, connections, transaction
from django.test import TestCase, TransactionTestCase
from django.http import Http404 from django.http import Http404
from django.test import TestCase, TransactionTestCase
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.unittest import skipUnless from django.utils.unittest import skipUnless
from rest_framework import status from rest_framework import status
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException
from rest_framework.response import Response from rest_framework.response import Response
@ -13,7 +14,6 @@ from rest_framework.test import APIRequestFactory
from rest_framework.views import APIView from rest_framework.views import APIView
from tests.models import BasicModel from tests.models import BasicModel
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,27 +1,26 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, include
import base64
from django.conf.urls import include, url
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.http import HttpResponse from django.http import HttpResponse
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from rest_framework import HTTP_HEADER_ENCODING
from rest_framework import exceptions from rest_framework import (
from rest_framework import permissions HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status
from rest_framework import renderers )
from rest_framework.response import Response
from rest_framework import status
from rest_framework.authentication import ( from rest_framework.authentication import (
BaseAuthentication, BaseAuthentication, BasicAuthentication, SessionAuthentication,
TokenAuthentication, TokenAuthentication
BasicAuthentication,
SessionAuthentication,
) )
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.test import APIRequestFactory, APIClient from rest_framework.response import Response
from rest_framework.test import APIClient, APIRequestFactory
from rest_framework.views import APIView from rest_framework.views import APIView
import base64
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,22 +1,20 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from rest_framework import status from rest_framework import status
from rest_framework.authentication import BasicAuthentication from rest_framework.authentication import BasicAuthentication
from rest_framework.decorators import (
api_view, authentication_classes, parser_classes, permission_classes,
renderer_classes, throttle_classes
)
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.renderers import JSONRenderer from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from rest_framework.throttling import UserRateThrottle from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.decorators import (
api_view,
renderer_classes,
parser_classes,
authentication_classes,
throttle_classes,
permission_classes,
)
class DecoratorTestCase(TestCase): class DecoratorTestCase(TestCase):

View File

@ -1,12 +1,17 @@
# -- coding: utf-8 -- # -- coding: utf-8 --
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from django.utils.encoding import python_2_unicode_compatible, smart_text from django.utils.encoding import python_2_unicode_compatible, smart_text
from rest_framework.compat import apply_markdown from rest_framework.compat import apply_markdown
from rest_framework.views import APIView from rest_framework.views import APIView
from .description import ViewWithNonASCIICharactersInDocstring
from .description import UTF8_TEST_DOCSTRING from .description import (
UTF8_TEST_DOCSTRING, ViewWithNonASCIICharactersInDocstring
)
# We check that docstrings get nicely un-indented. # We check that docstrings get nicely un-indented.
DESCRIPTION = """an example docstring DESCRIPTION = """an example docstring

View File

@ -1,11 +1,13 @@
from decimal import Decimal
from django.utils import timezone
from rest_framework import serializers
import rest_framework
import datetime import datetime
import uuid
from decimal import Decimal
import django import django
import pytest import pytest
import uuid from django.utils import timezone
import rest_framework
from rest_framework import serializers
# Tests for field keyword arguments and core functionality. # Tests for field keyword arguments and core functionality.

View File

@ -1,19 +1,22 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime import datetime
from decimal import Decimal from decimal import Decimal
from django.db import models
from django.conf.urls import url from django.conf.urls import url
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils import unittest from django.utils import unittest
from django.utils.dateparse import parse_date from django.utils.dateparse import parse_date
from django.utils.six.moves import reload_module from django.utils.six.moves import reload_module
from rest_framework import generics, serializers, status, filters
from rest_framework import filters, generics, serializers, status
from rest_framework.compat import django_filters from rest_framework.compat import django_filters
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from .models import BaseFilterableItem, FilterableItem, BasicModel
from .models import BaseFilterableItem, BasicModel, FilterableItem
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,13 +1,16 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import django import django
from django.db import models from django.db import models
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from rest_framework import generics, renderers, serializers, status from rest_framework import generics, renderers, serializers, status
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from tests.models import BasicModel, RESTFrameworkModel from tests.models import (
from tests.models import ForeignKeySource, ForeignKeyTarget BasicModel, ForeignKeySource, ForeignKeyTarget, RESTFrameworkModel
)
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,15 +1,17 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.exceptions import PermissionDenied
import django.template.loader
from django.conf.urls import url from django.conf.urls import url
from django.core.exceptions import PermissionDenied
from django.http import Http404 from django.http import Http404
from django.template import Template, TemplateDoesNotExist
from django.test import TestCase from django.test import TestCase
from django.template import TemplateDoesNotExist, Template
from django.utils import six from django.utils import six
from rest_framework import status from rest_framework import status
from rest_framework.decorators import api_view, renderer_classes from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import TemplateHTMLRenderer from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response from rest_framework.response import Response
import django.template.loader
@api_view(('GET',)) @api_view(('GET',))

View File

@ -1,10 +1,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.core.validators import MinValueValidator, MaxValueValidator
from rest_framework import exceptions, metadata, serializers, status, views, versioning from rest_framework import (
from rest_framework.request import Request exceptions, metadata, serializers, status, versioning, views
)
from rest_framework.renderers import BrowsableAPIRenderer from rest_framework.renderers import BrowsableAPIRenderer
from rest_framework.request import Request
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
request = Request(APIRequestFactory().options('/')) request = Request(APIRequestFactory().options('/'))

View File

@ -1,12 +1,12 @@
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth.models import User from django.contrib.auth.models import User
from rest_framework.authentication import TokenAuthentication from rest_framework.authentication import TokenAuthentication
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from rest_framework.views import APIView from rest_framework.views import APIView
urlpatterns = [ urlpatterns = [
url(r'^$', APIView.as_view(authentication_classes=(TokenAuthentication,))), url(r'^$', APIView.as_view(authentication_classes=(TokenAuthentication,))),
] ]

View File

@ -6,15 +6,20 @@ These tests deal with ensuring that we correctly map the model fields onto
an appropriate set of serializer fields for each case. an appropriate set of serializer fields for each case.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import django import django
import pytest
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.core.validators import MaxValueValidator, MinValueValidator, MinLengthValidator from django.core.validators import (
MaxValueValidator, MinLengthValidator, MinValueValidator
)
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
import pytest
from rest_framework import serializers from rest_framework import serializers
from rest_framework.compat import unicode_repr, DurationField as ModelDurationField from rest_framework.compat import DurationField as ModelDurationField
from rest_framework.compat import unicode_repr
def dedent(blocktext): def dedent(blocktext):

View File

@ -1,6 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from rest_framework import serializers from rest_framework import serializers
from tests.models import RESTFrameworkModel from tests.models import RESTFrameworkModel

View File

@ -1,10 +1,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase
from rest_framework.negotiation import DefaultContentNegotiation
from rest_framework.request import Request
from rest_framework.renderers import BaseRenderer
from rest_framework.test import APIRequestFactory
from django.test import TestCase
from rest_framework.negotiation import DefaultContentNegotiation
from rest_framework.renderers import BaseRenderer
from rest_framework.request import Request
from rest_framework.test import APIRequestFactory
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,11 +1,15 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from rest_framework import exceptions, generics, pagination, serializers, status, filters
from rest_framework.request import Request
from rest_framework.pagination import PageLink, PAGE_BREAK
from rest_framework.test import APIRequestFactory
import pytest import pytest
from rest_framework import (
exceptions, filters, generics, pagination, serializers, status
)
from rest_framework.pagination import PAGE_BREAK, PageLink
from rest_framework.request import Request
from rest_framework.test import APIRequestFactory
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,12 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django import forms from django import forms
from django.core.files.uploadhandler import MemoryFileUploadHandler from django.core.files.uploadhandler import MemoryFileUploadHandler
from django.test import TestCase from django.test import TestCase
from django.utils.six.moves import StringIO from django.utils.six.moves import StringIO
from rest_framework.exceptions import ParseError from rest_framework.exceptions import ParseError
from rest_framework.parsers import FormParser, FileUploadParser from rest_framework.parsers import FileUploadParser, FormParser
class Form(forms.Form): class Form(forms.Form):

View File

@ -1,16 +1,22 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.auth.models import User, Permission, Group
import base64
from django.contrib.auth.models import Group, Permission, User
from django.core.urlresolvers import ResolverMatch
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.utils import unittest from django.utils import unittest
from rest_framework import generics, serializers, status, permissions, authentication, HTTP_HEADER_ENCODING
from rest_framework.compat import guardian, get_model_name from rest_framework import (
from django.core.urlresolvers import ResolverMatch HTTP_HEADER_ENCODING, authentication, generics, permissions, serializers,
status
)
from rest_framework.compat import get_model_name, guardian
from rest_framework.filters import DjangoObjectPermissionsFilter from rest_framework.filters import DjangoObjectPermissionsFilter
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from tests.models import BasicModel from tests.models import BasicModel
import base64
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,11 +1,16 @@
import uuid import uuid
from .utils import mock_reverse, fail_reverse, BadType, MockObject, MockQueryset
import pytest
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from rest_framework import serializers from rest_framework import serializers
from rest_framework.fields import empty from rest_framework.fields import empty
from rest_framework.test import APISimpleTestCase from rest_framework.test import APISimpleTestCase
import pytest
from .utils import (
BadType, MockObject, MockQueryset, fail_reverse, mock_reverse
)
class TestStringRelatedField(APISimpleTestCase): class TestStringRelatedField(APISimpleTestCase):

View File

@ -1,9 +1,13 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.contrib.contenttypes.generic import (
GenericForeignKey, GenericRelation
)
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.generic import GenericRelation, GenericForeignKey
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from rest_framework import serializers from rest_framework import serializers

View File

@ -1,11 +1,13 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
from django.test import TestCase from django.test import TestCase
from rest_framework import serializers from rest_framework import serializers
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from tests.models import ( from tests.models import (
ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, ForeignKeySource, ForeignKeyTarget, ManyToManySource, ManyToManyTarget,
NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource NullableForeignKeySource, NullableOneToOneSource, OneToOneTarget
) )
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,10 +1,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from rest_framework import serializers from rest_framework import serializers
from tests.models import ( from tests.models import (
ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, ForeignKeySource, ForeignKeyTarget, ManyToManySource, ManyToManyTarget,
NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource, NullableForeignKeySource, NullableOneToOneSource, OneToOneTarget
) )

View File

@ -1,6 +1,9 @@
from django.test import TestCase from django.test import TestCase
from rest_framework import serializers from rest_framework import serializers
from tests.models import NullableForeignKeySource, ForeignKeySource, ForeignKeyTarget from tests.models import (
ForeignKeySource, ForeignKeyTarget, NullableForeignKeySource
)
class ForeignKeyTargetSerializer(serializers.ModelSerializer): class ForeignKeyTargetSerializer(serializers.ModelSerializer):

View File

@ -1,25 +1,26 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, include
import json
import re
from collections import MutableMapping
from django.conf.urls import include, url
from django.core.cache import cache from django.core.cache import cache
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import status, permissions
from rest_framework import permissions, serializers, status
from rest_framework.compat import OrderedDict from rest_framework.compat import OrderedDict
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import serializers
from rest_framework.renderers import ( from rest_framework.renderers import (
BaseRenderer, JSONRenderer, BrowsableAPIRenderer, HTMLFormRenderer BaseRenderer, BrowsableAPIRenderer, HTMLFormRenderer, JSONRenderer
) )
from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from collections import MutableMapping from rest_framework.views import APIView
import json
import re
DUMMYSTATUS = status.HTTP_200_OK DUMMYSTATUS = status.HTTP_200_OK
DUMMYCONTENT = 'dummycontent' DUMMYCONTENT = 'dummycontent'

View File

@ -2,31 +2,30 @@
Tests for content parsing, and form-overloaded content parsing. Tests for content parsing, and form-overloaded content parsing.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import json
from io import BytesIO
import django
import pytest
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.core.handlers.wsgi import WSGIRequest from django.core.handlers.wsgi import WSGIRequest
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from rest_framework import status from rest_framework import status
from rest_framework.authentication import SessionAuthentication from rest_framework.authentication import SessionAuthentication
from rest_framework.parsers import ( from rest_framework.parsers import (
BaseParser, BaseParser, FormParser, JSONParser, MultiPartParser
FormParser,
MultiPartParser,
JSONParser
) )
from rest_framework.request import Request, Empty from rest_framework.request import Empty, Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.test import APIRequestFactory, APIClient from rest_framework.test import APIClient, APIRequestFactory
from rest_framework.views import APIView from rest_framework.views import APIView
from io import BytesIO
import json
import django
import pytest
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,21 +1,17 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, include
from django.conf.urls import include, url
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from tests.models import BasicModel
from rest_framework.response import Response from rest_framework import generics, routers, serializers, status, viewsets
from rest_framework.views import APIView
from rest_framework import generics
from rest_framework import routers
from rest_framework import serializers
from rest_framework import status
from rest_framework.renderers import ( from rest_framework.renderers import (
BaseRenderer, BaseRenderer, BrowsableAPIRenderer, JSONRenderer
JSONRenderer,
BrowsableAPIRenderer
) )
from rest_framework import viewsets from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.views import APIView
from tests.models import BasicModel
# Serializer used to test BasicModel # Serializer used to test BasicModel

View File

@ -1,7 +1,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
from django.core.urlresolvers import NoReverseMatch from django.core.urlresolvers import NoReverseMatch
from django.test import TestCase from django.test import TestCase
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory

View File

@ -1,14 +1,17 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf.urls import url, include
from collections import namedtuple
from django.conf.urls import include, url
from django.core.exceptions import ImproperlyConfigured
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from django.core.exceptions import ImproperlyConfigured
from rest_framework import serializers, viewsets, permissions from rest_framework import permissions, serializers, viewsets
from rest_framework.decorators import detail_route, list_route from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.routers import SimpleRouter, DefaultRouter from rest_framework.routers import DefaultRouter, SimpleRouter
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from collections import namedtuple
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,10 +1,14 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from .utils import MockObject
import pickle
import pytest
from rest_framework import serializers from rest_framework import serializers
from rest_framework.compat import unicode_repr from rest_framework.compat import unicode_repr
import pickle
import pytest from .utils import MockObject
# Tests for core functionality. # Tests for core functionality.

View File

@ -2,8 +2,10 @@
Tests to cover bulk create and update using serializers. Tests to cover bulk create and update using serializers.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from rest_framework import serializers from rest_framework import serializers

View File

@ -1,6 +1,7 @@
from rest_framework import serializers
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from rest_framework import serializers
class BasicObject: class BasicObject:
""" """

View File

@ -1,5 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from rest_framework.settings import APISettings from rest_framework.settings import APISettings

View File

@ -1,7 +1,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from rest_framework.status import ( from rest_framework.status import (
is_informational, is_success, is_redirect, is_client_error, is_server_error is_client_error, is_informational, is_redirect, is_server_error,
is_success
) )

View File

@ -1,9 +1,12 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase
from rest_framework.test import APIRequestFactory
from rest_framework.templatetags.rest_framework import add_query_param, urlize_quoted_links
from django.test import TestCase
from rest_framework.templatetags.rest_framework import (
add_query_param, urlize_quoted_links
)
from rest_framework.test import APIRequestFactory
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,13 +1,18 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from io import BytesIO
from django.conf.urls import url from django.conf.urls import url
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.shortcuts import redirect from django.shortcuts import redirect
from django.test import TestCase from django.test import TestCase
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.test import APIClient, APIRequestFactory, force_authenticate from rest_framework.test import (
from io import BytesIO APIClient, APIRequestFactory, force_authenticate
)
@api_view(['GET', 'POST']) @api_view(['GET', 'POST'])

View File

@ -2,14 +2,18 @@
Tests for the throttling implementations in the permissions module. Tests for the throttling implementations in the permissions module.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.cache import cache from django.core.cache import cache
from django.test import TestCase
from rest_framework.response import Response
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from rest_framework.throttling import (
BaseThrottle, ScopedRateThrottle, UserRateThrottle
)
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.throttling import BaseThrottle, UserRateThrottle, ScopedRateThrottle
from rest_framework.response import Response
class User3SecRateThrottle(UserRateThrottle): class User3SecRateThrottle(UserRateThrottle):

View File

@ -1,12 +1,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from collections import namedtuple from collections import namedtuple
from django.conf.urls import url, include
from django.conf.urls import include, url
from django.core import urlresolvers from django.core import urlresolvers
from django.test import TestCase from django.test import TestCase
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from rest_framework.urlpatterns import format_suffix_patterns from rest_framework.urlpatterns import format_suffix_patterns
# A container class for test paths for the test case # A container class for test paths for the test case
URLTestPath = namedtuple('URLTestPath', ['path', 'args', 'kwargs']) URLTestPath = namedtuple('URLTestPath', ['path', 'args', 'kwargs'])

View File

@ -1,14 +1,15 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.exceptions import ImproperlyConfigured
from django.conf.urls import url from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase from django.test import TestCase
from django.utils import six from django.utils import six
from rest_framework.utils.model_meta import _resolve_model
from rest_framework.utils.breadcrumbs import get_breadcrumbs
from rest_framework.views import APIView
from tests.models import BasicModel
import rest_framework.utils.model_meta import rest_framework.utils.model_meta
from rest_framework.utils.breadcrumbs import get_breadcrumbs
from rest_framework.utils.model_meta import _resolve_model
from rest_framework.views import APIView
from tests.models import BasicModel
class Root(APIView): class Root(APIView):

View File

@ -1,10 +1,13 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.validators import RegexValidator, MaxValueValidator
import re
from django.core.validators import MaxValueValidator, RegexValidator
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from rest_framework import generics, serializers, status from rest_framework import generics, serializers, status
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
import re
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,7 +1,9 @@
import datetime
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from rest_framework import serializers from rest_framework import serializers
import datetime
def dedent(blocktext): def dedent(blocktext):

View File

@ -1,14 +1,15 @@
from .utils import UsingURLPatterns import pytest
from django.conf.urls import include, url from django.conf.urls import include, url
from rest_framework import serializers
from rest_framework import status, versioning from rest_framework import serializers, status, versioning
from rest_framework.decorators import APIView from rest_framework.decorators import APIView
from rest_framework.relations import PKOnlyObject
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.test import APIRequestFactory, APITestCase from rest_framework.test import APIRequestFactory, APITestCase
from rest_framework.versioning import NamespaceVersioning from rest_framework.versioning import NamespaceVersioning
from rest_framework.relations import PKOnlyObject
import pytest from .utils import UsingURLPatterns
class RequestVersionView(APIView): class RequestVersionView(APIView):

View File

@ -1,8 +1,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import sys
import copy import copy
import sys
from django.test import TestCase from django.test import TestCase
from rest_framework import status from rest_framework import status
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.response import Response from rest_framework.response import Response

View File

@ -1,10 +1,10 @@
from django.test import TestCase from django.test import TestCase
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from rest_framework.viewsets import GenericViewSet from rest_framework.viewsets import GenericViewSet
factory = APIRequestFactory() factory = APIRequestFactory()

View File

@ -1,4 +1,5 @@
from django.test import TestCase from django.test import TestCase
from rest_framework import serializers from rest_framework import serializers

View File

@ -3,7 +3,7 @@ addopts=--tb=short
[tox] [tox]
envlist = envlist =
py27-{flake8,docs}, py27-{lint,docs},
{py26,py27}-django14, {py26,py27}-django14,
{py26,py27,py32,py33,py34}-django{15,16}, {py26,py27,py32,py33,py34}-django{15,16},
{py27,py32,py33,py34}-django{17,18,master} {py27,py32,py33,py34}-django{17,18,master}
@ -22,14 +22,14 @@ deps =
-rrequirements/requirements-testing.txt -rrequirements/requirements-testing.txt
-rrequirements/requirements-optionals.txt -rrequirements/requirements-optionals.txt
[testenv:py27-flake8] [testenv:py27-lint]
commands = ./runtests.py --lintonly
deps = deps =
-rrequirements/requirements-codestyle.txt -rrequirements/requirements-codestyle.txt
-rrequirements/requirements-testing.txt -rrequirements/requirements-testing.txt
commands = ./runtests.py --lintonly
[testenv:py27-docs] [testenv:py27-docs]
commands = mkdocs build
deps = deps =
-rrequirements/requirements-testing.txt -rrequirements/requirements-testing.txt
-rrequirements/requirements-documentation.txt -rrequirements/requirements-documentation.txt
commands = mkdocs build