Skip to content

Commit 6c2b940

Browse files
committed
Improved ClientIDMutation tests for thenables
1 parent 645bfdd commit 6c2b940

File tree

1 file changed

+52
-15
lines changed

1 file changed

+52
-15
lines changed

graphene/relay/tests/test_mutation.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
from ...types.scalars import String
66
from ..mutation import ClientIDMutation
77
from ..node import Node
8+
from promise import Promise
89

910

1011
class SharedFields(AbstractType):
1112
shared = String()
1213

1314

1415
class MyNode(ObjectType):
15-
1616
class Meta:
1717
interfaces = (Node, )
1818

1919
name = String()
2020

2121

2222
class SaySomething(ClientIDMutation):
23-
2423
class Input:
2524
what = String()
25+
2626
phrase = String()
2727

2828
@staticmethod
@@ -31,8 +31,19 @@ def mutate_and_get_payload(args, context, info):
3131
return SaySomething(phrase=str(what))
3232

3333

34-
class OtherMutation(ClientIDMutation):
34+
class SaySomethingPromise(ClientIDMutation):
35+
class Input:
36+
what = String()
37+
38+
phrase = String()
39+
40+
@staticmethod
41+
def mutate_and_get_payload(args, context, info):
42+
what = args.get('what')
43+
return Promise.resolve(SaySomething(phrase=str(what)))
44+
3545

46+
class OtherMutation(ClientIDMutation):
3647
class Input(SharedFields):
3748
additional_field = String()
3849

@@ -44,9 +55,9 @@ def mutate_and_get_payload(cls, args, context, info):
4455
shared = args.get('shared', '')
4556
additionalField = args.get('additionalField', '')
4657
edge_type = MyNode.Connection.Edge
47-
return OtherMutation(name=shared + additionalField,
48-
my_node_edge=edge_type(
49-
cursor='1', node=MyNode(name='name')))
58+
return OtherMutation(
59+
name=shared + additionalField,
60+
my_node_edge=edge_type(cursor='1', node=MyNode(name='name')))
5061

5162

5263
class RootQuery(ObjectType):
@@ -55,13 +66,16 @@ class RootQuery(ObjectType):
5566

5667
class Mutation(ObjectType):
5768
say = SaySomething.Field()
69+
say_promise = SaySomethingPromise.Field()
5870
other = OtherMutation.Field()
5971

72+
6073
schema = Schema(query=RootQuery, mutation=Mutation)
6174

6275

6376
def test_no_mutate_and_get_payload():
6477
with pytest.raises(AssertionError) as excinfo:
78+
6579
class MyMutation(ClientIDMutation):
6680
pass
6781

@@ -97,7 +111,9 @@ def test_mutation_input():
97111

98112
def test_subclassed_mutation():
99113
fields = OtherMutation._meta.fields
100-
assert list(fields.keys()) == ['name', 'my_node_edge', 'client_mutation_id']
114+
assert list(fields.keys()) == [
115+
'name', 'my_node_edge', 'client_mutation_id'
116+
]
101117
assert isinstance(fields['name'], Field)
102118
field = OtherMutation.Field()
103119
assert field.type == OtherMutation
@@ -111,7 +127,9 @@ def test_subclassed_mutation_input():
111127
Input = OtherMutation.Input
112128
assert issubclass(Input, InputObjectType)
113129
fields = Input._meta.fields
114-
assert list(fields.keys()) == ['shared', 'additional_field', 'client_mutation_id']
130+
assert list(fields.keys()) == [
131+
'shared', 'additional_field', 'client_mutation_id'
132+
]
115133
assert isinstance(fields['shared'], InputField)
116134
assert fields['shared'].type == String
117135
assert isinstance(fields['additional_field'], InputField)
@@ -120,16 +138,35 @@ def test_subclassed_mutation_input():
120138
assert fields['client_mutation_id'].type == String
121139

122140

123-
# def test_node_query():
124-
# executed = schema.execute(
125-
# 'mutation a { say(input: {what:"hello", clientMutationId:"1"}) { phrase } }'
126-
# )
127-
# assert not executed.errors
128-
# assert executed.data == {'say': {'phrase': 'hello'}}
141+
def test_node_query():
142+
executed = schema.execute(
143+
'mutation a { say(input: {what:"hello", clientMutationId:"1"}) { phrase } }'
144+
)
145+
assert not executed.errors
146+
assert executed.data == {'say': {'phrase': 'hello'}}
147+
148+
149+
def test_node_query():
150+
executed = schema.execute(
151+
'mutation a { sayPromise(input: {what:"hello", clientMutationId:"1"}) { phrase } }'
152+
)
153+
assert not executed.errors
154+
assert executed.data == {'sayPromise': {'phrase': 'hello'}}
155+
129156

130157
def test_edge_query():
131158
executed = schema.execute(
132159
'mutation a { other(input: {clientMutationId:"1"}) { clientMutationId, myNodeEdge { cursor node { name }} } }'
133160
)
134161
assert not executed.errors
135-
assert dict(executed.data) == {'other': {'clientMutationId': '1', 'myNodeEdge': {'cursor': '1', 'node': {'name': 'name'}}}}
162+
assert dict(executed.data) == {
163+
'other': {
164+
'clientMutationId': '1',
165+
'myNodeEdge': {
166+
'cursor': '1',
167+
'node': {
168+
'name': 'name'
169+
}
170+
}
171+
}
172+
}

0 commit comments

Comments
 (0)