Skip to content

Commit 6ad3230

Browse files
committed
test: Separate test_mutation
1 parent 2488f6f commit 6ad3230

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

graphene_mongo/tests/test_mutation.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import graphene
2+
3+
from graphene.relay import Node
4+
5+
from .models import (Article,)
6+
from .types import (ArticleNode,)
7+
8+
def test_should_mutate_create():
9+
10+
class CreateArticle(graphene.Mutation):
11+
12+
class Arguments:
13+
14+
headline = graphene.String()
15+
16+
article = graphene.Field(ArticleNode)
17+
18+
def mutate(self, info, headline):
19+
article = Article(
20+
headline=headline
21+
)
22+
article.save()
23+
24+
return CreateArticle(article=article)
25+
26+
class Query(graphene.ObjectType):
27+
28+
node = Node.Field()
29+
30+
class Mutation(graphene.ObjectType):
31+
32+
create_article = CreateArticle.Field()
33+
34+
query = '''
35+
mutation ArticleCreator {
36+
createArticle(
37+
headline: "My Article"
38+
) {
39+
article {
40+
headline
41+
}
42+
}
43+
}
44+
'''
45+
expected = {
46+
'createArticle': {
47+
'article': {
48+
'headline': 'My Article'
49+
}
50+
}
51+
}
52+
schema = graphene.Schema(query=Query, mutation=Mutation)
53+
result = schema.execute(query)
54+
assert not result.errors
55+
assert result.data == expected
56+

graphene_mongo/tests/test_relay_query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def test_should_mutate():
212212
class CreateArticle(graphene.Mutation):
213213

214214
class Arguments:
215+
215216
headline = graphene.String()
216217

217218
article = graphene.Field(ArticleNode)
@@ -225,6 +226,7 @@ def mutate(self, info, headline):
225226
return CreateArticle(article=article)
226227

227228
class Query(graphene.ObjectType):
229+
228230
node = Node.Field()
229231

230232
class Mutation(graphene.ObjectType):

0 commit comments

Comments
 (0)