Skip to content

Commit 118fb5d

Browse files
committed
test: Add test_should_update
1 parent 6ad3230 commit 118fb5d

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

graphene_mongo/tests/test_mutation.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
from graphene.relay import Node
44

5-
from .models import (Article,)
6-
from .types import (ArticleNode,)
5+
from .fixtures import setup_fixtures
6+
from .models import (Article, Editor)
7+
from .types import (ArticleNode, EditorNode)
78

8-
def test_should_mutate_create():
9+
10+
setup_fixtures()
11+
12+
13+
def test_should_create():
914

1015
class CreateArticle(graphene.Mutation):
1116

@@ -54,3 +59,53 @@ class Mutation(graphene.ObjectType):
5459
assert not result.errors
5560
assert result.data == expected
5661

62+
63+
def test_should_update():
64+
65+
class UpdateEditor(graphene.Mutation):
66+
67+
class Arguments:
68+
id = graphene.ID()
69+
first_name = graphene.String()
70+
71+
editor = graphene.Field(EditorNode)
72+
73+
def mutate(self, info, id, first_name):
74+
print(id, first_name)
75+
editor = Editor.objects.get(id=id)
76+
editor.first_name = first_name
77+
editor.save()
78+
return UpdateEditor(editor=editor)
79+
80+
class Query(graphene.ObjectType):
81+
82+
node = Node.Field()
83+
84+
class Mutation(graphene.ObjectType):
85+
86+
update_editor = UpdateEditor.Field()
87+
88+
query = '''
89+
mutation EditorUpdater {
90+
updateEditor(
91+
id: "1"
92+
firstName: "Tony"
93+
) {
94+
editor {
95+
firstName
96+
}
97+
}
98+
}
99+
'''
100+
expected = {
101+
'updateEditor': {
102+
'editor': {
103+
'firstName': 'Tony'
104+
}
105+
}
106+
}
107+
schema = graphene.Schema(query=Query, mutation=Mutation)
108+
result = schema.execute(query)
109+
# print(result.data)
110+
assert not result.errors
111+
assert result.data == expected

0 commit comments

Comments
 (0)