mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 01:27:01 +03:00
Use ruff in pre-commit (#1441)
* Use ruff in pre-commit * Add pyupgrade * Add isort * Add bugbear * Fix B015 Pointless comparison * Fix B026 * B018 false positive * Remove flake8 and isort config from setup.cfg * Remove black and flake8 from dev dependencies * Update black * Show list of fixes applied with autofix on * Fix typo * Add C4 flake8-comprehensions * Add ruff to dev dependencies * Fix up
This commit is contained in:
parent
45a732f1db
commit
9a773b9d7b
|
@ -15,16 +15,12 @@ repos:
|
||||||
- --autofix
|
- --autofix
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
exclude: README.md
|
exclude: README.md
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
|
||||||
rev: v3.3.2
|
|
||||||
hooks:
|
|
||||||
- id: pyupgrade
|
|
||||||
args: [--py38-plus]
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 23.3.0
|
rev: 23.7.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: 6.0.0
|
rev: v0.0.282
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: ruff
|
||||||
|
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
|
||||||
|
|
33
.ruff.toml
Normal file
33
.ruff.toml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
select = [
|
||||||
|
"E", # pycodestyle
|
||||||
|
"W", # pycodestyle
|
||||||
|
"F", # pyflake
|
||||||
|
"I", # isort
|
||||||
|
"B", # flake8-bugbear
|
||||||
|
"C4", # flake8-comprehensions
|
||||||
|
"UP", # pyupgrade
|
||||||
|
]
|
||||||
|
|
||||||
|
ignore = [
|
||||||
|
"E501", # line-too-long
|
||||||
|
"B017", # pytest.raises(Exception) should be considered evil
|
||||||
|
"B028", # warnings.warn called without an explicit stacklevel keyword argument
|
||||||
|
"B904", # check for raise statements in exception handlers that lack a from clause
|
||||||
|
]
|
||||||
|
|
||||||
|
exclude = [
|
||||||
|
"**/docs",
|
||||||
|
]
|
||||||
|
|
||||||
|
target-version = "py38"
|
||||||
|
|
||||||
|
[per-file-ignores]
|
||||||
|
# Ignore unused imports (F401) in these files
|
||||||
|
"__init__.py" = ["F401"]
|
||||||
|
"graphene_django/compat.py" = ["F401"]
|
||||||
|
|
||||||
|
[isort]
|
||||||
|
known-first-party = ["graphene", "graphene-django"]
|
||||||
|
known-local-folder = ["cookbook"]
|
||||||
|
force-wrap-aliases = true
|
||||||
|
combine-as-imports = true
|
|
@ -1,8 +1,8 @@
|
||||||
|
import graphene
|
||||||
|
from graphene_django.debug import DjangoDebug
|
||||||
|
|
||||||
import cookbook.ingredients.schema
|
import cookbook.ingredients.schema
|
||||||
import cookbook.recipes.schema
|
import cookbook.recipes.schema
|
||||||
import graphene
|
|
||||||
|
|
||||||
from graphene_django.debug import DjangoDebug
|
|
||||||
|
|
||||||
|
|
||||||
class Query(
|
class Query(
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
from django.urls import path
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
from graphene_django.views import GraphQLView
|
from graphene_django.views import GraphQLView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("graphql/", GraphQLView.as_view(graphiql=True)),
|
path("graphql/", GraphQLView.as_view(graphiql=True)),
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
from cookbook.ingredients.models import Category, Ingredient
|
|
||||||
from graphene import Node
|
from graphene import Node
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
from graphene_django.types import DjangoObjectType
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
|
from cookbook.ingredients.models import Category, Ingredient
|
||||||
|
|
||||||
|
|
||||||
# Graphene will automatically map the Category model's fields onto the CategoryNode.
|
# Graphene will automatically map the Category model's fields onto the CategoryNode.
|
||||||
# This is configured in the CategoryNode's Meta class (as you can see below)
|
# This is configured in the CategoryNode's Meta class (as you can see below)
|
||||||
|
|
|
@ -6,7 +6,9 @@ from cookbook.ingredients.models import Ingredient
|
||||||
class Recipe(models.Model):
|
class Recipe(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
instructions = models.TextField()
|
instructions = models.TextField()
|
||||||
__unicode__ = lambda self: self.title
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
class RecipeIngredient(models.Model):
|
class RecipeIngredient(models.Model):
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
from cookbook.recipes.models import Recipe, RecipeIngredient
|
|
||||||
from graphene import Node
|
from graphene import Node
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
from graphene_django.types import DjangoObjectType
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
|
from cookbook.recipes.models import Recipe, RecipeIngredient
|
||||||
|
|
||||||
|
|
||||||
class RecipeNode(DjangoObjectType):
|
class RecipeNode(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
import graphene
|
||||||
|
from graphene_django.debug import DjangoDebug
|
||||||
|
|
||||||
import cookbook.ingredients.schema
|
import cookbook.ingredients.schema
|
||||||
import cookbook.recipes.schema
|
import cookbook.recipes.schema
|
||||||
import graphene
|
|
||||||
|
|
||||||
from graphene_django.debug import DjangoDebug
|
|
||||||
|
|
||||||
|
|
||||||
class Query(
|
class Query(
|
||||||
|
|
|
@ -3,7 +3,6 @@ from django.contrib import admin
|
||||||
|
|
||||||
from graphene_django.views import GraphQLView
|
from graphene_django.views import GraphQLView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r"^admin/", admin.site.urls),
|
url(r"^admin/", admin.site.urls),
|
||||||
url(r"^graphql$", GraphQLView.as_view(graphiql=True)),
|
url(r"^graphql$", GraphQLView.as_view(graphiql=True)),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
sys.path.insert(0, ROOT_PATH + "/examples/")
|
sys.path.insert(0, ROOT_PATH + "/examples/")
|
||||||
|
|
|
@ -3,9 +3,11 @@ from graphene import Schema, relay, resolve_only_args
|
||||||
from graphene_django import DjangoConnectionField, DjangoObjectType
|
from graphene_django import DjangoConnectionField, DjangoObjectType
|
||||||
|
|
||||||
from .data import create_ship, get_empire, get_faction, get_rebels, get_ship, get_ships
|
from .data import create_ship, get_empire, get_faction, get_rebels, get_ship, get_ships
|
||||||
from .models import Character as CharacterModel
|
from .models import (
|
||||||
from .models import Faction as FactionModel
|
Character as CharacterModel,
|
||||||
from .models import Ship as ShipModel
|
Faction as FactionModel,
|
||||||
|
Ship as ShipModel,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Ship(DjangoObjectType):
|
class Ship(DjangoObjectType):
|
||||||
|
|
|
@ -13,9 +13,9 @@ try:
|
||||||
# Postgres fields are only available in Django with psycopg2 installed
|
# Postgres fields are only available in Django with psycopg2 installed
|
||||||
# and we cannot have psycopg2 on PyPy
|
# and we cannot have psycopg2 on PyPy
|
||||||
from django.contrib.postgres.fields import (
|
from django.contrib.postgres.fields import (
|
||||||
IntegerRangeField,
|
|
||||||
ArrayField,
|
ArrayField,
|
||||||
HStoreField,
|
HStoreField,
|
||||||
|
IntegerRangeField,
|
||||||
RangeField,
|
RangeField,
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.db import models
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
|
from graphql import GraphQLError
|
||||||
|
|
||||||
from graphene import (
|
from graphene import (
|
||||||
ID,
|
ID,
|
||||||
|
@ -13,6 +14,7 @@ from graphene import (
|
||||||
Boolean,
|
Boolean,
|
||||||
Date,
|
Date,
|
||||||
DateTime,
|
DateTime,
|
||||||
|
Decimal,
|
||||||
Dynamic,
|
Dynamic,
|
||||||
Enum,
|
Enum,
|
||||||
Field,
|
Field,
|
||||||
|
@ -22,13 +24,11 @@ from graphene import (
|
||||||
NonNull,
|
NonNull,
|
||||||
String,
|
String,
|
||||||
Time,
|
Time,
|
||||||
Decimal,
|
|
||||||
)
|
)
|
||||||
from graphene.types.json import JSONString
|
from graphene.types.json import JSONString
|
||||||
from graphene.types.scalars import BigInt
|
|
||||||
from graphene.types.resolver import get_default_resolver
|
from graphene.types.resolver import get_default_resolver
|
||||||
|
from graphene.types.scalars import BigInt
|
||||||
from graphene.utils.str_converters import to_camel_case
|
from graphene.utils.str_converters import to_camel_case
|
||||||
from graphql import GraphQLError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from graphql import assert_name
|
from graphql import assert_name
|
||||||
|
@ -38,7 +38,7 @@ except ImportError:
|
||||||
from graphql.pyutils import register_description
|
from graphql.pyutils import register_description
|
||||||
|
|
||||||
from .compat import ArrayField, HStoreField, RangeField
|
from .compat import ArrayField, HStoreField, RangeField
|
||||||
from .fields import DjangoListField, DjangoConnectionField
|
from .fields import DjangoConnectionField, DjangoListField
|
||||||
from .settings import graphene_settings
|
from .settings import graphene_settings
|
||||||
from .utils.str_converters import to_const
|
from .utils.str_converters import to_const
|
||||||
|
|
||||||
|
@ -161,9 +161,7 @@ def get_django_field_description(field):
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def convert_django_field(field, registry=None):
|
def convert_django_field(field, registry=None):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Don't know how to convert the Django field {} ({})".format(
|
f"Don't know how to convert the Django field {field} ({field.__class__})"
|
||||||
field, field.__class__
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,6 +259,7 @@ def convert_time_to_string(field, registry=None):
|
||||||
@convert_django_field.register(models.OneToOneRel)
|
@convert_django_field.register(models.OneToOneRel)
|
||||||
def convert_onetoone_field_to_djangomodel(field, registry=None):
|
def convert_onetoone_field_to_djangomodel(field, registry=None):
|
||||||
from graphene.utils.str_converters import to_snake_case
|
from graphene.utils.str_converters import to_snake_case
|
||||||
|
|
||||||
from .types import DjangoObjectType
|
from .types import DjangoObjectType
|
||||||
|
|
||||||
model = field.related_model
|
model = field.related_model
|
||||||
|
@ -364,6 +363,7 @@ def convert_field_to_list_or_connection(field, registry=None):
|
||||||
@convert_django_field.register(models.ForeignKey)
|
@convert_django_field.register(models.ForeignKey)
|
||||||
def convert_field_to_djangomodel(field, registry=None):
|
def convert_field_to_djangomodel(field, registry=None):
|
||||||
from graphene.utils.str_converters import to_snake_case
|
from graphene.utils.str_converters import to_snake_case
|
||||||
|
|
||||||
from .types import DjangoObjectType
|
from .types import DjangoObjectType
|
||||||
|
|
||||||
model = field.related_model
|
model = field.related_model
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
|
|
||||||
from promise import Promise
|
|
||||||
|
|
||||||
from .sql.tracking import unwrap_cursor, wrap_cursor
|
|
||||||
from .exception.formating import wrap_exception
|
from .exception.formating import wrap_exception
|
||||||
|
from .sql.tracking import unwrap_cursor, wrap_cursor
|
||||||
from .types import DjangoDebug
|
from .types import DjangoDebug
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import graphene
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import graphene
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
from graphene_django import DjangoConnectionField, DjangoObjectType
|
from graphene_django import DjangoConnectionField, DjangoObjectType
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from graphene import List, ObjectType
|
from graphene import List, ObjectType
|
||||||
|
|
||||||
from .sql.types import DjangoDebugSQL
|
|
||||||
from .exception.types import DjangoDebugException
|
from .exception.types import DjangoDebugException
|
||||||
|
from .sql.types import DjangoDebugSQL
|
||||||
|
|
||||||
|
|
||||||
class DjangoDebug(ObjectType):
|
class DjangoDebug(ObjectType):
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
|
||||||
from graphql_relay import (
|
from graphql_relay import (
|
||||||
connection_from_array_slice,
|
connection_from_array_slice,
|
||||||
cursor_to_offset,
|
cursor_to_offset,
|
||||||
get_offset_with_default,
|
get_offset_with_default,
|
||||||
offset_to_cursor,
|
offset_to_cursor,
|
||||||
)
|
)
|
||||||
|
|
||||||
from promise import Promise
|
from promise import Promise
|
||||||
|
|
||||||
from graphene import Int, NonNull
|
from graphene import Int, NonNull
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from ..utils import DJANGO_FILTER_INSTALLED
|
from ..utils import DJANGO_FILTER_INSTALLED
|
||||||
|
|
||||||
if not DJANGO_FILTER_INSTALLED:
|
if not DJANGO_FILTER_INSTALLED:
|
||||||
|
|
|
@ -3,8 +3,8 @@ from functools import partial
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from graphene.types.enum import EnumType
|
|
||||||
from graphene.types.argument import to_arguments
|
from graphene.types.argument import to_arguments
|
||||||
|
from graphene.types.enum import EnumType
|
||||||
from graphene.utils.str_converters import to_snake_case
|
from graphene.utils.str_converters import to_snake_case
|
||||||
|
|
||||||
from ..fields import DjangoConnectionField
|
from ..fields import DjangoConnectionField
|
||||||
|
@ -58,7 +58,7 @@ class DjangoFilterConnectionField(DjangoConnectionField):
|
||||||
def filterset_class(self):
|
def filterset_class(self):
|
||||||
if not self._filterset_class:
|
if not self._filterset_class:
|
||||||
fields = self._fields or self.node_type._meta.filter_fields
|
fields = self._fields or self.node_type._meta.filter_fields
|
||||||
meta = dict(model=self.model, fields=fields)
|
meta = {"model": self.model, "fields": fields}
|
||||||
if self._extra_filter_meta:
|
if self._extra_filter_meta:
|
||||||
meta.update(self._extra_filter_meta)
|
meta.update(self._extra_filter_meta)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from ...utils import DJANGO_FILTER_INSTALLED
|
from ...utils import DJANGO_FILTER_INSTALLED
|
||||||
|
|
||||||
if not DJANGO_FILTER_INSTALLED:
|
if not DJANGO_FILTER_INSTALLED:
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from django_filters import Filter, MultipleChoiceFilter
|
from django_filters import Filter, MultipleChoiceFilter
|
||||||
|
|
||||||
from graphql_relay.node.node import from_global_id
|
from graphql_relay.node.node import from_global_id
|
||||||
|
|
||||||
from ...forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
from ...forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django_filters.filterset import BaseFilterSet, FilterSet
|
from django_filters.filterset import (
|
||||||
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS
|
FILTER_FOR_DBFIELD_DEFAULTS,
|
||||||
|
BaseFilterSet,
|
||||||
|
FilterSet,
|
||||||
|
)
|
||||||
|
|
||||||
from .filters import GlobalIDFilter, GlobalIDMultipleChoiceFilter
|
from .filters import GlobalIDFilter, GlobalIDMultipleChoiceFilter
|
||||||
|
|
||||||
|
|
||||||
GRAPHENE_FILTER_SET_OVERRIDES = {
|
GRAPHENE_FILTER_SET_OVERRIDES = {
|
||||||
models.AutoField: {"filter_class": GlobalIDFilter},
|
models.AutoField: {"filter_class": GlobalIDFilter},
|
||||||
models.OneToOneField: {"filter_class": GlobalIDFilter},
|
models.OneToOneField: {"filter_class": GlobalIDFilter},
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django_filters import filters
|
|
||||||
from django_filters import FilterSet
|
from django_filters import FilterSet
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
|
from graphene_django.filter import ArrayFilter
|
||||||
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
||||||
from graphene_django.filter import ArrayFilter, ListFilter
|
|
||||||
|
|
||||||
from ...compat import ArrayField
|
from ...compat import ArrayField
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@ import pytest
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
|
from graphene_django import DjangoConnectionField, DjangoObjectType
|
||||||
from graphene_django import DjangoObjectType, DjangoConnectionField
|
|
||||||
from graphene_django.tests.models import Article, Reporter
|
from graphene_django.tests.models import Article, Reporter
|
||||||
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ if DJANGO_FILTER_INSTALLED:
|
||||||
from django_filters import FilterSet, NumberFilter, OrderingFilter
|
from django_filters import FilterSet, NumberFilter, OrderingFilter
|
||||||
|
|
||||||
from graphene_django.filter import (
|
from graphene_django.filter import (
|
||||||
GlobalIDFilter,
|
|
||||||
DjangoFilterConnectionField,
|
DjangoFilterConnectionField,
|
||||||
|
GlobalIDFilter,
|
||||||
GlobalIDMultipleChoiceFilter,
|
GlobalIDMultipleChoiceFilter,
|
||||||
)
|
)
|
||||||
from graphene_django.filter.tests.filters import (
|
from graphene_django.filter.tests.filters import (
|
||||||
|
@ -222,7 +222,7 @@ def test_filter_filterset_information_on_meta_related():
|
||||||
reporter = Field(ReporterFilterNode)
|
reporter = Field(ReporterFilterNode)
|
||||||
article = Field(ArticleFilterNode)
|
article = Field(ArticleFilterNode)
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
Schema(query=Query)
|
||||||
articles_field = ReporterFilterNode._meta.fields["articles"].get_type()
|
articles_field = ReporterFilterNode._meta.fields["articles"].get_type()
|
||||||
assert_arguments(articles_field, "headline", "reporter")
|
assert_arguments(articles_field, "headline", "reporter")
|
||||||
assert_not_orderable(articles_field)
|
assert_not_orderable(articles_field)
|
||||||
|
@ -294,7 +294,7 @@ def test_filter_filterset_class_information_on_meta_related():
|
||||||
reporter = Field(ReporterFilterNode)
|
reporter = Field(ReporterFilterNode)
|
||||||
article = Field(ArticleFilterNode)
|
article = Field(ArticleFilterNode)
|
||||||
|
|
||||||
schema = Schema(query=Query)
|
Schema(query=Query)
|
||||||
articles_field = ReporterFilterNode._meta.fields["articles"].get_type()
|
articles_field = ReporterFilterNode._meta.fields["articles"].get_type()
|
||||||
assert_arguments(articles_field, "headline", "reporter")
|
assert_arguments(articles_field, "headline", "reporter")
|
||||||
assert_not_orderable(articles_field)
|
assert_not_orderable(articles_field)
|
||||||
|
@ -1186,7 +1186,7 @@ def test_filter_filterset_based_on_mixin():
|
||||||
first_name="Adam", last_name="Doe", email="adam@doe.com"
|
first_name="Adam", last_name="Doe", email="adam@doe.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
article_2 = Article.objects.create(
|
Article.objects.create(
|
||||||
headline="Good Bye",
|
headline="Good Bye",
|
||||||
reporter=reporter_2,
|
reporter=reporter_2,
|
||||||
editor=reporter_2,
|
editor=reporter_2,
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from django_filters import (
|
||||||
|
FilterSet,
|
||||||
|
rest_framework as filters,
|
||||||
|
)
|
||||||
|
|
||||||
from django_filters import FilterSet
|
|
||||||
from django_filters import rest_framework as filters
|
|
||||||
from graphene import ObjectType, Schema
|
from graphene import ObjectType, Schema
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.tests.models import Pet, Person, Reporter, Article, Film
|
|
||||||
from graphene_django.filter.tests.filters import ArticleFilter
|
from graphene_django.filter.tests.filters import ArticleFilter
|
||||||
|
from graphene_django.tests.models import Article, Film, Person, Pet, Reporter
|
||||||
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
||||||
|
|
||||||
pytestmark = []
|
pytestmark = []
|
||||||
|
@ -348,9 +350,9 @@ def test_fk_id_in_filter(query):
|
||||||
|
|
||||||
schema = Schema(query=query)
|
schema = Schema(query=query)
|
||||||
|
|
||||||
query = """
|
query = f"""
|
||||||
query {{
|
query {{
|
||||||
articles (reporter_In: [{}, {}]) {{
|
articles (reporter_In: [{john_doe.id}, {jean_bon.id}]) {{
|
||||||
edges {{
|
edges {{
|
||||||
node {{
|
node {{
|
||||||
headline
|
headline
|
||||||
|
@ -361,10 +363,7 @@ def test_fk_id_in_filter(query):
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
""".format(
|
"""
|
||||||
john_doe.id,
|
|
||||||
jean_bon.id,
|
|
||||||
)
|
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data["articles"]["edges"] == [
|
assert result.data["articles"]["edges"] == [
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django_filters import FilterSet
|
|
||||||
from django_filters import rest_framework as filters
|
|
||||||
from graphene import ObjectType, Schema
|
from graphene import ObjectType, Schema
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from django_filters import FilterSet
|
from django_filters import FilterSet
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
|
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.tests.models import Article, Reporter
|
from graphene_django.tests.models import Article, Reporter
|
||||||
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
from graphene_django.utils import DJANGO_FILTER_INSTALLED
|
||||||
|
@ -14,8 +12,8 @@ pytestmark = []
|
||||||
if DJANGO_FILTER_INSTALLED:
|
if DJANGO_FILTER_INSTALLED:
|
||||||
from graphene_django.filter import (
|
from graphene_django.filter import (
|
||||||
DjangoFilterConnectionField,
|
DjangoFilterConnectionField,
|
||||||
TypedFilter,
|
|
||||||
ListFilter,
|
ListFilter,
|
||||||
|
TypedFilter,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
pytestmark.append(
|
pytestmark.append(
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import graphene
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django_filters.utils import get_model_field, get_field_parts
|
from django_filters.utils import get_model_field
|
||||||
from django_filters.filters import Filter, BaseCSVFilter
|
|
||||||
from .filters import ArrayFilter, ListFilter, RangeFilter, TypedFilter
|
import graphene
|
||||||
from .filterset import custom_filterset_factory, setup_filterset
|
|
||||||
from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||||
|
from .filters import ListFilter, RangeFilter, TypedFilter
|
||||||
|
from .filterset import custom_filterset_factory, setup_filterset
|
||||||
|
|
||||||
|
|
||||||
def get_field_type(registry, model, field_name):
|
def get_field_type(registry, model, field_name):
|
||||||
|
@ -50,7 +51,7 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
||||||
):
|
):
|
||||||
# Get the filter field for filters that are no explicitly declared.
|
# Get the filter field for filters that are no explicitly declared.
|
||||||
if filter_type == "isnull":
|
if filter_type == "isnull":
|
||||||
field = graphene.Boolean(required=required)
|
field_type = graphene.Boolean
|
||||||
else:
|
else:
|
||||||
model_field = get_model_field(model, filter_field.field_name)
|
model_field = get_model_field(model, filter_field.field_name)
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,15 @@ from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
from graphene import (
|
from graphene import (
|
||||||
ID,
|
ID,
|
||||||
|
UUID,
|
||||||
Boolean,
|
Boolean,
|
||||||
|
Date,
|
||||||
|
DateTime,
|
||||||
Decimal,
|
Decimal,
|
||||||
Float,
|
Float,
|
||||||
Int,
|
Int,
|
||||||
List,
|
List,
|
||||||
String,
|
String,
|
||||||
UUID,
|
|
||||||
Date,
|
|
||||||
DateTime,
|
|
||||||
Time,
|
Time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ def get_form_field_description(field):
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def convert_form_field(field):
|
def convert_form_field(field):
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"Don't know how to convert the Django form field %s (%s) "
|
"Don't know how to convert the Django form field {} ({}) "
|
||||||
"to Graphene type" % (field, field.__class__)
|
"to Graphene type".format(field, field.__class__)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import binascii
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.forms import CharField, Field, MultipleChoiceField
|
from django.forms import CharField, Field, MultipleChoiceField
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from graphql_relay import from_global_id
|
from graphql_relay import from_global_id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
|
|
||||||
import graphene
|
|
||||||
from graphene import (
|
from graphene import (
|
||||||
String,
|
|
||||||
Int,
|
|
||||||
Boolean,
|
|
||||||
Decimal,
|
|
||||||
Float,
|
|
||||||
ID,
|
ID,
|
||||||
UUID,
|
UUID,
|
||||||
|
Boolean,
|
||||||
|
Date,
|
||||||
|
DateTime,
|
||||||
|
Decimal,
|
||||||
|
Float,
|
||||||
|
Int,
|
||||||
List,
|
List,
|
||||||
NonNull,
|
NonNull,
|
||||||
DateTime,
|
String,
|
||||||
Date,
|
|
||||||
Time,
|
Time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
|
|
||||||
|
import graphene
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
|
|
||||||
|
from ...tests.models import CHOICES, Film, Reporter
|
||||||
from ..types import DjangoFormInputObjectType
|
from ..types import DjangoFormInputObjectType
|
||||||
from ...tests.models import Reporter, Film, CHOICES
|
|
||||||
|
|
||||||
# Reporter a_choice CHOICES = ((1, "this"), (2, _("that")))
|
# Reporter a_choice CHOICES = ((1, "this"), (2, _("that")))
|
||||||
THIS = CHOICES[0][0]
|
THIS = CHOICES[0][0]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import pytest
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
|
@ -280,7 +279,7 @@ def test_model_form_mutation_mutate_invalid_form():
|
||||||
result = PetMutation.mutate_and_get_payload(None, None)
|
result = PetMutation.mutate_and_get_payload(None, None)
|
||||||
|
|
||||||
# A pet was not created
|
# A pet was not created
|
||||||
Pet.objects.count() == 0
|
assert Pet.objects.count() == 0
|
||||||
|
|
||||||
fields_w_error = [e.field for e in result.errors]
|
fields_w_error = [e.field for e in result.errors]
|
||||||
assert len(result.errors) == 2
|
assert len(result.errors) == 2
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from graphene import ID
|
from graphene import ID
|
||||||
from graphene.types.inputobjecttype import InputObjectType
|
from graphene.types.inputobjecttype import InputObjectType
|
||||||
from graphene.utils.str_converters import to_camel_case
|
from graphene.utils.str_converters import to_camel_case
|
||||||
|
|
||||||
from .mutation import fields_for_form
|
|
||||||
from ..types import ErrorType # noqa Import ErrorType for backwards compatability
|
|
||||||
from ..converter import BlankValueField
|
from ..converter import BlankValueField
|
||||||
|
from ..types import ErrorType # noqa Import ErrorType for backwards compatability
|
||||||
|
from .mutation import fields_for_form
|
||||||
|
|
||||||
|
|
||||||
class DjangoFormInputObjectType(InputObjectType):
|
class DjangoFormInputObjectType(InputObjectType):
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import os
|
import functools
|
||||||
import importlib
|
import importlib
|
||||||
import json
|
import json
|
||||||
import functools
|
import os
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.utils import autoreload
|
from django.utils import autoreload
|
||||||
|
|
||||||
from graphql import print_schema
|
from graphql import print_schema
|
||||||
|
|
||||||
from graphene_django.settings import graphene_settings
|
from graphene_django.settings import graphene_settings
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,7 @@ class Registry:
|
||||||
|
|
||||||
assert issubclass(
|
assert issubclass(
|
||||||
cls, DjangoObjectType
|
cls, DjangoObjectType
|
||||||
), 'Only DjangoObjectTypes can be registered, received "{}"'.format(
|
), f'Only DjangoObjectTypes can be registered, received "{cls.__name__}"'
|
||||||
cls.__name__
|
|
||||||
)
|
|
||||||
assert cls._meta.registry == self, "Registry for a Model have to match."
|
assert cls._meta.registry == self, "Registry for a Model have to match."
|
||||||
# assert self.get_type_for_model(cls._meta.model) == cls, (
|
# assert self.get_type_for_model(cls._meta.model) == cls, (
|
||||||
# 'Multiple DjangoObjectTypes registered for "{}"'.format(cls._meta.model)
|
# 'Multiple DjangoObjectTypes registered for "{}"'.format(cls._meta.model)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
|
@ -5,16 +5,16 @@ from rest_framework import serializers
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from ..registry import get_global_registry
|
|
||||||
from ..converter import convert_choices_to_named_enum_with_descriptions
|
from ..converter import convert_choices_to_named_enum_with_descriptions
|
||||||
|
from ..registry import get_global_registry
|
||||||
from .types import DictType
|
from .types import DictType
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def get_graphene_type_from_serializer_field(field):
|
def get_graphene_type_from_serializer_field(field):
|
||||||
raise ImproperlyConfigured(
|
raise ImproperlyConfigured(
|
||||||
"Don't know how to convert the serializer field %s (%s) "
|
"Don't know how to convert the serializer field {} ({}) "
|
||||||
"to Graphene type" % (field, field.__class__)
|
"to Graphene type".format(field, field.__class__)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
import graphene
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from graphene import InputObjectType
|
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
import graphene
|
||||||
|
|
||||||
from ..serializer_converter import convert_serializer_field
|
from ..serializer_converter import convert_serializer_field
|
||||||
from ..types import DictType
|
from ..types import DictType
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ from graphene.types.inputobjecttype import InputObjectType
|
||||||
from ...types import DjangoObjectType
|
from ...types import DjangoObjectType
|
||||||
from ..models import (
|
from ..models import (
|
||||||
MyFakeModel,
|
MyFakeModel,
|
||||||
|
MyFakeModelWithChoiceField,
|
||||||
MyFakeModelWithDate,
|
MyFakeModelWithDate,
|
||||||
MyFakeModelWithPassword,
|
MyFakeModelWithPassword,
|
||||||
MyFakeModelWithChoiceField,
|
|
||||||
)
|
)
|
||||||
from ..mutation import SerializerMutation
|
from ..mutation import SerializerMutation
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ def test_model_invalid_update_mutate_and_get_payload_success():
|
||||||
model_operations = ["update"]
|
model_operations = ["update"]
|
||||||
|
|
||||||
with raises(Exception) as exc:
|
with raises(Exception) as exc:
|
||||||
result = InvalidModelMutation.mutate_and_get_payload(
|
InvalidModelMutation.mutate_and_get_payload(
|
||||||
None, mock_info(), **{"cool_name": "Narf"}
|
None, mock_info(), **{"cool_name": "Narf"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,10 @@ Graphene settings, checking for user settings first, then falling
|
||||||
back to the defaults.
|
back to the defaults.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.test.signals import setting_changed
|
|
||||||
|
|
||||||
import importlib # Available in Python 3.1+
|
import importlib # Available in Python 3.1+
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.test.signals import setting_changed
|
||||||
|
|
||||||
# Copied shamelessly from Django REST Framework
|
# Copied shamelessly from Django REST Framework
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
# https://github.com/graphql-python/graphene-django/issues/520
|
# https://github.com/graphql-python/graphene-django/issues/520
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
|
||||||
from graphene import Field, ResolveInfo
|
from ...forms.mutation import DjangoFormMutation
|
||||||
from graphene.types.inputobjecttype import InputObjectType
|
|
||||||
from pytest import raises
|
|
||||||
from pytest import mark
|
|
||||||
from rest_framework import serializers
|
|
||||||
|
|
||||||
from ...types import DjangoObjectType
|
|
||||||
from ...rest_framework.models import MyFakeModel
|
from ...rest_framework.models import MyFakeModel
|
||||||
from ...rest_framework.mutation import SerializerMutation
|
from ...rest_framework.mutation import SerializerMutation
|
||||||
from ...forms.mutation import DjangoFormMutation
|
|
||||||
|
|
||||||
|
|
||||||
class MyModelSerializer(serializers.ModelSerializer):
|
class MyModelSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from graphene import Field
|
from graphene import Field
|
||||||
|
|
||||||
from graphene_django.forms.mutation import DjangoFormMutation, DjangoModelFormMutation
|
from graphene_django.forms.mutation import DjangoFormMutation, DjangoModelFormMutation
|
||||||
|
|
||||||
from .forms import PetForm
|
from .forms import PetForm
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
from io import StringIO
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
from unittest.mock import mock_open, patch
|
||||||
|
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from io import StringIO
|
|
||||||
from unittest.mock import mock_open, patch
|
|
||||||
|
|
||||||
from graphene import ObjectType, Schema, String
|
from graphene import ObjectType, Schema, String
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ from .models import Article, Film, FilmDetails, Reporter
|
||||||
|
|
||||||
|
|
||||||
def assert_conversion(django_field, graphene_field, *args, **kwargs):
|
def assert_conversion(django_field, graphene_field, *args, **kwargs):
|
||||||
_kwargs = kwargs.copy()
|
_kwargs = {**kwargs, "help_text": "Custom Help Text"}
|
||||||
if "null" not in kwargs:
|
if "null" not in kwargs:
|
||||||
_kwargs["null"] = True
|
_kwargs["null"] = True
|
||||||
field = django_field(help_text="Custom Help Text", *args, **_kwargs)
|
field = django_field(*args, **_kwargs)
|
||||||
graphene_type = convert_django_field(field)
|
graphene_type = convert_django_field(field)
|
||||||
assert isinstance(graphene_type, graphene_field)
|
assert isinstance(graphene_type, graphene_field)
|
||||||
field = graphene_type.Field()
|
field = graphene_type.Field()
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
from django.db.models import Count, Prefetch
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from django.db.models import Count, Prefetch
|
||||||
|
|
||||||
from graphene import List, NonNull, ObjectType, Schema, String
|
from graphene import List, NonNull, ObjectType, Schema, String
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ class TestDjangoListField:
|
||||||
foo = String()
|
foo = String()
|
||||||
|
|
||||||
with pytest.raises(AssertionError):
|
with pytest.raises(AssertionError):
|
||||||
list_field = DjangoListField(TestType)
|
DjangoListField(TestType)
|
||||||
|
|
||||||
def test_only_import_paths(self):
|
def test_only_import_paths(self):
|
||||||
list_field = DjangoListField("graphene_django.tests.schema.Human")
|
list_field = DjangoListField("graphene_django.tests.schema.Human")
|
||||||
|
|
|
@ -3,7 +3,6 @@ from pytest import raises
|
||||||
|
|
||||||
from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
from ..forms import GlobalIDFormField, GlobalIDMultipleChoiceField
|
||||||
|
|
||||||
|
|
||||||
# 'TXlUeXBlOmFiYw==' -> 'MyType', 'abc'
|
# 'TXlUeXBlOmFiYw==' -> 'MyType', 'abc'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from graphql_relay import to_global_id
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
|
|
||||||
from graphql_relay import to_global_id
|
|
||||||
|
|
||||||
from ..fields import DjangoConnectionField
|
|
||||||
from ..types import DjangoObjectType
|
from ..types import DjangoObjectType
|
||||||
|
from .models import Article, Film, FilmDetails, Reporter
|
||||||
from .models import Article, Reporter, FilmDetails, Film
|
|
||||||
|
|
||||||
|
|
||||||
class TestShouldCallGetQuerySetOnForeignKey:
|
class TestShouldCallGetQuerySetOnForeignKey:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import datetime
|
|
||||||
import base64
|
import base64
|
||||||
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -16,6 +16,7 @@ from ..fields import DjangoConnectionField
|
||||||
from ..types import DjangoObjectType
|
from ..types import DjangoObjectType
|
||||||
from ..utils import DJANGO_FILTER_INSTALLED
|
from ..utils import DJANGO_FILTER_INSTALLED
|
||||||
from .models import (
|
from .models import (
|
||||||
|
APNewsReporter,
|
||||||
Article,
|
Article,
|
||||||
CNNReporter,
|
CNNReporter,
|
||||||
Film,
|
Film,
|
||||||
|
@ -23,7 +24,6 @@ from .models import (
|
||||||
Person,
|
Person,
|
||||||
Pet,
|
Pet,
|
||||||
Reporter,
|
Reporter,
|
||||||
APNewsReporter,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ def test_should_query_well():
|
||||||
@pytest.mark.skipif(IntegerRangeField is MissingType, reason="RangeField should exist")
|
@pytest.mark.skipif(IntegerRangeField is MissingType, reason="RangeField should exist")
|
||||||
def test_should_query_postgres_fields():
|
def test_should_query_postgres_fields():
|
||||||
from django.contrib.postgres.fields import (
|
from django.contrib.postgres.fields import (
|
||||||
IntegerRangeField,
|
|
||||||
ArrayField,
|
ArrayField,
|
||||||
HStoreField,
|
HStoreField,
|
||||||
|
IntegerRangeField,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
|
@ -355,7 +355,7 @@ def test_should_query_connectionfields():
|
||||||
|
|
||||||
|
|
||||||
def test_should_keep_annotations():
|
def test_should_keep_annotations():
|
||||||
from django.db.models import Count, Avg
|
from django.db.models import Avg, Count
|
||||||
|
|
||||||
class ReporterType(DjangoObjectType):
|
class ReporterType(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -517,7 +517,7 @@ def test_should_query_node_filtering_with_distinct_queryset():
|
||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
f = Film.objects.create()
|
f = Film.objects.create()
|
||||||
fd = FilmDetails.objects.create(location="Berlin", film=f)
|
FilmDetails.objects.create(location="Berlin", film=f)
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
||||||
query = """
|
query = """
|
||||||
|
@ -640,7 +640,7 @@ def test_should_enforce_first_or_last(graphene_settings):
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
all_reporters = DjangoConnectionField(ReporterType)
|
all_reporters = DjangoConnectionField(ReporterType)
|
||||||
|
|
||||||
r = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -682,7 +682,7 @@ def test_should_error_if_first_is_greater_than_max(graphene_settings):
|
||||||
|
|
||||||
assert Query.all_reporters.max_limit == 100
|
assert Query.all_reporters.max_limit == 100
|
||||||
|
|
||||||
r = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -724,7 +724,7 @@ def test_should_error_if_last_is_greater_than_max(graphene_settings):
|
||||||
|
|
||||||
assert Query.all_reporters.max_limit == 100
|
assert Query.all_reporters.max_limit == 100
|
||||||
|
|
||||||
r = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -788,7 +788,7 @@ def test_should_query_promise_connectionfields():
|
||||||
|
|
||||||
|
|
||||||
def test_should_query_connectionfields_with_last():
|
def test_should_query_connectionfields_with_last():
|
||||||
r = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -825,11 +825,11 @@ def test_should_query_connectionfields_with_last():
|
||||||
|
|
||||||
|
|
||||||
def test_should_query_connectionfields_with_manager():
|
def test_should_query_connectionfields_with_manager():
|
||||||
r = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
r = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="NotDoe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="NotDoe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1369,10 +1369,10 @@ def test_model_inheritance_support_local_relationships():
|
||||||
|
|
||||||
|
|
||||||
def test_should_resolve_get_queryset_connectionfields():
|
def test_should_resolve_get_queryset_connectionfields():
|
||||||
reporter_1 = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
reporter_2 = CNNReporter.objects.create(
|
CNNReporter.objects.create(
|
||||||
first_name="Some",
|
first_name="Some",
|
||||||
last_name="Guy",
|
last_name="Guy",
|
||||||
email="someguy@cnn.com",
|
email="someguy@cnn.com",
|
||||||
|
@ -1414,10 +1414,10 @@ def test_should_resolve_get_queryset_connectionfields():
|
||||||
|
|
||||||
|
|
||||||
def test_connection_should_limit_after_to_list_length():
|
def test_connection_should_limit_after_to_list_length():
|
||||||
reporter_1 = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
first_name="John", last_name="Doe", email="johndoe@example.com", a_choice=1
|
||||||
)
|
)
|
||||||
reporter_2 = Reporter.objects.create(
|
Reporter.objects.create(
|
||||||
first_name="Some", last_name="Guy", email="someguy@cnn.com", a_choice=1
|
first_name="Some", last_name="Guy", email="someguy@cnn.com", a_choice=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1444,19 +1444,19 @@ def test_connection_should_limit_after_to_list_length():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
after = base64.b64encode(b"arrayconnection:10").decode()
|
after = base64.b64encode(b"arrayconnection:10").decode()
|
||||||
result = schema.execute(query, variable_values=dict(after=after))
|
result = schema.execute(query, variable_values={"after": after})
|
||||||
expected = {"allReporters": {"edges": []}}
|
expected = {"allReporters": {"edges": []}}
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
|
||||||
REPORTERS = [
|
REPORTERS = [
|
||||||
dict(
|
{
|
||||||
first_name=f"First {i}",
|
"first_name": f"First {i}",
|
||||||
last_name=f"Last {i}",
|
"last_name": f"Last {i}",
|
||||||
email=f"johndoe+{i}@example.com",
|
"email": f"johndoe+{i}@example.com",
|
||||||
a_choice=1,
|
"a_choice": 1,
|
||||||
)
|
}
|
||||||
for i in range(6)
|
for i in range(6)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1531,7 +1531,7 @@ def test_should_have_next_page(graphene_settings):
|
||||||
assert result.data["allReporters"]["pageInfo"]["hasNextPage"]
|
assert result.data["allReporters"]["pageInfo"]["hasNextPage"]
|
||||||
|
|
||||||
last_result = result.data["allReporters"]["pageInfo"]["endCursor"]
|
last_result = result.data["allReporters"]["pageInfo"]["endCursor"]
|
||||||
result2 = schema.execute(query, variable_values=dict(first=4, after=last_result))
|
result2 = schema.execute(query, variable_values={"first": 4, "after": last_result})
|
||||||
assert not result2.errors
|
assert not result2.errors
|
||||||
assert len(result2.data["allReporters"]["edges"]) == 2
|
assert len(result2.data["allReporters"]["edges"]) == 2
|
||||||
assert not result2.data["allReporters"]["pageInfo"]["hasNextPage"]
|
assert not result2.data["allReporters"]["pageInfo"]["hasNextPage"]
|
||||||
|
@ -1622,7 +1622,7 @@ class TestBackwardPagination:
|
||||||
after = base64.b64encode(b"arrayconnection:0").decode()
|
after = base64.b64encode(b"arrayconnection:0").decode()
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
query_first_last_and_after,
|
query_first_last_and_after,
|
||||||
variable_values=dict(after=after),
|
variable_values={"after": after},
|
||||||
)
|
)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert len(result.data["allReporters"]["edges"]) == 3
|
assert len(result.data["allReporters"]["edges"]) == 3
|
||||||
|
@ -1654,7 +1654,7 @@ class TestBackwardPagination:
|
||||||
before = base64.b64encode(b"arrayconnection:5").decode()
|
before = base64.b64encode(b"arrayconnection:5").decode()
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
query_first_last_and_after,
|
query_first_last_and_after,
|
||||||
variable_values=dict(before=before),
|
variable_values={"before": before},
|
||||||
)
|
)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert len(result.data["allReporters"]["edges"]) == 1
|
assert len(result.data["allReporters"]["edges"]) == 1
|
||||||
|
@ -1710,7 +1710,7 @@ def test_should_preserve_prefetch_related(django_assert_num_queries):
|
||||||
"""
|
"""
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
||||||
|
|
||||||
with django_assert_num_queries(3) as captured:
|
with django_assert_num_queries(3):
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
|
||||||
|
@ -1877,7 +1877,7 @@ def test_connection_should_forbid_offset_filtering_with_before():
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
before = base64.b64encode(b"arrayconnection:2").decode()
|
before = base64.b64encode(b"arrayconnection:2").decode()
|
||||||
result = schema.execute(query, variable_values=dict(before=before))
|
result = schema.execute(query, variable_values={"before": before})
|
||||||
expected_error = "You can't provide a `before` value at the same time as an `offset` value to properly paginate the `allReporters` connection."
|
expected_error = "You can't provide a `before` value at the same time as an `offset` value to properly paginate the `allReporters` connection."
|
||||||
assert len(result.errors) == 1
|
assert len(result.errors) == 1
|
||||||
assert result.errors[0].message == expected_error
|
assert result.errors[0].message == expected_error
|
||||||
|
@ -1913,7 +1913,7 @@ def test_connection_should_allow_offset_filtering_with_after():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
after = base64.b64encode(b"arrayconnection:0").decode()
|
after = base64.b64encode(b"arrayconnection:0").decode()
|
||||||
result = schema.execute(query, variable_values=dict(after=after))
|
result = schema.execute(query, variable_values={"after": after})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {
|
"allReporters": {
|
||||||
|
@ -1949,7 +1949,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = schema.execute(query, variable_values=dict(last=2))
|
result = schema.execute(query, variable_values={"last": 2})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {"allReporters": {"edges": []}}
|
expected = {"allReporters": {"edges": []}}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
@ -1959,7 +1959,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
Reporter.objects.create(first_name="Jane", last_name="Roe")
|
Reporter.objects.create(first_name="Jane", last_name="Roe")
|
||||||
Reporter.objects.create(first_name="Some", last_name="Lady")
|
Reporter.objects.create(first_name="Some", last_name="Lady")
|
||||||
|
|
||||||
result = schema.execute(query, variable_values=dict(last=2))
|
result = schema.execute(query, variable_values={"last": 2})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {
|
"allReporters": {
|
||||||
|
@ -1971,7 +1971,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
result = schema.execute(query, variable_values=dict(last=4))
|
result = schema.execute(query, variable_values={"last": 4})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {
|
"allReporters": {
|
||||||
|
@ -1985,7 +1985,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
result = schema.execute(query, variable_values=dict(last=20))
|
result = schema.execute(query, variable_values={"last": 20})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {
|
expected = {
|
||||||
"allReporters": {
|
"allReporters": {
|
||||||
|
@ -2022,7 +2022,7 @@ def test_should_query_nullable_foreign_key():
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
||||||
|
|
||||||
person = Person.objects.create(name="Jane")
|
person = Person.objects.create(name="Jane")
|
||||||
pets = [
|
[
|
||||||
Pet.objects.create(name="Stray dog", age=1),
|
Pet.objects.create(name="Stray dog", age=1),
|
||||||
Pet.objects.create(name="Jane's dog", owner=person, age=1),
|
Pet.objects.create(name="Jane's dog", owner=person, age=1),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from collections import OrderedDict, defaultdict
|
from collections import OrderedDict, defaultdict
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from graphene import Connection, Field, Interface, ObjectType, Schema, String
|
from graphene import Connection, Field, Interface, ObjectType, Schema, String
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
|
@ -11,8 +11,10 @@ from graphene.relay import Node
|
||||||
from .. import registry
|
from .. import registry
|
||||||
from ..filter import DjangoFilterConnectionField
|
from ..filter import DjangoFilterConnectionField
|
||||||
from ..types import DjangoObjectType, DjangoObjectTypeOptions
|
from ..types import DjangoObjectType, DjangoObjectTypeOptions
|
||||||
from .models import Article as ArticleModel
|
from .models import (
|
||||||
from .models import Reporter as ReporterModel
|
Article as ArticleModel,
|
||||||
|
Reporter as ReporterModel,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Reporter(DjangoObjectType):
|
class Reporter(DjangoObjectType):
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
from ..utils import camelize, get_model_fields, get_reverse_fields, GraphQLTestCase
|
from ..utils import GraphQLTestCase, camelize, get_model_fields, get_reverse_fields
|
||||||
from .models import Film, Reporter, CNNReporter, APNewsReporter
|
|
||||||
from ..utils.testing import graphql_query
|
from ..utils.testing import graphql_query
|
||||||
|
from .models import APNewsReporter, CNNReporter, Film, Reporter
|
||||||
|
|
||||||
|
|
||||||
def test_get_model_fields_no_duplication():
|
def test_get_model_fields_no_duplication():
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
from graphene_django.settings import graphene_settings
|
|
||||||
|
|
||||||
from .models import Pet
|
from .models import Pet
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -31,8 +27,12 @@ def response_json(response):
|
||||||
return json.loads(response.content.decode())
|
return json.loads(response.content.decode())
|
||||||
|
|
||||||
|
|
||||||
j = lambda **kwargs: json.dumps(kwargs)
|
def j(**kwargs):
|
||||||
jl = lambda **kwargs: json.dumps([kwargs])
|
return json.dumps(kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def jl(**kwargs):
|
||||||
|
return json.dumps([kwargs])
|
||||||
|
|
||||||
|
|
||||||
def test_graphiql_is_enabled(client):
|
def test_graphiql_is_enabled(client):
|
||||||
|
@ -229,7 +229,7 @@ def test_allows_sending_a_mutation_via_post(client):
|
||||||
def test_allows_post_with_url_encoding(client):
|
def test_allows_post_with_url_encoding(client):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_string(),
|
url_string(),
|
||||||
urlencode(dict(query="{test}")),
|
urlencode({"query": "{test}"}),
|
||||||
"application/x-www-form-urlencoded",
|
"application/x-www-form-urlencoded",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -303,10 +303,10 @@ def test_supports_post_url_encoded_query_with_string_variables(client):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_string(),
|
url_string(),
|
||||||
urlencode(
|
urlencode(
|
||||||
dict(
|
{
|
||||||
query="query helloWho($who: String){ test(who: $who) }",
|
"query": "query helloWho($who: String){ test(who: $who) }",
|
||||||
variables=json.dumps({"who": "Dolly"}),
|
"variables": json.dumps({"who": "Dolly"}),
|
||||||
)
|
}
|
||||||
),
|
),
|
||||||
"application/x-www-form-urlencoded",
|
"application/x-www-form-urlencoded",
|
||||||
)
|
)
|
||||||
|
@ -329,7 +329,7 @@ def test_supports_post_json_quey_with_get_variable_values(client):
|
||||||
def test_post_url_encoded_query_with_get_variable_values(client):
|
def test_post_url_encoded_query_with_get_variable_values(client):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
url_string(variables=json.dumps({"who": "Dolly"})),
|
url_string(variables=json.dumps({"who": "Dolly"})),
|
||||||
urlencode(dict(query="query helloWho($who: String){ test(who: $who) }")),
|
urlencode({"query": "query helloWho($who: String){ test(who: $who) }"}),
|
||||||
"application/x-www-form-urlencoded",
|
"application/x-www-form-urlencoded",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ def test_handles_django_request_error(client, monkeypatch):
|
||||||
|
|
||||||
monkeypatch.setattr("django.http.request.HttpRequest.read", mocked_read)
|
monkeypatch.setattr("django.http.request.HttpRequest.read", mocked_read)
|
||||||
|
|
||||||
valid_json = json.dumps(dict(foo="bar"))
|
valid_json = json.dumps({"foo": "bar"})
|
||||||
response = client.post(url_string(), valid_json, "application/json")
|
response = client.post(url_string(), valid_json, "application/json")
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import warnings
|
import warnings
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from typing import Type
|
from typing import Type # noqa: F401
|
||||||
|
|
||||||
|
from django.db.models import Model # noqa: F401
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from django.db.models import Model
|
|
||||||
from graphene.relay import Connection, Node
|
from graphene.relay import Connection, Node
|
||||||
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
||||||
from graphene.types.utils import yank_fields_from_attrs
|
from graphene.types.utils import yank_fields_from_attrs
|
||||||
|
@ -149,7 +150,7 @@ class DjangoObjectType(ObjectType):
|
||||||
interfaces=(),
|
interfaces=(),
|
||||||
convert_choices_to_enum=True,
|
convert_choices_to_enum=True,
|
||||||
_meta=None,
|
_meta=None,
|
||||||
**options
|
**options,
|
||||||
):
|
):
|
||||||
assert is_valid_django_model(model), (
|
assert is_valid_django_model(model), (
|
||||||
'You need to pass a valid Django Model in {}.Meta, received "{}".'
|
'You need to pass a valid Django Model in {}.Meta, received "{}".'
|
||||||
|
@ -239,9 +240,9 @@ class DjangoObjectType(ObjectType):
|
||||||
)
|
)
|
||||||
|
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
assert issubclass(connection, Connection), (
|
assert issubclass(
|
||||||
"The connection must be a Connection. Received {}"
|
connection, Connection
|
||||||
).format(connection.__name__)
|
), f"The connection must be a Connection. Received {connection.__name__}"
|
||||||
|
|
||||||
if not _meta:
|
if not _meta:
|
||||||
_meta = DjangoObjectTypeOptions(cls)
|
_meta = DjangoObjectTypeOptions(cls)
|
||||||
|
@ -272,7 +273,7 @@ class DjangoObjectType(ObjectType):
|
||||||
if isinstance(root, cls):
|
if isinstance(root, cls):
|
||||||
return True
|
return True
|
||||||
if not is_valid_django_model(root.__class__):
|
if not is_valid_django_model(root.__class__):
|
||||||
raise Exception(('Received incompatible instance "{}".').format(root))
|
raise Exception(f'Received incompatible instance "{root}".')
|
||||||
|
|
||||||
if cls._meta.model._meta.proxy:
|
if cls._meta.model._meta.proxy:
|
||||||
model = root._meta.model
|
model = root._meta.model
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
from .testing import GraphQLTestCase
|
from .testing import GraphQLTestCase
|
||||||
from .utils import (
|
from .utils import (
|
||||||
DJANGO_FILTER_INSTALLED,
|
DJANGO_FILTER_INSTALLED,
|
||||||
|
bypass_get_queryset,
|
||||||
camelize,
|
camelize,
|
||||||
get_model_fields,
|
get_model_fields,
|
||||||
get_reverse_fields,
|
get_reverse_fields,
|
||||||
is_valid_django_model,
|
is_valid_django_model,
|
||||||
maybe_queryset,
|
maybe_queryset,
|
||||||
bypass_get_queryset,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from text_unidecode import unidecode
|
from text_unidecode import unidecode
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .. import GraphQLTestCase
|
|
||||||
from ...tests.test_types import with_local_registry
|
|
||||||
from ...settings import graphene_settings
|
|
||||||
from django.test import Client
|
from django.test import Client
|
||||||
|
|
||||||
|
from ...settings import graphene_settings
|
||||||
|
from ...tests.test_types import with_local_registry
|
||||||
|
from .. import GraphQLTestCase
|
||||||
|
|
||||||
|
|
||||||
@with_local_registry
|
@with_local_registry
|
||||||
def test_graphql_test_case_deprecated_client_getter():
|
def test_graphql_test_case_deprecated_client_getter():
|
||||||
|
@ -23,7 +23,7 @@ def test_graphql_test_case_deprecated_client_getter():
|
||||||
tc.setUpClass()
|
tc.setUpClass()
|
||||||
|
|
||||||
with pytest.warns(PendingDeprecationWarning):
|
with pytest.warns(PendingDeprecationWarning):
|
||||||
tc._client
|
tc._client # noqa: B018
|
||||||
|
|
||||||
|
|
||||||
@with_local_registry
|
@with_local_registry
|
||||||
|
|
|
@ -12,10 +12,9 @@ from django.views.generic import View
|
||||||
from graphql import OperationType, get_operation_ast, parse
|
from graphql import OperationType, get_operation_ast, parse
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError
|
||||||
from graphql.execution import ExecutionResult
|
from graphql.execution import ExecutionResult
|
||||||
|
|
||||||
from graphene import Schema
|
|
||||||
from graphql.execution.middleware import MiddlewareManager
|
from graphql.execution.middleware import MiddlewareManager
|
||||||
|
|
||||||
|
from graphene import Schema
|
||||||
from graphene_django.constants import MUTATION_ERRORS_FLAG
|
from graphene_django.constants import MUTATION_ERRORS_FLAG
|
||||||
from graphene_django.utils.utils import set_rollback
|
from graphene_django.utils.utils import set_rollback
|
||||||
|
|
||||||
|
@ -40,9 +39,9 @@ def get_accepted_content_types(request):
|
||||||
|
|
||||||
raw_content_types = request.META.get("HTTP_ACCEPT", "*/*").split(",")
|
raw_content_types = request.META.get("HTTP_ACCEPT", "*/*").split(",")
|
||||||
qualified_content_types = map(qualify, raw_content_types)
|
qualified_content_types = map(qualify, raw_content_types)
|
||||||
return list(
|
return [
|
||||||
x[0] for x in sorted(qualified_content_types, key=lambda x: x[1], reverse=True)
|
x[0] for x in sorted(qualified_content_types, key=lambda x: x[1], reverse=True)
|
||||||
)
|
]
|
||||||
|
|
||||||
|
|
||||||
def instantiate_middleware(middlewares):
|
def instantiate_middleware(middlewares):
|
||||||
|
|
37
setup.cfg
37
setup.cfg
|
@ -4,46 +4,9 @@ test=pytest
|
||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal=1
|
universal=1
|
||||||
|
|
||||||
[flake8]
|
|
||||||
exclude = docs,graphene_django/debug/sql/*
|
|
||||||
max-line-length = 120
|
|
||||||
select =
|
|
||||||
# Dictionary key repeated
|
|
||||||
F601,
|
|
||||||
# Ensure use of ==/!= to compare with str, bytes and int literals
|
|
||||||
F632,
|
|
||||||
# Redefinition of unused name
|
|
||||||
F811,
|
|
||||||
# Using an undefined variable
|
|
||||||
F821,
|
|
||||||
# Defining an undefined variable in __all__
|
|
||||||
F822,
|
|
||||||
# Using a variable before it is assigned
|
|
||||||
F823,
|
|
||||||
# Duplicate argument in function declaration
|
|
||||||
F831,
|
|
||||||
# Black would format this line
|
|
||||||
BLK,
|
|
||||||
# Do not use bare except
|
|
||||||
B001,
|
|
||||||
# Don't allow ++n. You probably meant n += 1
|
|
||||||
B002,
|
|
||||||
# Do not use mutable structures for argument defaults
|
|
||||||
B006,
|
|
||||||
# Do not perform calls in argument defaults
|
|
||||||
B008
|
|
||||||
|
|
||||||
[coverage:run]
|
[coverage:run]
|
||||||
omit = */tests/*
|
omit = */tests/*
|
||||||
|
|
||||||
[isort]
|
|
||||||
known_first_party=graphene,graphene_django
|
|
||||||
multi_line_output=3
|
|
||||||
include_trailing_comma=True
|
|
||||||
force_grid_wrap=0
|
|
||||||
use_parentheses=True
|
|
||||||
line_length=88
|
|
||||||
|
|
||||||
[tool:pytest]
|
[tool:pytest]
|
||||||
DJANGO_SETTINGS_MODULE = examples.django_test_settings
|
DJANGO_SETTINGS_MODULE = examples.django_test_settings
|
||||||
addopts = --random-order
|
addopts = --random-order
|
||||||
|
|
Loading…
Reference in New Issue
Block a user