mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 01:26:49 +03:00
Add test to confirm default_value setting
This commit is contained in:
parent
5b2eb1109a
commit
a5e0652585
|
@ -1,7 +1,12 @@
|
|||
from functools import partial
|
||||
|
||||
from ..inputfield import InputField
|
||||
from ..inputobjecttype import InputObjectType
|
||||
from ..scalars import String, Boolean
|
||||
from ..objecttype import ObjectType
|
||||
from ..structures import NonNull
|
||||
from ..schema import Schema
|
||||
from ..mutation import Mutation
|
||||
from .utils import MyLazyType
|
||||
|
||||
|
||||
|
@ -27,3 +32,36 @@ def test_inputfield_with_lazy_partial_type():
|
|||
def test_inputfield_with_string_type():
|
||||
field = InputField("graphene.types.tests.utils.MyLazyType")
|
||||
assert field.type == MyLazyType
|
||||
|
||||
|
||||
def test_inputfield_with_default_value():
|
||||
class MyInput(InputObjectType):
|
||||
name = InputField(String, default_value="Emma", required=True)
|
||||
good_person = InputField(Boolean, default_value=True, required=True)
|
||||
|
||||
class Query(ObjectType):
|
||||
a = String()
|
||||
|
||||
class TestMutation(Mutation):
|
||||
class Arguments:
|
||||
my_field = MyInput(required=True)
|
||||
|
||||
Output = Boolean
|
||||
|
||||
def mutate(root, info, my_field):
|
||||
return my_field.good_person
|
||||
|
||||
class MyMutation(ObjectType):
|
||||
test_mutation = TestMutation.Field(required=True)
|
||||
|
||||
schema = Schema(query=Query, mutation=MyMutation)
|
||||
result = schema.execute(
|
||||
"""
|
||||
mutation {
|
||||
testMutation(myField: {})
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
assert not result.errors
|
||||
assert result.data == {"testMutation": True}
|
||||
|
|
Loading…
Reference in New Issue
Block a user