diff --git a/examples/cookbook-plain/cookbook/ingredients/admin.py b/examples/cookbook-plain/cookbook/ingredients/admin.py index 05a6478..042682f 100644 --- a/examples/cookbook-plain/cookbook/ingredients/admin.py +++ b/examples/cookbook-plain/cookbook/ingredients/admin.py @@ -1,6 +1,7 @@ -from cookbook.ingredients.models import Category, Ingredient from django.contrib import admin +from cookbook.ingredients.models import Category, Ingredient + @admin.register(Ingredient) class IngredientAdmin(admin.ModelAdmin): diff --git a/examples/cookbook-plain/cookbook/recipes/admin.py b/examples/cookbook-plain/cookbook/recipes/admin.py index ada9a7b..10d568f 100644 --- a/examples/cookbook-plain/cookbook/recipes/admin.py +++ b/examples/cookbook-plain/cookbook/recipes/admin.py @@ -1,6 +1,7 @@ -from cookbook.recipes.models import Recipe, RecipeIngredient from django.contrib import admin +from cookbook.recipes.models import Recipe, RecipeIngredient + class RecipeIngredientInline(admin.TabularInline): model = RecipeIngredient 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 2f8a3ea..f135392 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,7 +13,13 @@ 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 f94f0d7..7a8df49 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,5 +9,10 @@ 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 d4a4f33..bde9372 100644 --- a/examples/cookbook-plain/cookbook/schema.py +++ b/examples/cookbook-plain/cookbook/schema.py @@ -1,6 +1,7 @@ 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 42c74e4..a64a875 100644 --- a/examples/cookbook-plain/cookbook/urls.py +++ b/examples/cookbook-plain/cookbook/urls.py @@ -1,7 +1,9 @@ -from django.contrib import admin from django.urls import path +from django.contrib import admin + 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 05a6478..042682f 100644 --- a/examples/cookbook/cookbook/ingredients/admin.py +++ b/examples/cookbook/cookbook/ingredients/admin.py @@ -1,6 +1,7 @@ -from cookbook.ingredients.models import Category, Ingredient from django.contrib import admin +from cookbook.ingredients.models import Category, Ingredient + @admin.register(Ingredient) class IngredientAdmin(admin.ModelAdmin): diff --git a/examples/cookbook/cookbook/recipes/admin.py b/examples/cookbook/cookbook/recipes/admin.py index ada9a7b..10d568f 100644 --- a/examples/cookbook/cookbook/recipes/admin.py +++ b/examples/cookbook/cookbook/recipes/admin.py @@ -1,6 +1,7 @@ -from cookbook.recipes.models import Recipe, RecipeIngredient from django.contrib import admin +from cookbook.recipes.models import Recipe, RecipeIngredient + class RecipeIngredientInline(admin.TabularInline): model = RecipeIngredient 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 2f8a3ea..f135392 100644 --- a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py +++ b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -13,7 +13,13 @@ 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 eec5833..0bfb434 100644 --- a/examples/cookbook/cookbook/recipes/models.py +++ b/examples/cookbook/cookbook/recipes/models.py @@ -1,12 +1,12 @@ -from cookbook.ingredients.models import Ingredient from django.db import models +from cookbook.ingredients.models import Ingredient + class Recipe(models.Model): title = models.CharField(max_length=100) instructions = models.TextField() - - def __unicode__(self): return self.title + __unicode__ = lambda self: self.title class RecipeIngredient(models.Model): diff --git a/examples/cookbook/cookbook/schema.py b/examples/cookbook/cookbook/schema.py index d4a4f33..bde9372 100644 --- a/examples/cookbook/cookbook/schema.py +++ b/examples/cookbook/cookbook/schema.py @@ -1,6 +1,7 @@ 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 51299e4..6f8a302 100644 --- a/examples/cookbook/cookbook/urls.py +++ b/examples/cookbook/cookbook/urls.py @@ -1,7 +1,9 @@ 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 9149269..bd8f79d 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -1,14 +1,11 @@ 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, @@ -17,15 +14,18 @@ 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 .compat import ArrayField, HStoreField, JSONField, RangeField -from .fields import DjangoConnectionField, DjangoListField from .settings import graphene_settings +from .compat import ArrayField, HStoreField, JSONField, RangeField +from .fields import DjangoListField, DjangoConnectionField 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 e92e15b..0fe3fe3 100644 --- a/graphene_django/debug/middleware.py +++ b/graphene_django/debug/middleware.py @@ -1,4 +1,5 @@ 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 bc1893d..a7c9d8d 100644 --- a/graphene_django/debug/sql/tracking.py +++ b/graphene_django/debug/sql/tracking.py @@ -6,7 +6,6 @@ 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 8b5050d..db8f275 100644 --- a/graphene_django/debug/tests/test_query.py +++ b/graphene_django/debug/tests/test_query.py @@ -1,5 +1,6 @@ -import graphene import pytest + +import graphene from graphene.relay import Node from graphene_django import DjangoConnectionField, DjangoObjectType diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 872d553..853fb98 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -1,12 +1,13 @@ from functools import partial, reduce from django.db.models.query import QuerySet + from graphene import NonNull -from graphene.relay import ConnectionField, PageInfo from graphene.types import Field, List +from graphene.relay import ConnectionField, PageInfo from graphene.utils.get_unbound_function import get_unbound_function -from graphene_django.utils.utils import auth_resolver from graphql_relay.connection.arrayconnection import connection_from_list_slice +from graphene_django.utils.utils import auth_resolver from promise import Promise from .settings import graphene_settings diff --git a/graphene_django/filter/fields.py b/graphene_django/filter/fields.py index ccce15f..a46a4b7 100644 --- a/graphene_django/filter/fields.py +++ b/graphene_django/filter/fields.py @@ -2,7 +2,6 @@ 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 1392a9e..7676ea8 100644 --- a/graphene_django/filter/filterset.py +++ b/graphene_django/filter/filterset.py @@ -1,12 +1,10 @@ import itertools from django.db import models -from django_filters import VERSION, Filter, MultipleChoiceFilter -from django_filters.filterset import ( - FILTER_FOR_DBFIELD_DEFAULTS, - BaseFilterSet, - FilterSet, -) +from django_filters import Filter, MultipleChoiceFilter, VERSION +from django_filters.filterset import BaseFilterSet, FilterSet +from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS + 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 c672ce3..359d2ba 100644 --- a/graphene_django/filter/tests/filters.py +++ b/graphene_django/filter/tests/filters.py @@ -1,5 +1,6 @@ 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 3411669..a0f7d96 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -4,6 +4,7 @@ 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 c22b188..c5f18e2 100644 --- a/graphene_django/filter/utils.py +++ b/graphene_django/filter/utils.py @@ -1,7 +1,6 @@ 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 8cdd914..f83c45f 100644 --- a/graphene_django/forms/converter.py +++ b/graphene_django/forms/converter.py @@ -1,23 +1,12 @@ from django import forms from django.core.exceptions import ImproperlyConfigured -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 ..utils import import_single_dispatch +from graphene import ID, Boolean, Float, Int, List, String, UUID, Date, DateTime, Time, Enum +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 singledispatch = import_single_dispatch() diff --git a/graphene_django/forms/forms.py b/graphene_django/forms/forms.py index f6ed031..4b81859 100644 --- a/graphene_django/forms/forms.py +++ b/graphene_django/forms/forms.py @@ -3,6 +3,7 @@ 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 f25cbd0..c78e110 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 e8ae70e..8251491 100644 --- a/graphene_django/forms/tests/test_converter.py +++ b/graphene_django/forms/tests/test_converter.py @@ -1,19 +1,20 @@ 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, - String, + DateTime, + Date, 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 e101707..aaf215b 100644 --- a/graphene_django/forms/tests/test_mutation.py +++ b/graphene_django/forms/tests/test_mutation.py @@ -1,10 +1,11 @@ from django import forms -from django.core.exceptions import ValidationError from django.test import TestCase -from graphene import Field, ObjectType, Schema, String +from django.core.exceptions import ValidationError +from py.test import raises + +from graphene import ObjectType, Schema, String, Field 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 5413648..751a385 100644 --- a/graphene_django/management/commands/graphql_schema.py +++ b/graphene_django/management/commands/graphql_schema.py @@ -1,12 +1,13 @@ -import functools +import os import importlib import json -import os +import functools from django.core.management.base import BaseCommand, CommandError from django.utils import autoreload -from graphene_django.settings import graphene_settings + from graphql import print_schema +from graphene_django.settings import graphene_settings class CommandArguments(BaseCommand): @@ -83,7 +84,7 @@ class Command(CommandArguments): def handle(self, *args, **options): options_schema = options.get("schema") - if options_schema and isinstance(options_schema, str): + if options_schema and type(options_schema) is 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 b26a8cd..592f8b3 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -1,12 +1,13 @@ from collections import OrderedDict -import graphene from django.shortcuts import get_object_or_404 +from rest_framework import serializers + +import graphene 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 107460c..82a113a 100644 --- a/graphene_django/rest_framework/serializer_converter.py +++ b/graphene_django/rest_framework/serializer_converter.py @@ -1,9 +1,10 @@ -import graphene from django.core.exceptions import ImproperlyConfigured from rest_framework import serializers -from ..converter import convert_choices_to_named_enum_with_descriptions +import graphene + from ..registry import get_global_registry +from ..converter import convert_choices_to_named_enum_with_descriptions 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 b67728c..c1f4626 100644 --- a/graphene_django/rest_framework/tests/test_multiple_model_serializers.py +++ b/graphene_django/rest_framework/tests/test_multiple_model_serializers.py @@ -2,9 +2,10 @@ 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 d965ee5..5bf3bc1 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -1,13 +1,14 @@ import datetime -from graphene import Field, ResolveInfo -from graphene.types.inputobjecttype import InputObjectType from py.test import mark, raises from rest_framework import serializers +from graphene import Field, ResolveInfo +from graphene.types.inputobjecttype import InputObjectType + from ...settings import graphene_settings from ...types import DjangoObjectType -from ..models import MyFakeModel, MyFakeModelWithDate, MyFakeModelWithPassword +from ..models import MyFakeModel, MyFakeModelWithPassword, MyFakeModelWithDate from ..mutation import SerializerMutation diff --git a/graphene_django/settings.py b/graphene_django/settings.py index 073102c..666ad8a 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -14,7 +14,6 @@ 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 2d15c03..60c5b54 100644 --- a/graphene_django/tests/issues/test_520.py +++ b/graphene_django/tests/issues/test_520.py @@ -2,17 +2,20 @@ import datetime -import graphene from django import forms + +import graphene + from graphene import Field, ResolveInfo from graphene.types.inputobjecttype import InputObjectType -from py.test import mark, raises +from py.test import raises +from py.test import mark from rest_framework import serializers -from ...forms.mutation import DjangoFormMutation +from ...types import DjangoObjectType from ...rest_framework.models import MyFakeModel from ...rest_framework.mutation import SerializerMutation -from ...types import DjangoObjectType +from ...forms.mutation import DjangoFormMutation class MyModelSerializer(serializers.ModelSerializer): diff --git a/graphene_django/tests/test_command.py b/graphene_django/tests/test_command.py index 13550ac..8b0a8e6 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 08b6de2..7f84de3 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -1,26 +1,27 @@ -from collections import namedtuple - -import graphene import pytest +from collections import namedtuple 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 -from ..compat import ArrayField, HStoreField, JSONField, MissingType, RangeField +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 ..converter import ( convert_django_field, convert_django_field_with_choices, generate_enum_name, ) from ..registry import Registry -from ..settings import graphene_settings from ..types import DjangoObjectType +from ..settings import graphene_settings 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 9b3c663..6b0f405 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 django.core.exceptions import PermissionDenied -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 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 promise import Promise 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 5b6b1cc..fa6628d 100644 --- a/graphene_django/tests/test_forms.py +++ b/graphene_django/tests/test_forms.py @@ -3,6 +3,7 @@ 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 4913d88..95db2d1 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1,21 +1,23 @@ 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 ..compat import JSONField, MissingType -from ..fields import DjangoConnectionField -from ..settings import graphene_settings -from ..types import DjangoObjectType +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 .models import Article, CNNReporter, Film, FilmDetails, Reporter +from ..compat import MissingType, JSONField +from ..fields import DjangoConnectionField +from ..types import DjangoObjectType +from ..settings import graphene_settings +from .models import Article, CNNReporter, Reporter, Film, FilmDetails pytestmark = pytest.mark.django_db diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index 7587c65..830b1fa 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -3,10 +3,11 @@ from textwrap import dedent import pytest from django.db import models -from graphene import Connection, Field, Interface, ObjectType, Schema, String -from graphene.relay import Node from mock import patch +from graphene import Interface, ObjectType, Schema, Connection, String, Field +from graphene.relay import Node + from .. import registry from ..settings import graphene_settings from ..types import DjangoObjectType, DjangoObjectTypeOptions diff --git a/graphene_django/tests/test_utils.py b/graphene_django/tests/test_utils.py index 3c2b27e..233ec06 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 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 441ec1a..8322cec 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 + 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 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,16 +71,30 @@ 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 (): @@ -100,9 +114,16 @@ 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 f058ce9..8a9b994 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -1,6 +1,6 @@ import json -from django.test import Client, TestCase +from django.test import TestCase, Client 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 0f1723c..d148932 100644 --- a/graphene_django/utils/utils.py +++ b/graphene_django/utils/utils.py @@ -1,15 +1,16 @@ 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 91964e0..4c58839 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.decorators.csrf import ensure_csrf_cookie from django.views.generic import View +from django.views.decorators.csrf import ensure_csrf_cookie + from graphql import get_default_backend -from graphql.error import GraphQLError from graphql.error import format_error as format_graphql_error +from graphql.error import GraphQLError from graphql.execution import ExecutionResult from graphql.type.schema import GraphQLSchema