Skip to content

Commit 8fa5501

Browse files
committed
test: Add test_query.test_should_connection_field
1 parent cbd172d commit 8fa5501

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

graphene_mongo/tests/test_query.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from graphene.relay import Node
66

77
from .models import Article, Editor, EmbeddedArticle, Reporter
8+
from ..fields import MongoengineConnectionField
89
from ..types import MongoengineObjectType
910

1011

@@ -179,9 +180,51 @@ def resolve_reporter(self, *args, **kwargs):
179180
assert not result.errors
180181
assert dict(result.data['reporter']) == expected['reporter']
181182

182-
# TODO:
183-
def test_should_custom_identifier():
184-
pass
183+
def test_should_connection_field():
184+
class EditorNode(MongoengineObjectType):
185+
186+
class Meta:
187+
model = Editor
188+
interfaces = (Node,)
189+
190+
class Query(graphene.ObjectType):
191+
node = Node.Field()
192+
all_editors = MongoengineConnectionField(EditorNode)
193+
194+
query = '''
195+
query EditorQuery {
196+
allEditors {
197+
edges {
198+
node {
199+
firstName,
200+
lastName
201+
}
202+
}
203+
}
204+
}
205+
'''
206+
expected = {
207+
'allEditors': {
208+
'edges': [
209+
{
210+
'node': {
211+
'firstName': 'Penny',
212+
'lastName': 'Hardaway'
213+
},
214+
},
215+
{
216+
'node': {
217+
'firstName': 'Grant',
218+
'lastName': 'Hill'
219+
}
220+
}
221+
]
222+
}
223+
}
224+
schema = graphene.Schema(query=Query)
225+
result = schema.execute(query)
226+
assert not result.errors
227+
assert dict(result.data['allEditors']) == expected['allEditors']
185228

186229
# TODO:
187230
def test_should_mutate_well():

0 commit comments

Comments
 (0)