Add tests

This commit is contained in:
Jonathan Kim 2019-06-13 17:19:22 +01:00
parent 010f3c217c
commit 0afd512bb2
2 changed files with 92 additions and 1 deletions

View File

@ -196,6 +196,24 @@ def test_field_with_choices_collision():
convert_django_field_with_choices(field)
def test_field_with_choices_convert_enum_false():
field = models.CharField(
help_text="Language", choices=(("es", "Spanish"), ("en", "English"))
)
class TranslatedModel(models.Model):
language = field
class Meta:
app_label = "test"
graphene_type = convert_django_field_with_choices(
field,
convert_choices_to_enum=False
)
assert isinstance(graphene_type, graphene.String)
def test_should_float_convert_float():
assert_conversion(models.FloatField, graphene.Float)

View File

@ -1,6 +1,10 @@
from textwrap import dedent
import pytest
from django.db import models
from mock import patch
from graphene import Interface, ObjectType, Schema, Connection, String
from graphene import Connection, Field, Interface, ObjectType, Schema, String
from graphene.relay import Node
from .. import registry
@ -224,3 +228,72 @@ def test_django_objecttype_exclude_fields():
fields = list(Reporter._meta.fields.keys())
assert "email" not in fields
class TestDjangoObjectType():
@pytest.fixture
def PetModel(self):
class PetModel(models.Model):
kind = models.CharField(choices=(('cat', 'Cat'), ('dog', 'Dog')))
cuteness = models.IntegerField(choices=(
(1, 'Kind of cute'), (2, 'Pretty cute'), (3, 'OMG SO CUTE!!!')))
return PetModel
def test_django_objecttype_convert_choices_enum_false(self, PetModel):
class Pet(DjangoObjectType):
class Meta:
model = PetModel
convert_choices_to_enum = False
class Query(ObjectType):
pet = Field(Pet)
schema = Schema(query=Query)
assert str(schema) == dedent("""\
schema {
query: Query
}
type Pet {
id: ID!
kind: String!
cuteness: Int!
}
type Query {
pet: Pet
}
""")
def test_django_objecttype_convert_choices_enum_list(self, PetModel):
class Pet(DjangoObjectType):
class Meta:
model = PetModel
convert_choices_to_enum = ['kind']
class Query(ObjectType):
pet = Field(Pet)
schema = Schema(query=Query)
assert str(schema) == dedent("""\
schema {
query: Query
}
type Pet {
id: ID!
kind: PetModelKind!
cuteness: Int!
}
enum PetModelKind {
CAT
DOG
}
type Query {
pet: Pet
}
""")