Skip to content

Commit

Permalink
Add test to confirm default_value setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimbo committed Jun 30, 2020
1 parent 5b2eb11 commit a5e0652
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions graphene/types/tests/test_inputfield.py
@@ -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


Expand All @@ -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}

0 comments on commit a5e0652

Please sign in to comment.