Skip to content

Commit f241b36

Browse files
committed
Add testcases for nested list coercion
Replicates graphql/graphql-js@dec24f9
1 parent 4d73f7e commit f241b36

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ a query language for APIs created by Facebook.
1212
[![Python 3 Status](https://pyup.io/repos/github/graphql-python/graphql-core-next/python-3-shield.svg)](https://pyup.io/repos/github/graphql-python/graphql-core-next/)
1313

1414
The current version 1.0.1 of GraphQL-core-next is up-to-date with GraphQL.js version
15-
14.0.2. All parts of the API are covered by an extensive test suite of currently 1626
15+
14.0.2. All parts of the API are covered by an extensive test suite of currently 1635
1616
unit tests.
1717

1818

tests/utilities/test_coerce_value.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
GraphQLInputField,
1010
GraphQLInputObjectType,
1111
GraphQLInt,
12+
GraphQLList,
1213
GraphQLNonNull,
1314
GraphQLString,
1415
)
@@ -199,13 +200,13 @@ def returns_no_error_for_a_valid_input():
199200
result = coerce_value({"foo": 123}, TestInputObject)
200201
assert expect_value(result) == {"foo": 123}
201202

202-
def returns_error_for_a_non_dict_value():
203+
def returns_an_error_for_a_non_dict_value():
203204
result = coerce_value(123, TestInputObject)
204205
assert expect_error(result) == [
205206
"Expected type TestInputObject to be a dict."
206207
]
207208

208-
def returns_error_for_an_invalid_field():
209+
def returns_an_error_for_an_invalid_field():
209210
result = coerce_value({"foo": "abc"}, TestInputObject)
210211
assert expect_error(result) == [
211212
"Expected type Int at value.foo;"
@@ -239,3 +240,50 @@ def returns_error_for_a_misspelled_field():
239240
"Field 'bart' is not defined by type TestInputObject;"
240241
" did you mean bar?"
241242
]
243+
244+
def describe_for_graphql_list():
245+
TestList = GraphQLList(GraphQLInt)
246+
247+
def returns_no_error_for_a_valid_input():
248+
result = coerce_value([1, 2, 3], TestList)
249+
assert expect_value(result) == [1, 2, 3]
250+
251+
def returns_an_error_for_an_invalid_input():
252+
result = coerce_value([1, "b", True], TestList)
253+
assert expect_error(result) == [
254+
"Expected type Int at value[1];"
255+
" Int cannot represent non-integer value: 'b'",
256+
"Expected type Int at value[2];"
257+
" Int cannot represent non-integer value: True",
258+
]
259+
260+
def returns_a_list_for_a_non_list_value():
261+
result = coerce_value(42, TestList)
262+
assert expect_value(result) == [42]
263+
264+
def returns_null_for_a_null_value():
265+
result = coerce_value(None, TestList)
266+
assert expect_value(result) is None
267+
268+
def describe_for_nested_graphql_list():
269+
TestNestedList = GraphQLList(GraphQLList(GraphQLInt))
270+
271+
def returns_no_error_for_a_valid_input():
272+
result = coerce_value([[1], [2], [3]], TestNestedList)
273+
assert expect_value(result) == [[1], [2], [3]]
274+
275+
def returns_a_list_for_a_non_list_value():
276+
result = coerce_value(42, TestNestedList)
277+
assert expect_value(result) == [[42]]
278+
279+
def returns_null_for_a_null_value():
280+
result = coerce_value(None, TestNestedList)
281+
assert expect_value(result) is None
282+
283+
def returns_nested_list_for_nested_non_list_values():
284+
result = coerce_value([1, 2, 3], TestNestedList)
285+
assert expect_value(result) == [[1], [2], [3]]
286+
287+
def returns_nested_null_for_nested_null_values():
288+
result = coerce_value([42, [None], None], TestNestedList)
289+
assert expect_value(result) == [[42], [None], None]

0 commit comments

Comments
 (0)