diff --git a/examples/cookbook-plain/cookbook/ingredients/admin.py b/examples/cookbook-plain/cookbook/ingredients/admin.py index 042682f..05a6478 100644 --- a/examples/cookbook-plain/cookbook/ingredients/admin.py +++ b/examples/cookbook-plain/cookbook/ingredients/admin.py @@ -1,6 +1,5 @@ -from django.contrib import admin - from cookbook.ingredients.models import Category, Ingredient +from django.contrib import admin @admin.register(Ingredient) diff --git a/examples/cookbook-plain/cookbook/recipes/admin.py b/examples/cookbook-plain/cookbook/recipes/admin.py index 10d568f..ada9a7b 100644 --- a/examples/cookbook-plain/cookbook/recipes/admin.py +++ b/examples/cookbook-plain/cookbook/recipes/admin.py @@ -1,6 +1,5 @@ -from django.contrib import admin - from cookbook.recipes.models import Recipe, RecipeIngredient +from django.contrib import admin class RecipeIngredientInline(admin.TabularInline): diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py index f135392..2f8a3ea 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -13,13 +13,7 @@ class Migration(migrations.Migration): operations = [ migrations.RenameField( - model_name='recipeingredient', - old_name='recipes', - new_name='recipe', - ), - migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), - ), - ] + model_name='recipeingredient', old_name='recipes', new_name='recipe', ), migrations.AlterField( + model_name='recipeingredient', name='unit', field=models.CharField( + choices=[ + (b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), ), ] diff --git a/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py b/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py index 7a8df49..f94f0d7 100644 --- a/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py +++ b/examples/cookbook-plain/cookbook/recipes/migrations/0003_auto_20181018_1728.py @@ -9,10 +9,5 @@ class Migration(migrations.Migration): ('recipes', '0002_auto_20161104_0106'), ] - operations = [ - migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[('unit', 'Units'), ('kg', 'Kilograms'), ('l', 'Litres'), ('st', 'Shots')], max_length=20), - ), - ] + operations = [migrations.AlterField(model_name='recipeingredient', name='unit', field=models.CharField( + choices=[('unit', 'Units'), ('kg', 'Kilograms'), ('l', 'Litres'), ('st', 'Shots')], max_length=20), ), ] diff --git a/examples/cookbook-plain/cookbook/schema.py b/examples/cookbook-plain/cookbook/schema.py index bde9372..d4a4f33 100644 --- a/examples/cookbook-plain/cookbook/schema.py +++ b/examples/cookbook-plain/cookbook/schema.py @@ -1,7 +1,6 @@ import cookbook.ingredients.schema import cookbook.recipes.schema import graphene - from graphene_django.debug import DjangoDebug diff --git a/examples/cookbook-plain/cookbook/urls.py b/examples/cookbook-plain/cookbook/urls.py index a64a875..42c74e4 100644 --- a/examples/cookbook-plain/cookbook/urls.py +++ b/examples/cookbook-plain/cookbook/urls.py @@ -1,9 +1,7 @@ -from django.urls import path from django.contrib import admin - +from django.urls import path from graphene_django.views import GraphQLView - urlpatterns = [ path("admin/", admin.site.urls), path("graphql/", GraphQLView.as_view(graphiql=True)), diff --git a/examples/cookbook/cookbook/ingredients/admin.py b/examples/cookbook/cookbook/ingredients/admin.py index 042682f..05a6478 100644 --- a/examples/cookbook/cookbook/ingredients/admin.py +++ b/examples/cookbook/cookbook/ingredients/admin.py @@ -1,6 +1,5 @@ -from django.contrib import admin - from cookbook.ingredients.models import Category, Ingredient +from django.contrib import admin @admin.register(Ingredient) diff --git a/examples/cookbook/cookbook/recipes/admin.py b/examples/cookbook/cookbook/recipes/admin.py index 10d568f..ada9a7b 100644 --- a/examples/cookbook/cookbook/recipes/admin.py +++ b/examples/cookbook/cookbook/recipes/admin.py @@ -1,6 +1,5 @@ -from django.contrib import admin - from cookbook.recipes.models import Recipe, RecipeIngredient +from django.contrib import admin class RecipeIngredientInline(admin.TabularInline): diff --git a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py index f135392..2f8a3ea 100644 --- a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -13,13 +13,7 @@ class Migration(migrations.Migration): operations = [ migrations.RenameField( - model_name='recipeingredient', - old_name='recipes', - new_name='recipe', - ), - migrations.AlterField( - model_name='recipeingredient', - name='unit', - field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), - ), - ] + model_name='recipeingredient', old_name='recipes', new_name='recipe', ), migrations.AlterField( + model_name='recipeingredient', name='unit', field=models.CharField( + choices=[ + (b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20), ), ] diff --git a/examples/cookbook/cookbook/recipes/models.py b/examples/cookbook/cookbook/recipes/models.py index 0bfb434..eec5833 100644 --- a/examples/cookbook/cookbook/recipes/models.py +++ b/examples/cookbook/cookbook/recipes/models.py @@ -1,12 +1,12 @@ -from django.db import models - from cookbook.ingredients.models import Ingredient +from django.db import models class Recipe(models.Model): title = models.CharField(max_length=100) instructions = models.TextField() - __unicode__ = lambda self: self.title + + def __unicode__(self): return self.title class RecipeIngredient(models.Model): diff --git a/examples/cookbook/cookbook/schema.py b/examples/cookbook/cookbook/schema.py index bde9372..d4a4f33 100644 --- a/examples/cookbook/cookbook/schema.py +++ b/examples/cookbook/cookbook/schema.py @@ -1,7 +1,6 @@ import cookbook.ingredients.schema import cookbook.recipes.schema import graphene - from graphene_django.debug import DjangoDebug diff --git a/examples/cookbook/cookbook/urls.py b/examples/cookbook/cookbook/urls.py index 6f8a302..51299e4 100644 --- a/examples/cookbook/cookbook/urls.py +++ b/examples/cookbook/cookbook/urls.py @@ -1,9 +1,7 @@ from django.conf.urls import url from django.contrib import admin - from graphene_django.views import GraphQLView - urlpatterns = [ url(r"^admin/", admin.site.urls), url(r"^graphql$", GraphQLView.as_view(graphiql=True)), diff --git a/graphene_django/converter.py b/graphene_django/converter.py index bd8f79d..9149269 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -1,11 +1,14 @@ from collections import OrderedDict + from django.db import models from django.utils.encoding import force_str from django.utils.module_loading import import_string - from graphene import ( ID, + UUID, Boolean, + Date, + DateTime, Dynamic, Enum, Field, @@ -14,18 +17,15 @@ from graphene import ( List, NonNull, String, - UUID, - DateTime, - Date, Time, ) from graphene.types.json import JSONString from graphene.utils.str_converters import to_camel_case, to_const from graphql import assert_valid_name -from .settings import graphene_settings from .compat import ArrayField, HStoreField, JSONField, RangeField -from .fields import DjangoListField, DjangoConnectionField +from .fields import DjangoConnectionField, DjangoListField +from .settings import graphene_settings from .utils import import_single_dispatch singledispatch = import_single_dispatch() diff --git a/graphene_django/debug/middleware.py b/graphene_django/debug/middleware.py index 0fe3fe3..e92e15b 100644 --- a/graphene_django/debug/middleware.py +++ b/graphene_django/debug/middleware.py @@ -1,5 +1,4 @@ from django.db import connections - from promise import Promise from .sql.tracking import unwrap_cursor, wrap_cursor diff --git a/graphene_django/debug/sql/tracking.py b/graphene_django/debug/sql/tracking.py index a7c9d8d..bc1893d 100644 --- a/graphene_django/debug/sql/tracking.py +++ b/graphene_django/debug/sql/tracking.py @@ -6,6 +6,7 @@ from threading import local from time import time import six + from django.utils.encoding import force_str from .types import DjangoDebugSQL diff --git a/graphene_django/debug/tests/test_query.py b/graphene_django/debug/tests/test_query.py index db8f275..8b5050d 100644 --- a/graphene_django/debug/tests/test_query.py +++ b/graphene_django/debug/tests/test_query.py @@ -1,6 +1,5 @@ -import pytest - import graphene +import pytest from graphene.relay import Node from graphene_django import DjangoConnectionField, DjangoObjectType diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 853fb98..872d553 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -1,13 +1,12 @@ from functools import partial, reduce from django.db.models.query import QuerySet - from graphene import NonNull -from graphene.types import Field, List from graphene.relay import ConnectionField, PageInfo +from graphene.types import Field, List from graphene.utils.get_unbound_function import get_unbound_function -from graphql_relay.connection.arrayconnection import connection_from_list_slice from graphene_django.utils.utils import auth_resolver +from graphql_relay.connection.arrayconnection import connection_from_list_slice from promise import Promise from .settings import graphene_settings diff --git a/graphene_django/filter/fields.py b/graphene_django/filter/fields.py index a46a4b7..ccce15f 100644 --- a/graphene_django/filter/fields.py +++ b/graphene_django/filter/fields.py @@ -2,6 +2,7 @@ from collections import OrderedDict from functools import partial from graphene.types.argument import to_arguments + from ..fields import DjangoConnectionField from .utils import get_filtering_args_from_filterset, get_filterset_class diff --git a/graphene_django/filter/filterset.py b/graphene_django/filter/filterset.py index 7676ea8..1392a9e 100644 --- a/graphene_django/filter/filterset.py +++ b/graphene_django/filter/filterset.py @@ -1,10 +1,12 @@ import itertools from django.db import models -from django_filters import Filter, MultipleChoiceFilter, VERSION -from django_filters.filterset import BaseFilterSet, FilterSet -from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS - +from django_filters import VERSION, Filter, MultipleChoiceFilter +from django_filters.filterset import ( + FILTER_FOR_DBFIELD_DEFAULTS, + BaseFilterSet, + FilterSet, +) from graphql_relay.node.node import from_global_id from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField diff --git a/graphene_django/filter/tests/filters.py b/graphene_django/filter/tests/filters.py index 359d2ba..c672ce3 100644 --- a/graphene_django/filter/tests/filters.py +++ b/graphene_django/filter/tests/filters.py @@ -1,6 +1,5 @@ import django_filters from django_filters import OrderingFilter - from graphene_django.tests.models import Article, Pet, Reporter diff --git a/graphene_django/filter/tests/test_fields.py b/graphene_django/filter/tests/test_fields.py index a0f7d96..3411669 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -4,7 +4,6 @@ from textwrap import dedent import pytest from django.db.models import TextField, Value from django.db.models.functions import Concat - from graphene import Argument, Boolean, Field, Float, ObjectType, Schema, String from graphene.relay import Node from graphene_django import DjangoObjectType diff --git a/graphene_django/filter/utils.py b/graphene_django/filter/utils.py index c5f18e2..c22b188 100644 --- a/graphene_django/filter/utils.py +++ b/graphene_django/filter/utils.py @@ -1,6 +1,7 @@ import six from django_filters.utils import get_model_field + from .filterset import custom_filterset_factory, setup_filterset diff --git a/graphene_django/forms/converter.py b/graphene_django/forms/converter.py index f83c45f..8cdd914 100644 --- a/graphene_django/forms/converter.py +++ b/graphene_django/forms/converter.py @@ -1,12 +1,23 @@ from django import forms from django.core.exceptions import ImproperlyConfigured - -from graphene import ID, Boolean, Float, Int, List, String, UUID, Date, DateTime, Time, Enum +from graphene import ( + ID, + UUID, + Boolean, + Date, + DateTime, + Enum, + Float, + Int, + List, + String, + Time, +) from graphene.utils.str_converters import to_camel_case - from graphene_django.converter import get_choices -from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField + from ..utils import import_single_dispatch +from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField singledispatch = import_single_dispatch() diff --git a/graphene_django/forms/forms.py b/graphene_django/forms/forms.py index 4b81859..f6ed031 100644 --- a/graphene_django/forms/forms.py +++ b/graphene_django/forms/forms.py @@ -3,7 +3,6 @@ import binascii from django.core.exceptions import ValidationError from django.forms import CharField, Field, MultipleChoiceField from django.utils.translation import gettext_lazy as _ - from graphql_relay import from_global_id diff --git a/graphene_django/forms/mutation.py b/graphene_django/forms/mutation.py index c78e110..f25cbd0 100644 --- a/graphene_django/forms/mutation.py +++ b/graphene_django/forms/mutation.py @@ -1,10 +1,10 @@ # from django import forms from collections import OrderedDict + import graphene from graphene import Field, InputField from graphene.relay.mutation import ClientIDMutation from graphene.types.mutation import MutationOptions - # from graphene.types.inputobjecttype import ( # InputObjectTypeOptions, # InputObjectType, @@ -22,8 +22,8 @@ def fields_for_form(form, only_fields, exclude_fields): for name, field in form.fields.items(): is_not_in_only = only_fields and name not in only_fields is_excluded = ( - name - in exclude_fields # or + name + in exclude_fields # or # name in already_created_fields ) diff --git a/graphene_django/forms/tests/test_converter.py b/graphene_django/forms/tests/test_converter.py index 8251491..e8ae70e 100644 --- a/graphene_django/forms/tests/test_converter.py +++ b/graphene_django/forms/tests/test_converter.py @@ -1,20 +1,19 @@ from django import forms -from py.test import raises - from graphene import ( - String, - Int, - Boolean, - Float, ID, UUID, + Boolean, + Date, + DateTime, + Enum, + Float, + Int, List, NonNull, - DateTime, - Date, + String, Time, - Enum, ) +from py.test import raises from ..converter import convert_form_field, convert_form_field_with_choices diff --git a/graphene_django/forms/tests/test_mutation.py b/graphene_django/forms/tests/test_mutation.py index aaf215b..e101707 100644 --- a/graphene_django/forms/tests/test_mutation.py +++ b/graphene_django/forms/tests/test_mutation.py @@ -1,11 +1,10 @@ from django import forms -from django.test import TestCase from django.core.exceptions import ValidationError -from py.test import raises - -from graphene import ObjectType, Schema, String, Field +from django.test import TestCase +from graphene import Field, ObjectType, Schema, String from graphene_django import DjangoObjectType from graphene_django.tests.models import Film, Pet +from py.test import raises from ...settings import graphene_settings from ..mutation import DjangoFormMutation, DjangoModelFormMutation diff --git a/graphene_django/management/commands/graphql_schema.py b/graphene_django/management/commands/graphql_schema.py index 751a385..5413648 100644 --- a/graphene_django/management/commands/graphql_schema.py +++ b/graphene_django/management/commands/graphql_schema.py @@ -1,13 +1,12 @@ -import os +import functools import importlib import json -import functools +import os from django.core.management.base import BaseCommand, CommandError from django.utils import autoreload - -from graphql import print_schema from graphene_django.settings import graphene_settings +from graphql import print_schema class CommandArguments(BaseCommand): @@ -84,7 +83,7 @@ class Command(CommandArguments): def handle(self, *args, **options): options_schema = options.get("schema") - if options_schema and type(options_schema) is str: + if options_schema and isinstance(options_schema, str): module_str, schema_name = options_schema.rsplit(".", 1) mod = importlib.import_module(module_str) schema = getattr(mod, schema_name) diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 592f8b3..b26a8cd 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -1,13 +1,12 @@ from collections import OrderedDict -from django.shortcuts import get_object_or_404 -from rest_framework import serializers - import graphene +from django.shortcuts import get_object_or_404 from graphene.relay.mutation import ClientIDMutation from graphene.types import Field, InputField from graphene.types.mutation import MutationOptions from graphene.types.objecttype import yank_fields_from_attrs +from rest_framework import serializers from ..types import ErrorType from .serializer_converter import convert_serializer_field diff --git a/graphene_django/rest_framework/serializer_converter.py b/graphene_django/rest_framework/serializer_converter.py index 82a113a..107460c 100644 --- a/graphene_django/rest_framework/serializer_converter.py +++ b/graphene_django/rest_framework/serializer_converter.py @@ -1,10 +1,9 @@ +import graphene from django.core.exceptions import ImproperlyConfigured from rest_framework import serializers -import graphene - -from ..registry import get_global_registry from ..converter import convert_choices_to_named_enum_with_descriptions +from ..registry import get_global_registry from ..utils import import_single_dispatch from .types import DictType diff --git a/graphene_django/rest_framework/tests/test_multiple_model_serializers.py b/graphene_django/rest_framework/tests/test_multiple_model_serializers.py index c1f4626..b67728c 100644 --- a/graphene_django/rest_framework/tests/test_multiple_model_serializers.py +++ b/graphene_django/rest_framework/tests/test_multiple_model_serializers.py @@ -2,10 +2,9 @@ import graphene import pytest from django.db import models from graphene import Schema -from rest_framework import serializers - from graphene_django import DjangoObjectType from graphene_django.rest_framework.mutation import SerializerMutation +from rest_framework import serializers pytestmark = pytest.mark.django_db diff --git a/graphene_django/rest_framework/tests/test_mutation.py b/graphene_django/rest_framework/tests/test_mutation.py index 5bf3bc1..d965ee5 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -1,14 +1,13 @@ import datetime -from py.test import mark, raises -from rest_framework import serializers - from graphene import Field, ResolveInfo from graphene.types.inputobjecttype import InputObjectType +from py.test import mark, raises +from rest_framework import serializers from ...settings import graphene_settings from ...types import DjangoObjectType -from ..models import MyFakeModel, MyFakeModelWithPassword, MyFakeModelWithDate +from ..models import MyFakeModel, MyFakeModelWithDate, MyFakeModelWithPassword from ..mutation import SerializerMutation diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 666ad8a..073102c 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -14,6 +14,7 @@ back to the defaults. from __future__ import unicode_literals import six + from django.conf import settings from django.test.signals import setting_changed diff --git a/graphene_django/tests/issues/test_520.py b/graphene_django/tests/issues/test_520.py index 60c5b54..2d15c03 100644 --- a/graphene_django/tests/issues/test_520.py +++ b/graphene_django/tests/issues/test_520.py @@ -2,20 +2,17 @@ import datetime -from django import forms - import graphene - +from django import forms from graphene import Field, ResolveInfo from graphene.types.inputobjecttype import InputObjectType -from py.test import raises -from py.test import mark +from py.test import mark, raises from rest_framework import serializers -from ...types import DjangoObjectType +from ...forms.mutation import DjangoFormMutation from ...rest_framework.models import MyFakeModel from ...rest_framework.mutation import SerializerMutation -from ...forms.mutation import DjangoFormMutation +from ...types import DjangoObjectType class MyModelSerializer(serializers.ModelSerializer): diff --git a/graphene_django/tests/test_command.py b/graphene_django/tests/test_command.py index 8b0a8e6..13550ac 100644 --- a/graphene_django/tests/test_command.py +++ b/graphene_django/tests/test_command.py @@ -1,10 +1,10 @@ from textwrap import dedent -from django.core import management -from mock import mock_open, patch from six import StringIO +from django.core import management from graphene import ObjectType, Schema, String +from mock import mock_open, patch @patch("graphene_django.management.commands.graphql_schema.Command.save_json_file") diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index 7f84de3..08b6de2 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -1,27 +1,26 @@ -import pytest from collections import namedtuple + +import graphene +import pytest from django.db import models from django.utils.translation import ugettext_lazy as _ from graphene import NonNull +from graphene.relay import ConnectionField, Node +from graphene.types.datetime import Date, DateTime, Time +from graphene.types.json import JSONString from py.test import raises -import graphene -from graphene.relay import ConnectionField, Node -from graphene.types.datetime import DateTime, Date, Time -from graphene.types.json import JSONString - -from ..compat import JSONField, ArrayField, HStoreField, RangeField, MissingType +from ..compat import ArrayField, HStoreField, JSONField, MissingType, RangeField from ..converter import ( convert_django_field, convert_django_field_with_choices, generate_enum_name, ) from ..registry import Registry -from ..types import DjangoObjectType from ..settings import graphene_settings +from ..types import DjangoObjectType from .models import Article, Film, FilmDetails, Reporter - # from graphene.core.types.custom_scalars import DateTime, Time, JSONString diff --git a/graphene_django/tests/test_fields.py b/graphene_django/tests/test_fields.py index 6b0f405..9b3c663 100644 --- a/graphene_django/tests/test_fields.py +++ b/graphene_django/tests/test_fields.py @@ -1,14 +1,14 @@ import datetime +from unittest import TestCase import pytest - -from graphene import List, NonNull, ObjectType, Schema, String -from mock import mock -from unittest import TestCase from django.core.exceptions import PermissionDenied -from graphene_django.fields import DjangoField, DataLoaderField -from promise.dataloader import DataLoader +from graphene import List, NonNull, ObjectType, Schema, String +from graphene_django.fields import DataLoaderField, DjangoField +from mock import mock from promise import Promise +from promise.dataloader import DataLoader + from ..fields import DjangoListField from ..types import DjangoObjectType from .models import Article as ArticleModel diff --git a/graphene_django/tests/test_forms.py b/graphene_django/tests/test_forms.py index fa6628d..5b6b1cc 100644 --- a/graphene_django/tests/test_forms.py +++ b/graphene_django/tests/test_forms.py @@ -3,7 +3,6 @@ from py.test import raises from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField - # 'TXlUeXBlOmFiYw==' -> 'MyType', 'abc' diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 95db2d1..4913d88 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1,23 +1,21 @@ import base64 import datetime +import graphene import pytest from django.db import models +from django.db.models import Q from django.utils.functional import SimpleLazyObject +from graphene.relay import Node +from graphql_relay import to_global_id from py.test import raises -from django.db.models import Q - -from graphql_relay import to_global_id -import graphene -from graphene.relay import Node - -from ..utils import DJANGO_FILTER_INSTALLED -from ..compat import MissingType, JSONField +from ..compat import JSONField, MissingType from ..fields import DjangoConnectionField -from ..types import DjangoObjectType from ..settings import graphene_settings -from .models import Article, CNNReporter, Reporter, Film, FilmDetails +from ..types import DjangoObjectType +from ..utils import DJANGO_FILTER_INSTALLED +from .models import Article, CNNReporter, Film, FilmDetails, Reporter pytestmark = pytest.mark.django_db diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 830b1fa..7587c65 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -3,10 +3,9 @@ from textwrap import dedent import pytest from django.db import models -from mock import patch - -from graphene import Interface, ObjectType, Schema, Connection, String, Field +from graphene import Connection, Field, Interface, ObjectType, Schema, String from graphene.relay import Node +from mock import patch from .. import registry from ..settings import graphene_settings diff --git a/graphene_django/tests/test_utils.py b/graphene_django/tests/test_utils.py index 233ec06..3c2b27e 100644 --- a/graphene_django/tests/test_utils.py +++ b/graphene_django/tests/test_utils.py @@ -1,6 +1,6 @@ from django.utils.translation import gettext_lazy - from graphene_django.utils.utils import has_permissions + from ..utils import camelize, get_model_fields from .models import Film, Reporter diff --git a/graphene_django/types.py b/graphene_django/types.py index 8322cec..441ec1a 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -3,16 +3,16 @@ from collections import OrderedDict from functools import partial import six -import graphene +import graphene from django.db.models import Model from django.utils.functional import SimpleLazyObject from graphene import Field, NonNull from graphene.relay import Connection, Node from graphene.types.objecttype import ObjectType, ObjectTypeOptions from graphene.types.utils import yank_fields_from_attrs - from graphene_django.utils.utils import auth_resolver + from .converter import convert_django_field_with_choices from .registry import Registry, get_global_registry from .settings import graphene_settings @@ -29,7 +29,7 @@ ALL_FIELDS = "__all__" def construct_fields( - model, registry, only_fields, exclude_fields, convert_choices_to_enum + model, registry, only_fields, exclude_fields, convert_choices_to_enum ): _model_fields = get_model_fields(model) @@ -71,30 +71,16 @@ def validate_fields(type_, model, fields, only_fields, exclude_fields): if hasattr(model, name): warnings.warn( - ( - 'Field name "{field_name}" matches an attribute on Django model "{app_label}.{object_name}" ' - "but it's not a model field so Graphene cannot determine what type it should be. " - 'Either define the type of the field on DjangoObjectType "{type_}" or remove it from the "fields" list.' - ).format( - field_name=name, - app_label=model._meta.app_label, - object_name=model._meta.object_name, - type_=type_, - ) - ) + ('Field name "{field_name}" matches an attribute on Django model "{app_label}.{object_name}" ' + "but it's not a model field so Graphene cannot determine what type it should be. " + 'Either define the type of the field on DjangoObjectType "{type_}" or remove it from the "fields" list.').format( + field_name=name, app_label=model._meta.app_label, object_name=model._meta.object_name, type_=type_, )) else: warnings.warn( - ( - 'Field name "{field_name}" doesn\'t exist on Django model "{app_label}.{object_name}". ' - 'Consider removing the field from the "fields" list of DjangoObjectType "{type_}" because it has no effect.' - ).format( - field_name=name, - app_label=model._meta.app_label, - object_name=model._meta.object_name, - type_=type_, - ) - ) + ('Field name "{field_name}" doesn\'t exist on Django model "{app_label}.{object_name}". ' + 'Consider removing the field from the "fields" list of DjangoObjectType "{type_}" because it has no effect.').format( + field_name=name, app_label=model._meta.app_label, object_name=model._meta.object_name, type_=type_, )) # Validate exclude fields for name in exclude_fields or (): @@ -114,16 +100,9 @@ def validate_fields(type_, model, fields, only_fields, exclude_fields): else: if not hasattr(model, name): warnings.warn( - ( - 'Django model "{app_label}.{object_name}" does not have a field or attribute named "{field_name}". ' - 'Consider removing the field from the "exclude" list of DjangoObjectType "{type_}" because it has no effect' - ).format( - field_name=name, - app_label=model._meta.app_label, - object_name=model._meta.object_name, - type_=type_, - ) - ) + ('Django model "{app_label}.{object_name}" does not have a field or attribute named "{field_name}". ' + 'Consider removing the field from the "exclude" list of DjangoObjectType "{type_}" because it has no effect').format( + field_name=name, app_label=model._meta.app_label, object_name=model._meta.object_name, type_=type_, )) def get_auth_resolver(name, permissions, resolver=None): diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 8a9b994..f058ce9 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -1,6 +1,6 @@ import json -from django.test import TestCase, Client +from django.test import Client, TestCase class GraphQLTestCase(TestCase): @@ -32,13 +32,13 @@ class GraphQLTestCase(TestCase): supply the op_name. For annon queries ("{ ... }"), should be None (default). input_data (dict) - If provided, the $input variable in GraphQL will be set - to this value. If both ``input_data`` and ``variables``, + to this value. If both ``input_data`` and ``variables``, are provided, the ``input`` field in the ``variables`` dict will be overwritten with this value. variables (dict) - If provided, the "variables" field in GraphQL will be set to this value. headers (dict) - If provided, the headers in POST request to GRAPHQL_URL - will be set to this value. + will be set to this value. Returns: Response object from client diff --git a/graphene_django/utils/utils.py b/graphene_django/utils/utils.py index d148932..0f1723c 100644 --- a/graphene_django/utils/utils.py +++ b/graphene_django/utils/utils.py @@ -1,16 +1,15 @@ import inspect import six + from django.core.exceptions import PermissionDenied from django.db import models from django.db.models.manager import Manager - +from django.utils.encoding import force_text +from django.utils.functional import Promise # from graphene.utils import LazyList from graphene.types.resolver import get_default_resolver from graphene.utils.get_unbound_function import get_unbound_function -from django.utils.encoding import force_text -from django.utils.functional import Promise - from graphene.utils.str_converters import to_camel_case try: diff --git a/graphene_django/views.py b/graphene_django/views.py index 4c58839..91964e0 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -3,16 +3,16 @@ import json import re import six + from django.http import HttpResponse, HttpResponseNotAllowed from django.http.response import HttpResponseBadRequest from django.shortcuts import render from django.utils.decorators import method_decorator -from django.views.generic import View from django.views.decorators.csrf import ensure_csrf_cookie - +from django.views.generic import View from graphql import get_default_backend -from graphql.error import format_error as format_graphql_error from graphql.error import GraphQLError +from graphql.error import format_error as format_graphql_error from graphql.execution import ExecutionResult from graphql.type.schema import GraphQLSchema