Skip to content

Commit 330c5e6

Browse files
committed
Add unit tests for isRequired predicates
Replicates graphql/graphql-js@f474a4e
1 parent 4d3b782 commit 330c5e6

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

tests/type/test_predicate.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from pytest import raises
22

33
from graphql.type import (
4-
GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType,
5-
GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
4+
GraphQLArgument, GraphQLEnumType, GraphQLInputField,
5+
GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList,
6+
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
67
GraphQLString, GraphQLUnionType,
78
assert_abstract_type, assert_composite_type, assert_enum_type,
89
assert_input_object_type, assert_input_type, assert_interface_type,
@@ -12,6 +13,7 @@
1213
assert_wrapping_type, get_named_type, get_nullable_type, is_abstract_type,
1314
is_composite_type, is_enum_type, is_input_object_type, is_input_type,
1415
is_interface_type, is_leaf_type, is_list_type, is_named_type,
16+
is_required_argument, is_required_input_field,
1517
is_non_null_type, is_nullable_type, is_object_type, is_output_type,
1618
is_scalar_type, is_type, is_union_type, is_wrapping_type)
1719

@@ -370,3 +372,47 @@ def unwraps_wrapper_types():
370372
def unwraps_deeply_wrapper_types():
371373
assert get_named_type(GraphQLNonNull(GraphQLList(GraphQLNonNull(
372374
ObjectType)))) is ObjectType
375+
376+
def describe_is_required_argument():
377+
378+
def returns_true_for_required_arguments():
379+
required_arg = GraphQLArgument(GraphQLNonNull(GraphQLString))
380+
assert is_required_argument(required_arg) is True
381+
382+
def returns_false_for_optional_arguments():
383+
opt_arg1 = GraphQLArgument(GraphQLString)
384+
assert is_required_argument(opt_arg1) is False
385+
386+
opt_arg2 = GraphQLArgument(GraphQLString, default_value=None)
387+
assert is_required_argument(opt_arg2) is False
388+
389+
opt_arg3 = GraphQLArgument(
390+
GraphQLList(GraphQLNonNull(GraphQLString)))
391+
assert is_required_argument(opt_arg3) is False
392+
393+
opt_arg4 = GraphQLArgument(
394+
GraphQLNonNull(GraphQLString), default_value='default')
395+
assert is_required_argument(opt_arg4) is False
396+
397+
def describe_is_required_input_field():
398+
399+
def returns_true_for_required_input_field():
400+
required_field = GraphQLInputField(
401+
GraphQLNonNull(GraphQLString))
402+
assert is_required_input_field(required_field) is True
403+
404+
def returns_false_for_optional_input_field():
405+
opt_field1 = GraphQLInputField(GraphQLString)
406+
assert is_required_input_field(opt_field1) is False
407+
408+
opt_field2 = GraphQLInputField(
409+
GraphQLString, default_value=None)
410+
assert is_required_input_field(opt_field2) is False
411+
412+
opt_field3 = GraphQLInputField(
413+
GraphQLList(GraphQLNonNull(GraphQLString)))
414+
assert is_required_input_field(opt_field3) is False
415+
416+
opt_field4 = GraphQLInputField(
417+
GraphQLNonNull(GraphQLString), default_value='default')
418+
assert is_required_input_field(opt_field4) is False

0 commit comments

Comments
 (0)