Skip to content

Commit 69a3263

Browse files
committed
test: Add test_query.test_should_custom_kwargs
1 parent e5b0d82 commit 69a3263

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

graphene_mongo/tests/test_query.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@ class Query(graphene.ObjectType):
275275
articles = MongoengineConnectionField(ArticleNode)
276276

277277
query = '''
278-
query ArticleQuery {
279-
articles(headline: "World") {
280-
edges {
281-
node {
282-
headline
278+
query ArticlesQuery {
279+
articles(headline: "World") {
280+
edges {
281+
node {
282+
headline
283+
}
283284
}
284285
}
285-
}
286286
}
287287
'''
288288
expected = {
@@ -302,8 +302,42 @@ class Query(graphene.ObjectType):
302302
assert result.data == expected
303303

304304

305-
def test_should_first_n():
306-
pass
305+
def test_should_custom_kwargs():
306+
307+
class Query(graphene.ObjectType):
308+
309+
editors = graphene.List(EditorType, first=graphene.Int())
310+
311+
def resolve_editors(self, *args, **kwargs):
312+
editors = Editor.objects()
313+
if 'first' in kwargs:
314+
editors = editors[:kwargs['first']]
315+
return list(editors)
316+
317+
query = '''
318+
query EditorQuery {
319+
editors(first: 2) {
320+
firstName,
321+
lastName
322+
}
323+
}
324+
'''
325+
expected = {
326+
'editors':[
327+
{
328+
'firstName': 'Penny',
329+
'lastName': 'Hardaway'
330+
},
331+
{
332+
'firstName': 'Grant',
333+
'lastName': 'Hill'
334+
}
335+
]
336+
}
337+
schema = graphene.Schema(query=Query)
338+
result = schema.execute(query)
339+
assert not result.errors
340+
assert all(item in result.data['editors'] for item in expected['editors'])
307341

308342
# TODO:
309343
def test_should_paging():

0 commit comments

Comments
 (0)