Skip to content

Commit bd2d6c4

Browse files
committed
test: Add test_query.test_should_mutate_well
1 parent 0840c70 commit bd2d6c4

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

graphene_mongo/tests/test_query.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,61 @@ class Query(graphene.ObjectType):
226226
assert not result.errors
227227
assert dict(result.data['allEditors']) == expected['allEditors']
228228

229-
# TODO:
229+
230230
def test_should_mutate_well():
231-
pass
231+
class ArticleNode(MongoengineObjectType):
232+
233+
class Meta:
234+
model = Article
235+
interfaces = (Node,)
236+
237+
238+
class CreateArticle(graphene.Mutation):
239+
240+
class Arguments:
241+
headline = graphene.String()
242+
243+
article = graphene.Field(ArticleNode)
244+
245+
def mutate(self, info, headline):
246+
article = Article(
247+
headline=headline
248+
)
249+
article.save()
250+
251+
return CreateArticle(article=article)
252+
253+
254+
class Query(graphene.ObjectType):
255+
node = Node.Field()
256+
257+
258+
class Mutation(graphene.ObjectType):
259+
260+
create_article = CreateArticle.Field()
261+
262+
query = '''
263+
mutation ArticleCreator {
264+
createArticle(
265+
headline: "My Article"
266+
) {
267+
article {
268+
headline
269+
}
270+
}
271+
}
272+
'''
273+
expected = {
274+
'createArticle': {
275+
'article': {
276+
'headline': 'My Article'
277+
}
278+
}
279+
}
280+
schema = graphene.Schema(query=Query, mutation=Mutation)
281+
result = schema.execute(query)
282+
assert not result.errors
283+
assert result.data == expected
232284

233285
# TODO:
234286
def test_should_filter():

0 commit comments

Comments
 (0)