mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-13 05:34:20 +03:00
fix: tests
This commit is contained in:
parent
6c3da8e1d5
commit
f8747e4598
|
@ -12,12 +12,13 @@ try:
|
|||
IntegerRangeField,
|
||||
RangeField,
|
||||
)
|
||||
from django.db.models import Choices
|
||||
|
||||
try:
|
||||
from django.db.models import JSONField
|
||||
except ImportError:
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
except ImportError:
|
||||
IntegerRangeField, ArrayField, HStoreField, RangeField, JSONField = (
|
||||
IntegerRangeField, ArrayField, HStoreField, RangeField, JSONField, Choices = (
|
||||
MissingType,
|
||||
) * 5
|
||||
) * 6
|
||||
|
|
|
@ -37,7 +37,7 @@ except ImportError:
|
|||
from graphql import assert_valid_name as assert_name
|
||||
from graphql.pyutils import register_description
|
||||
|
||||
from .compat import ArrayField, HStoreField, RangeField, JSONField
|
||||
from .compat import ArrayField, HStoreField, JSONField, RangeField
|
||||
from .fields import DjangoConnectionField, DjangoListField
|
||||
from .settings import graphene_settings
|
||||
from .utils.str_converters import to_const
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from django.db import models
|
||||
|
||||
from ..compat import Choices, MissingType
|
||||
|
||||
|
||||
class MyFakeModel(models.Model):
|
||||
cool_name = models.CharField(max_length=50)
|
||||
|
@ -16,12 +18,19 @@ class MyFakeModelWithDate(models.Model):
|
|||
last_edited = models.DateField()
|
||||
|
||||
|
||||
class MyFakeModelWithChoiceField(models.Model):
|
||||
class ChoiceType(models.Choices):
|
||||
ASDF = "asdf"
|
||||
HI = "hi"
|
||||
if Choices is not MissingType:
|
||||
|
||||
choice_type = models.CharField(
|
||||
max_length=4,
|
||||
default=ChoiceType.HI.name,
|
||||
)
|
||||
class MyFakeModelWithChoiceField(models.Model):
|
||||
class ChoiceType(Choices):
|
||||
ASDF = "asdf"
|
||||
HI = "hi"
|
||||
|
||||
choice_type = models.CharField(
|
||||
max_length=4,
|
||||
default=ChoiceType.HI.name,
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
class MyFakeModelWithChoiceField:
|
||||
...
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import datetime
|
||||
|
||||
import pytest
|
||||
from pytest import raises
|
||||
from rest_framework import serializers
|
||||
|
||||
from graphene import Field, ResolveInfo
|
||||
from graphene.types.inputobjecttype import InputObjectType
|
||||
|
||||
from ...compat import Choices, MissingType
|
||||
from ...types import DjangoObjectType
|
||||
from ..models import (
|
||||
MyFakeModel,
|
||||
|
@ -273,6 +275,7 @@ def test_perform_mutate_success():
|
|||
assert result.days_since_last_edit == 4
|
||||
|
||||
|
||||
@pytest.mark.skipif(Choices is MissingType, reason="Choices should exist")
|
||||
def test_perform_mutate_success_with_enum_choice_field():
|
||||
class ListViewChoiceFieldSerializer(serializers.ModelSerializer):
|
||||
choice_type = serializers.ChoiceField(
|
||||
|
|
|
@ -11,7 +11,7 @@ from pytest import raises
|
|||
import graphene
|
||||
from graphene.relay import Node
|
||||
|
||||
from ..compat import IntegerRangeField, MissingType, JSONField
|
||||
from ..compat import IntegerRangeField, JSONField, MissingType
|
||||
from ..fields import DjangoConnectionField
|
||||
from ..types import DjangoObjectType
|
||||
from ..utils import DJANGO_FILTER_INSTALLED
|
||||
|
|
Loading…
Reference in New Issue
Block a user