From 7351a3f6ca7028868a79a6f2dae36ccb2fc7dd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Padilla?= Date: Thu, 25 Jun 2015 16:55:51 -0400 Subject: [PATCH] Sort imports with isort --- rest_framework/authentication.py | 4 +-- .../authtoken/migrations/0001_initial.py | 2 +- rest_framework/authtoken/models.py | 5 ++- rest_framework/authtoken/views.py | 4 +-- rest_framework/compat.py | 8 ++--- rest_framework/exceptions.py | 3 +- rest_framework/fields.py | 33 +++++++++---------- rest_framework/filters.py | 7 ++-- rest_framework/generics.py | 4 +-- rest_framework/metadata.py | 2 +- rest_framework/negotiation.py | 2 +- rest_framework/pagination.py | 15 ++++----- rest_framework/parsers.py | 13 ++++---- rest_framework/permissions.py | 1 - rest_framework/relations.py | 20 +++++------ rest_framework/renderers.py | 22 ++++++------- rest_framework/request.py | 4 +-- rest_framework/response.py | 2 +- rest_framework/reverse.py | 3 +- rest_framework/routers.py | 7 ++-- rest_framework/serializers.py | 24 ++++++-------- rest_framework/settings.py | 3 +- rest_framework/templatetags/rest_framework.py | 10 +++--- rest_framework/test.py | 10 +++--- rest_framework/urlpatterns.py | 2 +- rest_framework/urls.py | 1 - rest_framework/utils/breadcrumbs.py | 2 +- rest_framework/utils/encoders.py | 10 +++--- rest_framework/utils/field_mapping.py | 3 +- rest_framework/utils/model_meta.py | 5 ++- rest_framework/utils/representation.py | 2 +- rest_framework/versioning.py | 4 +-- rest_framework/views.py | 14 ++++---- rest_framework/viewsets.py | 2 +- setup.py | 3 +- tests/browsable_api/auth_urls.py | 4 +-- tests/browsable_api/no_auth_urls.py | 1 + tests/browsable_api/test_browsable_api.py | 1 + tests/browsable_api/views.py | 5 ++- tests/description.py | 1 - tests/test_atomic_requests.py | 4 +-- tests/test_authentication.py | 25 +++++++------- tests/test_decorators.py | 16 ++++----- tests/test_description.py | 9 +++-- tests/test_fields.py | 12 ++++--- tests/test_filters.py | 9 +++-- tests/test_generics.py | 7 ++-- tests/test_htmlrenderer.py | 8 +++-- tests/test_metadata.py | 10 ++++-- tests/test_middleware.py | 2 +- tests/test_model_serializer.py | 11 +++++-- tests/test_multitable_inheritance.py | 2 ++ tests/test_negotiation.py | 11 ++++--- tests/test_pagination.py | 12 ++++--- tests/test_parsers.py | 4 ++- tests/test_permissions.py | 16 ++++++--- tests/test_relations.py | 9 +++-- tests/test_relations_generic.py | 6 +++- tests/test_relations_hyperlink.py | 6 ++-- tests/test_relations_pk.py | 6 ++-- tests/test_relations_slug.py | 5 ++- tests/test_renderers.py | 21 ++++++------ tests/test_request.py | 23 +++++++------ tests/test_response.py | 20 +++++------ tests/test_reverse.py | 2 ++ tests/test_routers.py | 13 +++++--- tests/test_serializer.py | 10 ++++-- tests/test_serializer_bulk_update.py | 2 ++ tests/test_serializer_lists.py | 3 +- tests/test_settings.py | 2 ++ tests/test_status.py | 5 ++- tests/test_templatetags.py | 9 +++-- tests/test_testing.py | 9 +++-- tests/test_throttling.py | 10 ++++-- tests/test_urlpatterns.py | 6 ++-- tests/test_utils.py | 11 ++++--- tests/test_validation.py | 7 ++-- tests/test_validators.py | 4 ++- tests/test_versioning.py | 11 ++++--- tests/test_views.py | 4 ++- tests/test_viewsets.py | 2 +- tests/test_write_only_fields.py | 1 + 82 files changed, 355 insertions(+), 278 deletions(-) diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 74c6b342b..088eac4ca 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -9,9 +9,9 @@ from django.contrib.auth import authenticate from django.middleware.csrf import CsrfViewMiddleware from django.utils.translation import ugettext_lazy as _ -from rest_framework.compat import get_user_model +from rest_framework import HTTP_HEADER_ENCODING, exceptions from rest_framework.authtoken.models import Token -from rest_framework import exceptions, HTTP_HEADER_ENCODING +from rest_framework.compat import get_user_model def get_authorization_header(request): diff --git a/rest_framework/authtoken/migrations/0001_initial.py b/rest_framework/authtoken/migrations/0001_initial.py index 769f62029..0eb9fbcbe 100644 --- a/rest_framework/authtoken/migrations/0001_initial.py +++ b/rest_framework/authtoken/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/rest_framework/authtoken/models.py b/rest_framework/authtoken/models.py index f3e01a4b7..b329ee65f 100644 --- a/rest_framework/authtoken/models.py +++ b/rest_framework/authtoken/models.py @@ -1,11 +1,10 @@ -import os import binascii +import os -from django.db import models from django.conf import settings +from django.db import models from django.utils.encoding import python_2_unicode_compatible - # 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 # bug report #1297 diff --git a/rest_framework/authtoken/views.py b/rest_framework/authtoken/views.py index 26df9e11c..743684057 100644 --- a/rest_framework/authtoken/views.py +++ b/rest_framework/authtoken/views.py @@ -1,8 +1,8 @@ from rest_framework import parsers, renderers -from rest_framework.views import APIView -from rest_framework.response import Response from rest_framework.authtoken.models import Token from rest_framework.authtoken.serializers import AuthTokenSerializer +from rest_framework.response import Response +from rest_framework.views import APIView class ObtainAuthToken(APIView): diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 28e72cfe8..d11c68093 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -9,11 +9,12 @@ from __future__ import unicode_literals import inspect import django -from django.utils import six from django.conf import settings -from django.db import connection, transaction -from django.utils.encoding import force_text from django.core.exceptions import ImproperlyConfigured +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.six.moves.urllib.parse import urlparse as _urlparse try: @@ -202,7 +203,6 @@ if 'patch' not in View.http_method_names: View.http_method_names = View.http_method_names + ['patch'] -from django.test.client import FakePayload try: # In 1.5 the test client uses force_bytes diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 9a467f987..f587d10fd 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -10,7 +10,8 @@ import math from django.utils import six 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 diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 3794329b7..7960295bd 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1,34 +1,33 @@ from __future__ import unicode_literals -import re +import collections import copy -import uuid +import datetime import decimal import inspect -import datetime -import collections +import re +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 django.forms import ImageField as DjangoImageField -from django.utils.encoding import is_protected_type, smart_text -from django.core.validators import RegexValidator, ip_address_validators -from django.utils.dateparse import parse_date, parse_datetime, parse_time -from django.core.exceptions import ( - ObjectDoesNotExist, ValidationError as DjangoValidationError -) from rest_framework import ISO_8601 -from rest_framework.settings import api_settings -from rest_framework.exceptions import ValidationError -from rest_framework.utils import html, representation, humanize_datetime from rest_framework.compat import ( - EmailValidator, MinValueValidator, MaxValueValidator, - MinLengthValidator, MaxLengthValidator, URLValidator, OrderedDict, - unicode_repr, unicode_to_repr, parse_duration, duration_string, + 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: diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 7976d06da..294d1b22b 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -7,13 +7,12 @@ from __future__ import unicode_literals import operator from functools import reduce -from django.utils import six -from django.db import models from django.core.exceptions import ImproperlyConfigured +from django.db import models +from django.utils import six +from rest_framework.compat import django_filters, get_model_name, guardian from rest_framework.settings import api_settings -from rest_framework.compat import django_filters, guardian, get_model_name - FilterSet = django_filters and django_filters.FilterSet or None diff --git a/rest_framework/generics.py b/rest_framework/generics.py index 20eb120cc..88438e8c4 100644 --- a/rest_framework/generics.py +++ b/rest_framework/generics.py @@ -3,11 +3,11 @@ Generic views that provide commonly needed behaviour. """ from __future__ import unicode_literals -from django.http import Http404 from django.db.models.query import QuerySet +from django.http import Http404 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 diff --git a/rest_framework/metadata.py b/rest_framework/metadata.py index df2c9d553..3c7b3d2ab 100644 --- a/rest_framework/metadata.py +++ b/rest_framework/metadata.py @@ -8,9 +8,9 @@ to return this information in a more standardized way. """ from __future__ import unicode_literals +from django.core.exceptions import PermissionDenied from django.http import Http404 from django.utils.encoding import force_text -from django.core.exceptions import PermissionDenied from rest_framework import exceptions, serializers from rest_framework.compat import OrderedDict diff --git a/rest_framework/negotiation.py b/rest_framework/negotiation.py index 0ec1936c7..b9263c447 100644 --- a/rest_framework/negotiation.py +++ b/rest_framework/negotiation.py @@ -9,7 +9,7 @@ from django.http import Http404 from rest_framework import HTTP_HEADER_ENCODING, exceptions from rest_framework.settings import api_settings from rest_framework.utils.mediatypes import ( - _MediaType, order_by_precedence, media_type_matches + _MediaType, media_type_matches, order_by_precedence ) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 8e45e9e6b..bea10d036 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -6,22 +6,21 @@ be used for paginated responses. from __future__ import unicode_literals import warnings -from base64 import b64encode, b64decode +from base64 import b64decode, b64encode from collections import namedtuple -from django.utils import six +from django.core.paginator import Paginator as DjangoPaginator +from django.core.paginator import InvalidPage from django.template import Context, loader -from django.utils.translation import ugettext_lazy as _ +from django.utils import six from django.utils.six.moves.urllib import parse as urlparse -from django.core.paginator import InvalidPage, Paginator as DjangoPaginator +from django.utils.translation import ugettext_lazy as _ -from rest_framework.response import Response from rest_framework.compat import OrderedDict from rest_framework.exceptions import NotFound +from rest_framework.response import Response from rest_framework.settings import api_settings -from rest_framework.utils.urls import ( - replace_query_param, remove_query_param -) +from rest_framework.utils.urls import remove_query_param, replace_query_param def _positive_int(integer_string, strict=False, cutoff=None): diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index 3cc820857..2dc808f1a 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -8,16 +8,17 @@ from __future__ import unicode_literals import json -from django.utils import six from django.conf import settings +from django.core.files.uploadhandler import StopFutureHandlers from django.http import QueryDict +from django.http.multipartparser import \ + MultiPartParser as DjangoMultiPartParser +from django.http.multipartparser import ( + ChunkIter, MultiPartParserError, parse_header +) +from django.utils import six from django.utils.encoding import force_text from django.utils.six.moves.urllib import parse as urlparse -from django.core.files.uploadhandler import StopFutureHandlers -from django.http.multipartparser import ( - MultiPartParserError, parse_header, ChunkIter, - MultiPartParser as DjangoMultiPartParser -) from rest_framework import renderers from rest_framework.exceptions import ParseError diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py index 84df78148..628538903 100644 --- a/rest_framework/permissions.py +++ b/rest_framework/permissions.py @@ -7,7 +7,6 @@ from django.http import Http404 from rest_framework.compat import get_model_name - SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS') diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 36e9cf71f..ca39dbade 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -1,20 +1,20 @@ # coding: utf-8 from __future__ import unicode_literals -from django.utils import six -from django.db.models.query import QuerySet -from django.utils.encoding import smart_text -from django.utils.translation import ugettext_lazy as _ -from django.utils.six.moves.urllib import parse as urlparse -from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured +from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist from django.core.urlresolvers import ( - get_script_prefix, resolve, NoReverseMatch, Resolver404 + NoReverseMatch, Resolver404, get_script_prefix, resolve ) +from django.db.models.query import QuerySet +from django.utils import six +from django.utils.encoding import smart_text +from django.utils.six.moves.urllib import parse as urlparse +from django.utils.translation import ugettext_lazy as _ -from rest_framework.utils import html -from rest_framework.reverse import reverse 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.utils import html class PKOnlyObject(object): diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 5fca5c12f..6e1370b72 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -12,23 +12,23 @@ import json import django from django import forms -from django.utils import six -from django.core.paginator import Page -from django.test.client import encode_multipart -from django.http.multipartparser import parse_header from django.core.exceptions import ImproperlyConfigured -from django.template import Context, RequestContext, loader, Template +from django.core.paginator import Page +from django.http.multipartparser import parse_header +from django.template import Context, RequestContext, Template, loader +from django.test.client import encode_multipart +from django.utils import six -from rest_framework.utils import encoders +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.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.breadcrumbs import get_breadcrumbs from rest_framework.utils.field_mapping import ClassLookupDict -from rest_framework import exceptions, serializers, status, VERSION -from rest_framework.request import is_form_media_type, override_method -from rest_framework.compat import ( - SHORT_SEPARATORS, LONG_SEPARATORS, INDENT_SEPARATORS -) def zero_as_none(value): diff --git a/rest_framework/request.py b/rest_framework/request.py index 614b73abf..568ba1b50 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -13,13 +13,13 @@ from __future__ import unicode_literals import sys import warnings -from django.utils import six from django.conf import settings from django.http import QueryDict from django.http.multipartparser import parse_header +from django.utils import six from django.utils.datastructures import MultiValueDict -from rest_framework import exceptions, HTTP_HEADER_ENCODING +from rest_framework import HTTP_HEADER_ENCODING, exceptions from rest_framework.settings import api_settings diff --git a/rest_framework/response.py b/rest_framework/response.py index e7f4cd3d1..47d947655 100644 --- a/rest_framework/response.py +++ b/rest_framework/response.py @@ -6,9 +6,9 @@ The appropriate renderer is called during Django's template response rendering. """ from __future__ import unicode_literals +from django.template.response import SimpleTemplateResponse from django.utils import six from django.utils.six.moves.http_client import responses -from django.template.response import SimpleTemplateResponse class Response(SimpleTemplateResponse): diff --git a/rest_framework/reverse.py b/rest_framework/reverse.py index c13b4819a..dae4b8212 100644 --- a/rest_framework/reverse.py +++ b/rest_framework/reverse.py @@ -3,9 +3,10 @@ Provide urlresolver functions that return fully qualified URLs or view names """ from __future__ import unicode_literals +from django.core.urlresolvers import reverse as django_reverse +from django.core.urlresolvers import NoReverseMatch from django.utils import six from django.utils.functional import lazy -from django.core.urlresolvers import NoReverseMatch, reverse as django_reverse def reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra): diff --git a/rest_framework/routers.py b/rest_framework/routers.py index f92cca004..380f3bb4f 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -19,16 +19,15 @@ import itertools from collections import namedtuple from django.conf.urls import url -from django.core.urlresolvers import NoReverseMatch from django.core.exceptions import ImproperlyConfigured +from django.core.urlresolvers import NoReverseMatch from rest_framework import views -from rest_framework.reverse import reverse +from rest_framework.compat import OrderedDict, get_resolver_match from rest_framework.response import Response -from rest_framework.compat import get_resolver_match, OrderedDict +from rest_framework.reverse import reverse from rest_framework.urlpatterns import format_suffix_patterns - Route = namedtuple('Route', ['url', 'mapping', 'name', 'initkwargs']) DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs']) DynamicListRoute = namedtuple('DynamicListRoute', ['url', 'name', 'initkwargs']) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index d4a26750d..3a452bcc1 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -15,29 +15,26 @@ from __future__ import unicode_literals import warnings from django.db import models +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.translation import ugettext_lazy as _ -from django.db.models.fields import ( - FieldDoesNotExist, Field as DjangoModelField -) +from rest_framework.compat import DurationField as ModelDurationField +from rest_framework.compat import postgres_fields, unicode_to_repr from rest_framework.utils import model_meta -from rest_framework.compat import ( - postgres_fields, unicode_to_repr, DurationField as ModelDurationField, +from rest_framework.utils.field_mapping import ( + ClassLookupDict, get_field_kwargs, get_nested_relation_kwargs, + get_relation_kwargs, get_url_kwargs ) from rest_framework.utils.serializer_helpers import ( - ReturnDict, ReturnList, BoundField, NestedBoundField, BindingDict -) -from rest_framework.utils.field_mapping import ( - get_url_kwargs, get_field_kwargs, get_relation_kwargs, - get_nested_relation_kwargs, ClassLookupDict + BindingDict, BoundField, NestedBoundField, ReturnDict, ReturnList ) from rest_framework.validators import ( UniqueForDateValidator, UniqueForMonthValidator, UniqueForYearValidator, UniqueTogetherValidator ) - # Note: We do the following so that users of the framework can use this style: # # example_field = serializers.CharField(...) @@ -45,9 +42,8 @@ from rest_framework.validators import ( # This helps keep the separation between model fields, form fields, and # serializer fields more explicit. -from rest_framework.relations import * # NOQA -from rest_framework.fields import * # NOQA - +from rest_framework.fields import * # NOQA # isort:skip +from rest_framework.relations import * # NOQA # isort:skip # We assume that 'validators' are intended for the child serializer, # rather than the parent serializer. diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 515e4aecb..4c46a4831 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -19,14 +19,13 @@ back to the defaults. """ from __future__ import unicode_literals -from django.utils import six from django.conf import settings from django.test.signals import setting_changed +from django.utils import six from rest_framework import ISO_8601 from rest_framework.compat import importlib - USER_SETTINGS = getattr(settings, 'REST_FRAMEWORK', None) DEFAULTS = { diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 7e9110d8f..3018489fb 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -1,19 +1,17 @@ -from __future__ import unicode_literals, absolute_import +from __future__ import absolute_import, unicode_literals import re from django import template +from django.core.urlresolvers import NoReverseMatch, reverse from django.utils import six -from django.utils.html import escape -from django.utils.html import smart_urlquote +from django.utils.encoding import force_text, iri_to_uri +from django.utils.html import escape, smart_urlquote from django.utils.safestring import SafeData, mark_safe -from django.utils.encoding import iri_to_uri, force_text -from django.core.urlresolvers import reverse, NoReverseMatch from rest_framework.renderers import HTMLFormRenderer from rest_framework.utils.urls import replace_query_param - register = template.Library() # Regex for adding classes to html snippets diff --git a/rest_framework/test.py b/rest_framework/test.py index 60c697814..92ac09f58 100644 --- a/rest_framework/test.py +++ b/rest_framework/test.py @@ -5,16 +5,16 @@ from __future__ import unicode_literals import django -from django.utils import six from django.conf import settings from django.test import testcases +from django.test.client import Client as DjangoClient +from django.test.client import ClientHandler +from django.utils import six from django.utils.http import urlencode -from django.test.client import ClientHandler, Client as DjangoClient +from rest_framework.compat import RequestFactory as DjangoRequestFactory +from rest_framework.compat import force_bytes_or_smart_bytes from rest_framework.settings import api_settings -from rest_framework.compat import ( - force_bytes_or_smart_bytes, RequestFactory as DjangoRequestFactory -) def force_authenticate(request, user=None, token=None): diff --git a/rest_framework/urlpatterns.py b/rest_framework/urlpatterns.py index 7b1516265..5347b3bc1 100644 --- a/rest_framework/urlpatterns.py +++ b/rest_framework/urlpatterns.py @@ -1,6 +1,6 @@ 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 rest_framework.settings import api_settings diff --git a/rest_framework/urls.py b/rest_framework/urls.py index 111524233..d88ee8dbd 100644 --- a/rest_framework/urls.py +++ b/rest_framework/urls.py @@ -17,7 +17,6 @@ from __future__ import unicode_literals from django.conf.urls import url from django.contrib.auth import views - template_name = {'template_name': 'rest_framework/login.html'} urlpatterns = [ diff --git a/rest_framework/utils/breadcrumbs.py b/rest_framework/utils/breadcrumbs.py index af786810f..65daea08f 100644 --- a/rest_framework/utils/breadcrumbs.py +++ b/rest_framework/utils/breadcrumbs.py @@ -1,6 +1,6 @@ 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): diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index 62bbfaff9..949c99eda 100644 --- a/rest_framework/utils/encoders.py +++ b/rest_framework/utils/encoders.py @@ -3,15 +3,15 @@ Helper classes for parsers. """ from __future__ import unicode_literals -import uuid -import json -import decimal import datetime +import decimal +import json +import uuid -from django.utils import six, timezone from django.db.models.query import QuerySet -from django.utils.functional import Promise +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 diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 8fcb8c332..38c433155 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -4,14 +4,13 @@ keyword arguments that should be used for their equivelent serializer fields. """ import inspect -from django.db import models from django.core import validators +from django.db import models from django.utils.text import capfirst from rest_framework.compat import clean_manytomany_helptext from rest_framework.validators import UniqueValidator - NUMERIC_FIELD_TYPES = ( models.IntegerField, models.FloatField, models.DecimalField ) diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py index 9fe2e7069..3bcd9049c 100644 --- a/rest_framework/utils/model_meta.py +++ b/rest_framework/utils/model_meta.py @@ -8,13 +8,12 @@ Usage: `get_field_info(model)` returns a `FieldInfo` instance. import inspect from collections import namedtuple -from django.utils import six -from django.db import models from django.core.exceptions import ImproperlyConfigured +from django.db import models +from django.utils import six from rest_framework.compat import OrderedDict - FieldInfo = namedtuple('FieldResult', [ 'pk', # Model field instance 'fields', # Dict of field name -> model field instance diff --git a/rest_framework/utils/representation.py b/rest_framework/utils/representation.py index 1bd579f62..920751719 100644 --- a/rest_framework/utils/representation.py +++ b/rest_framework/utils/representation.py @@ -7,8 +7,8 @@ from __future__ import unicode_literals import re from django.db import models -from django.utils.functional import Promise from django.utils.encoding import force_text +from django.utils.functional import Promise from rest_framework.compat import unicode_repr diff --git a/rest_framework/versioning.py b/rest_framework/versioning.py index 4ee6e2546..7b1422c92 100644 --- a/rest_framework/versioning.py +++ b/rest_framework/versioning.py @@ -6,11 +6,11 @@ import re from django.utils.translation import ugettext_lazy as _ from rest_framework import exceptions +from rest_framework.compat import unicode_http_header from rest_framework.reverse import _reverse from rest_framework.settings import api_settings -from rest_framework.compat import unicode_http_header -from rest_framework.utils.mediatypes import _MediaType from rest_framework.templatetags.rest_framework import replace_query_param +from rest_framework.utils.mediatypes import _MediaType class BaseVersioning(object): diff --git a/rest_framework/views.py b/rest_framework/views.py index 2230c6dc6..a709c2f6b 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -6,19 +6,19 @@ from __future__ import unicode_literals import inspect import warnings -from django.utils import six -from django.http import Http404 -from django.utils.encoding import smart_text from django.core.exceptions import PermissionDenied -from django.views.decorators.csrf import csrf_exempt +from django.http import Http404 +from django.utils import six +from django.utils.encoding import smart_text from django.utils.translation import ugettext_lazy as _ +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.request import Request -from rest_framework.utils import formatting from rest_framework.response import Response from rest_framework.settings import api_settings -from rest_framework.compat import HttpResponseBase, View, set_rollback +from rest_framework.utils import formatting def get_view_name(view_cls, suffix=None): diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index e9fa41fbc..e1c5e17f6 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -23,7 +23,7 @@ from functools import update_wrapper from django.utils.decorators import classonlymethod 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): diff --git a/setup.py b/setup.py index ca802774d..2dfcbc5bd 100755 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import re import os +import re import sys + from setuptools import setup diff --git a/tests/browsable_api/auth_urls.py b/tests/browsable_api/auth_urls.py index aa3958b0b..0e9379717 100644 --- a/tests/browsable_api/auth_urls.py +++ b/tests/browsable_api/auth_urls.py @@ -1,9 +1,9 @@ from __future__ import unicode_literals -from django.conf.urls import url, include + +from django.conf.urls import include, url from .views import MockView - urlpatterns = [ url(r'^$', MockView.as_view()), url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')), diff --git a/tests/browsable_api/no_auth_urls.py b/tests/browsable_api/no_auth_urls.py index ec273f91c..5fc95c727 100644 --- a/tests/browsable_api/no_auth_urls.py +++ b/tests/browsable_api/no_auth_urls.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals from django.conf.urls import url + from .views import MockView urlpatterns = [ diff --git a/tests/browsable_api/test_browsable_api.py b/tests/browsable_api/test_browsable_api.py index 5f2647838..a9e14f677 100644 --- a/tests/browsable_api/test_browsable_api.py +++ b/tests/browsable_api/test_browsable_api.py @@ -1,4 +1,5 @@ from __future__ import unicode_literals + from django.contrib.auth.models import User from django.test import TestCase diff --git a/tests/browsable_api/views.py b/tests/browsable_api/views.py index 000f4e804..cd020cd32 100644 --- a/tests/browsable_api/views.py +++ b/tests/browsable_api/views.py @@ -1,9 +1,8 @@ from __future__ import unicode_literals -from rest_framework.views import APIView -from rest_framework import authentication -from rest_framework import renderers +from rest_framework import authentication, renderers from rest_framework.response import Response +from rest_framework.views import APIView class MockView(APIView): diff --git a/tests/description.py b/tests/description.py index b46d7f54d..55a55a9f6 100644 --- a/tests/description.py +++ b/tests/description.py @@ -8,7 +8,6 @@ from rest_framework.views import APIView - # test strings snatched from http://www.columbia.edu/~fdc/utf8/, # http://winrus.com/utf8-jap.htm and memory UTF8_TEST_DOCSTRING = ( diff --git a/tests/test_atomic_requests.py b/tests/test_atomic_requests.py index b74f2179e..d0d088f52 100644 --- a/tests/test_atomic_requests.py +++ b/tests/test_atomic_requests.py @@ -2,10 +2,11 @@ from __future__ import unicode_literals from django.conf.urls import patterns, url from django.db import connection, connections, transaction -from django.test import TestCase, TransactionTestCase from django.http import Http404 +from django.test import TestCase, TransactionTestCase from django.utils.decorators import method_decorator from django.utils.unittest import skipUnless + from rest_framework import status from rest_framework.exceptions import APIException from rest_framework.response import Response @@ -13,7 +14,6 @@ from rest_framework.test import APIRequestFactory from rest_framework.views import APIView from tests.models import BasicModel - factory = APIRequestFactory() diff --git a/tests/test_authentication.py b/tests/test_authentication.py index f5d91da3d..91434124e 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -1,27 +1,26 @@ # coding: utf-8 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.http import HttpResponse from django.test import TestCase from django.utils import six -from rest_framework import HTTP_HEADER_ENCODING -from rest_framework import exceptions -from rest_framework import permissions -from rest_framework import renderers -from rest_framework.response import Response -from rest_framework import status + +from rest_framework import ( + HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status +) from rest_framework.authentication import ( - BaseAuthentication, - TokenAuthentication, - BasicAuthentication, - SessionAuthentication, + BaseAuthentication, BasicAuthentication, SessionAuthentication, + TokenAuthentication ) 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 -import base64 factory = APIRequestFactory() diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 195f0ba3e..46e4a6ad7 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -1,22 +1,20 @@ from __future__ import unicode_literals + from django.test import TestCase + from rest_framework import status 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.permissions import IsAuthenticated -from rest_framework.response import Response from rest_framework.renderers import JSONRenderer +from rest_framework.response import Response from rest_framework.test import APIRequestFactory from rest_framework.throttling import UserRateThrottle 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): diff --git a/tests/test_description.py b/tests/test_description.py index 78ce2350b..d0ca40762 100644 --- a/tests/test_description.py +++ b/tests/test_description.py @@ -1,12 +1,17 @@ # -- coding: utf-8 -- from __future__ import unicode_literals + from django.test import TestCase from django.utils.encoding import python_2_unicode_compatible, smart_text + from rest_framework.compat import apply_markdown 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. DESCRIPTION = """an example docstring diff --git a/tests/test_fields.py b/tests/test_fields.py index 1c4228d3a..76e6d9d60 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,11 +1,13 @@ -from decimal import Decimal -from django.utils import timezone -from rest_framework import serializers -import rest_framework import datetime +import uuid +from decimal import Decimal + import django 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. diff --git a/tests/test_filters.py b/tests/test_filters.py index c06160f9c..9db685c28 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -1,19 +1,22 @@ from __future__ import unicode_literals + import datetime from decimal import Decimal -from django.db import models + from django.conf.urls import url from django.core.urlresolvers import reverse +from django.db import models from django.test import TestCase from django.test.utils import override_settings from django.utils import unittest from django.utils.dateparse import parse_date 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.test import APIRequestFactory -from .models import BaseFilterableItem, FilterableItem, BasicModel +from .models import BaseFilterableItem, BasicModel, FilterableItem factory = APIRequestFactory() diff --git a/tests/test_generics.py b/tests/test_generics.py index 88e792cea..0647119bf 100644 --- a/tests/test_generics.py +++ b/tests/test_generics.py @@ -1,13 +1,16 @@ from __future__ import unicode_literals + import django from django.db import models from django.shortcuts import get_object_or_404 from django.test import TestCase from django.utils import six + from rest_framework import generics, renderers, serializers, status from rest_framework.test import APIRequestFactory -from tests.models import BasicModel, RESTFrameworkModel -from tests.models import ForeignKeySource, ForeignKeyTarget +from tests.models import ( + BasicModel, ForeignKeySource, ForeignKeyTarget, RESTFrameworkModel +) factory = APIRequestFactory() diff --git a/tests/test_htmlrenderer.py b/tests/test_htmlrenderer.py index 1a4a62b25..01ef46d35 100644 --- a/tests/test_htmlrenderer.py +++ b/tests/test_htmlrenderer.py @@ -1,15 +1,17 @@ from __future__ import unicode_literals -from django.core.exceptions import PermissionDenied + +import django.template.loader from django.conf.urls import url +from django.core.exceptions import PermissionDenied from django.http import Http404 +from django.template import Template, TemplateDoesNotExist from django.test import TestCase -from django.template import TemplateDoesNotExist, Template from django.utils import six + from rest_framework import status from rest_framework.decorators import api_view, renderer_classes from rest_framework.renderers import TemplateHTMLRenderer from rest_framework.response import Response -import django.template.loader @api_view(('GET',)) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 04f4284d9..6510a7070 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -1,10 +1,14 @@ from __future__ import unicode_literals + +from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models 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.request import Request + +from rest_framework import ( + exceptions, metadata, serializers, status, versioning, views +) from rest_framework.renderers import BrowsableAPIRenderer +from rest_framework.request import Request from rest_framework.test import APIRequestFactory request = Request(APIRequestFactory().options('/')) diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 36688be4d..49124da61 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -1,12 +1,12 @@ from django.conf.urls import url from django.contrib.auth.models import User + from rest_framework.authentication import TokenAuthentication from rest_framework.authtoken.models import Token from rest_framework.test import APITestCase from rest_framework.views import APIView - urlpatterns = [ url(r'^$', APIView.as_view(authentication_classes=(TokenAuthentication,))), ] diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py index 35fa0e252..28173b687 100644 --- a/tests/test_model_serializer.py +++ b/tests/test_model_serializer.py @@ -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. """ from __future__ import unicode_literals + import django +import pytest 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.test import TestCase from django.utils import six -import pytest + 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): diff --git a/tests/test_multitable_inheritance.py b/tests/test_multitable_inheritance.py index 15627e1dd..340d4966a 100644 --- a/tests/test_multitable_inheritance.py +++ b/tests/test_multitable_inheritance.py @@ -1,6 +1,8 @@ from __future__ import unicode_literals + from django.db import models from django.test import TestCase + from rest_framework import serializers from tests.models import RESTFrameworkModel diff --git a/tests/test_negotiation.py b/tests/test_negotiation.py index 04b89eb60..434fba496 100644 --- a/tests/test_negotiation.py +++ b/tests/test_negotiation.py @@ -1,10 +1,11 @@ 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() diff --git a/tests/test_pagination.py b/tests/test_pagination.py index eb3c78cc5..03c4fdf47 100644 --- a/tests/test_pagination.py +++ b/tests/test_pagination.py @@ -1,11 +1,15 @@ # coding: utf-8 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 +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() diff --git a/tests/test_parsers.py b/tests/test_parsers.py index fe6aec196..1e0f2e17f 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals + from django import forms from django.core.files.uploadhandler import MemoryFileUploadHandler from django.test import TestCase from django.utils.six.moves import StringIO + from rest_framework.exceptions import ParseError -from rest_framework.parsers import FormParser, FileUploadParser +from rest_framework.parsers import FileUploadParser, FormParser class Form(forms.Form): diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 59a85845e..398020002 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -1,16 +1,22 @@ 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.test import TestCase 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 django.core.urlresolvers import ResolverMatch + +from rest_framework import ( + 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.routers import DefaultRouter from rest_framework.test import APIRequestFactory from tests.models import BasicModel -import base64 factory = APIRequestFactory() diff --git a/tests/test_relations.py b/tests/test_relations.py index 25a53f276..fd37e63e3 100644 --- a/tests/test_relations.py +++ b/tests/test_relations.py @@ -1,11 +1,16 @@ import uuid -from .utils import mock_reverse, fail_reverse, BadType, MockObject, MockQueryset + +import pytest from django.core.exceptions import ImproperlyConfigured from django.utils.datastructures import MultiValueDict + from rest_framework import serializers from rest_framework.fields import empty from rest_framework.test import APISimpleTestCase -import pytest + +from .utils import ( + BadType, MockObject, MockQueryset, fail_reverse, mock_reverse +) class TestStringRelatedField(APISimpleTestCase): diff --git a/tests/test_relations_generic.py b/tests/test_relations_generic.py index b600b3333..962857365 100644 --- a/tests/test_relations_generic.py +++ b/tests/test_relations_generic.py @@ -1,9 +1,13 @@ from __future__ import unicode_literals + +from django.contrib.contenttypes.generic import ( + GenericForeignKey, GenericRelation +) from django.contrib.contenttypes.models import ContentType -from django.contrib.contenttypes.generic import GenericRelation, GenericForeignKey from django.db import models from django.test import TestCase from django.utils.encoding import python_2_unicode_compatible + from rest_framework import serializers diff --git a/tests/test_relations_hyperlink.py b/tests/test_relations_hyperlink.py index 33b09713a..c0642eda2 100644 --- a/tests/test_relations_hyperlink.py +++ b/tests/test_relations_hyperlink.py @@ -1,11 +1,13 @@ from __future__ import unicode_literals + from django.conf.urls import url from django.test import TestCase + from rest_framework import serializers from rest_framework.test import APIRequestFactory from tests.models import ( - ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, - NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource + ForeignKeySource, ForeignKeyTarget, ManyToManySource, ManyToManyTarget, + NullableForeignKeySource, NullableOneToOneSource, OneToOneTarget ) factory = APIRequestFactory() diff --git a/tests/test_relations_pk.py b/tests/test_relations_pk.py index ca43272b0..169f7d9c5 100644 --- a/tests/test_relations_pk.py +++ b/tests/test_relations_pk.py @@ -1,10 +1,12 @@ from __future__ import unicode_literals + from django.test import TestCase from django.utils import six + from rest_framework import serializers from tests.models import ( - ManyToManyTarget, ManyToManySource, ForeignKeyTarget, ForeignKeySource, - NullableForeignKeySource, OneToOneTarget, NullableOneToOneSource, + ForeignKeySource, ForeignKeyTarget, ManyToManySource, ManyToManyTarget, + NullableForeignKeySource, NullableOneToOneSource, OneToOneTarget ) diff --git a/tests/test_relations_slug.py b/tests/test_relations_slug.py index cd2cb1ed6..680aee417 100644 --- a/tests/test_relations_slug.py +++ b/tests/test_relations_slug.py @@ -1,6 +1,9 @@ from django.test import TestCase + from rest_framework import serializers -from tests.models import NullableForeignKeySource, ForeignKeySource, ForeignKeyTarget +from tests.models import ( + ForeignKeySource, ForeignKeyTarget, NullableForeignKeySource +) class ForeignKeyTargetSerializer(serializers.ModelSerializer): diff --git a/tests/test_renderers.py b/tests/test_renderers.py index 85c6258d2..113c1b66d 100644 --- a/tests/test_renderers.py +++ b/tests/test_renderers.py @@ -1,25 +1,26 @@ # -*- coding: utf-8 -*- 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.db import models from django.test import TestCase from django.utils import six 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.response import Response -from rest_framework.views import APIView -from rest_framework import serializers 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.test import APIRequestFactory -from collections import MutableMapping -import json -import re - +from rest_framework.views import APIView DUMMYSTATUS = status.HTTP_200_OK DUMMYCONTENT = 'dummycontent' diff --git a/tests/test_request.py b/tests/test_request.py index 03d9f8e49..7c62c90a4 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -2,31 +2,30 @@ Tests for content parsing, and form-overloaded content parsing. """ from __future__ import unicode_literals + +import json +from io import BytesIO + +import django +import pytest 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.models import User from django.contrib.sessions.middleware import SessionMiddleware from django.core.handlers.wsgi import WSGIRequest from django.test import TestCase from django.utils import six + from rest_framework import status from rest_framework.authentication import SessionAuthentication from rest_framework.parsers import ( - BaseParser, - FormParser, - MultiPartParser, - JSONParser + BaseParser, FormParser, JSONParser, MultiPartParser ) -from rest_framework.request import Request, Empty +from rest_framework.request import Empty, Request from rest_framework.response import Response 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 io import BytesIO -import json -import django -import pytest - factory = APIRequestFactory() diff --git a/tests/test_response.py b/tests/test_response.py index 864478a87..1dd5d5ea0 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -1,21 +1,17 @@ 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.utils import six -from tests.models import BasicModel -from rest_framework.response import Response -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 import generics, routers, serializers, status, viewsets from rest_framework.renderers import ( - BaseRenderer, - JSONRenderer, - BrowsableAPIRenderer + BaseRenderer, BrowsableAPIRenderer, JSONRenderer ) -from rest_framework import viewsets +from rest_framework.response import Response from rest_framework.settings import api_settings +from rest_framework.views import APIView +from tests.models import BasicModel # Serializer used to test BasicModel diff --git a/tests/test_reverse.py b/tests/test_reverse.py index bf94f9ee1..c5486e5db 100644 --- a/tests/test_reverse.py +++ b/tests/test_reverse.py @@ -1,7 +1,9 @@ from __future__ import unicode_literals + from django.conf.urls import url from django.core.urlresolvers import NoReverseMatch from django.test import TestCase + from rest_framework.reverse import reverse from rest_framework.test import APIRequestFactory diff --git a/tests/test_routers.py b/tests/test_routers.py index 19eeb868d..ae2639bf2 100644 --- a/tests/test_routers.py +++ b/tests/test_routers.py @@ -1,14 +1,17 @@ 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.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.response import Response -from rest_framework.routers import SimpleRouter, DefaultRouter +from rest_framework.routers import DefaultRouter, SimpleRouter from rest_framework.test import APIRequestFactory -from collections import namedtuple factory = APIRequestFactory() diff --git a/tests/test_serializer.py b/tests/test_serializer.py index b7a0484bc..c18cbb584 100644 --- a/tests/test_serializer.py +++ b/tests/test_serializer.py @@ -1,10 +1,14 @@ # coding: utf-8 from __future__ import unicode_literals -from .utils import MockObject + +import pickle + +import pytest + from rest_framework import serializers from rest_framework.compat import unicode_repr -import pickle -import pytest + +from .utils import MockObject # Tests for core functionality. diff --git a/tests/test_serializer_bulk_update.py b/tests/test_serializer_bulk_update.py index bc955b2ef..8d7240a7b 100644 --- a/tests/test_serializer_bulk_update.py +++ b/tests/test_serializer_bulk_update.py @@ -2,8 +2,10 @@ Tests to cover bulk create and update using serializers. """ from __future__ import unicode_literals + from django.test import TestCase from django.utils import six + from rest_framework import serializers diff --git a/tests/test_serializer_lists.py b/tests/test_serializer_lists.py index 35b68ae7d..e9234d8f7 100644 --- a/tests/test_serializer_lists.py +++ b/tests/test_serializer_lists.py @@ -1,6 +1,7 @@ -from rest_framework import serializers from django.utils.datastructures import MultiValueDict +from rest_framework import serializers + class BasicObject: """ diff --git a/tests/test_settings.py b/tests/test_settings.py index f2ff4ca14..85c36c1fd 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals + from django.test import TestCase + from rest_framework.settings import APISettings diff --git a/tests/test_status.py b/tests/test_status.py index 721a6e30b..1cd6e229e 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -1,7 +1,10 @@ from __future__ import unicode_literals + from django.test import TestCase + 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 ) diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 0cee91f19..746f51b7e 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -1,9 +1,12 @@ # encoding: utf-8 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() diff --git a/tests/test_testing.py b/tests/test_testing.py index b42c08756..70c83f8d9 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -1,13 +1,18 @@ # encoding: utf-8 from __future__ import unicode_literals + +from io import BytesIO + from django.conf.urls import url from django.contrib.auth.models import User from django.shortcuts import redirect from django.test import TestCase + from rest_framework.decorators import api_view from rest_framework.response import Response -from rest_framework.test import APIClient, APIRequestFactory, force_authenticate -from io import BytesIO +from rest_framework.test import ( + APIClient, APIRequestFactory, force_authenticate +) @api_view(['GET', 'POST']) diff --git a/tests/test_throttling.py b/tests/test_throttling.py index 50a53b3eb..6d8d05a32 100644 --- a/tests/test_throttling.py +++ b/tests/test_throttling.py @@ -2,14 +2,18 @@ Tests for the throttling implementations in the permissions module. """ from __future__ import unicode_literals -from django.test import TestCase + from django.contrib.auth.models import User 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.test import APIRequestFactory +from rest_framework.throttling import ( + BaseThrottle, ScopedRateThrottle, UserRateThrottle +) from rest_framework.views import APIView -from rest_framework.throttling import BaseThrottle, UserRateThrottle, ScopedRateThrottle -from rest_framework.response import Response class User3SecRateThrottle(UserRateThrottle): diff --git a/tests/test_urlpatterns.py b/tests/test_urlpatterns.py index f58388c52..fee96878d 100644 --- a/tests/test_urlpatterns.py +++ b/tests/test_urlpatterns.py @@ -1,12 +1,14 @@ from __future__ import unicode_literals + 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.test import TestCase + from rest_framework.test import APIRequestFactory from rest_framework.urlpatterns import format_suffix_patterns - # A container class for test paths for the test case URLTestPath = namedtuple('URLTestPath', ['path', 'args', 'kwargs']) diff --git a/tests/test_utils.py b/tests/test_utils.py index a25518424..062f78e11 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,14 +1,15 @@ from __future__ import unicode_literals -from django.core.exceptions import ImproperlyConfigured + from django.conf.urls import url +from django.core.exceptions import ImproperlyConfigured from django.test import TestCase 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 +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): diff --git a/tests/test_validation.py b/tests/test_validation.py index 4234efd36..46e36f5d8 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -1,10 +1,13 @@ 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.test import TestCase + from rest_framework import generics, serializers, status from rest_framework.test import APIRequestFactory -import re factory = APIRequestFactory() diff --git a/tests/test_validators.py b/tests/test_validators.py index 127ec6f8b..206e882a7 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -1,7 +1,9 @@ +import datetime + from django.db import models from django.test import TestCase + from rest_framework import serializers -import datetime def dedent(blocktext): diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 000762b08..4029e0e43 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -1,14 +1,15 @@ -from .utils import UsingURLPatterns +import pytest 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.relations import PKOnlyObject from rest_framework.response import Response from rest_framework.reverse import reverse from rest_framework.test import APIRequestFactory, APITestCase from rest_framework.versioning import NamespaceVersioning -from rest_framework.relations import PKOnlyObject -import pytest + +from .utils import UsingURLPatterns class RequestVersionView(APIView): diff --git a/tests/test_views.py b/tests/test_views.py index 77b113ee5..65024609c 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,8 +1,10 @@ from __future__ import unicode_literals -import sys import copy +import sys + from django.test import TestCase + from rest_framework import status from rest_framework.decorators import api_view from rest_framework.response import Response diff --git a/tests/test_viewsets.py b/tests/test_viewsets.py index 4d18a955d..0d9b6b310 100644 --- a/tests/test_viewsets.py +++ b/tests/test_viewsets.py @@ -1,10 +1,10 @@ from django.test import TestCase + from rest_framework import status from rest_framework.response import Response from rest_framework.test import APIRequestFactory from rest_framework.viewsets import GenericViewSet - factory = APIRequestFactory() diff --git a/tests/test_write_only_fields.py b/tests/test_write_only_fields.py index dd3bbd6e1..83ef366a5 100644 --- a/tests/test_write_only_fields.py +++ b/tests/test_write_only_fields.py @@ -1,4 +1,5 @@ from django.test import TestCase + from rest_framework import serializers