mirror of
https://github.com/graphql-python/graphene.git
synced 2025-07-26 07:49:53 +03:00
Add test for callable default value.
This commit is contained in:
parent
fce0b85b8a
commit
dd72759396
|
@ -18,7 +18,7 @@ def source_resolver(source, root, args, context, info):
|
|||
|
||||
class Field(OrderedType):
|
||||
|
||||
def __init__(self, type, args=None, resolver=None, source=None,
|
||||
def __init__(self, object_type, args=None, resolver=None, source=None,
|
||||
deprecation_reason=None, name=None, description=None,
|
||||
required=False, _creation_counter=None, default_value=None,
|
||||
**extra_args):
|
||||
|
@ -29,12 +29,15 @@ class Field(OrderedType):
|
|||
assert not (source and resolver), (
|
||||
'A Field cannot have a source and a resolver in at the same time.'
|
||||
)
|
||||
assert not callable(default_value), (
|
||||
'The default value can not be a function but received "{}".'
|
||||
).format(type(default_value))
|
||||
|
||||
if required or default_value is not None:
|
||||
type = NonNull(type)
|
||||
object_type = NonNull(object_type)
|
||||
|
||||
self.name = name
|
||||
self._type = type
|
||||
self._type = object_type
|
||||
self.args = to_arguments(args or OrderedDict(), extra_args)
|
||||
if source:
|
||||
resolver = partial(source_resolver, source)
|
||||
|
|
|
@ -41,6 +41,14 @@ def test_field_required():
|
|||
assert field.type.of_type == MyType
|
||||
|
||||
|
||||
def test_field_default_value_not_callable():
|
||||
MyType = object()
|
||||
try:
|
||||
Field(MyType, default_value=lambda: True)
|
||||
except AssertionError as e:
|
||||
assert str(e) == 'The default value can not be a function but received "<type \'function\'>".'
|
||||
|
||||
|
||||
def test_field_source():
|
||||
MyType = object()
|
||||
field = Field(MyType, source='value')
|
||||
|
|
Loading…
Reference in New Issue
Block a user