1
- import pytest
1
+ # -*- coding: utf-8 -*-
2
2
import json
3
3
4
+ import pytest
5
+
4
6
try :
5
7
from StringIO import StringIO
6
8
except ImportError :
19
21
def app ():
20
22
return create_app ()
21
23
24
+
22
25
def url_string (** url_params ):
23
26
string = url_for ('graphql' )
24
27
@@ -41,19 +44,19 @@ def test_allows_get_with_query_param(client):
41
44
42
45
assert response .status_code == 200
43
46
assert response_json (response ) == {
44
- 'data' : {'test' : " Hello World" }
47
+ 'data' : {'test' : ' Hello World' }
45
48
}
46
49
47
50
48
51
def test_allows_get_with_variable_values (client ):
49
52
response = client .get (url_string (
50
53
query = 'query helloWho($who: String){ test(who: $who) }' ,
51
- variables = json .dumps ({'who' : " Dolly" })
54
+ variables = json .dumps ({'who' : ' Dolly' })
52
55
))
53
56
54
57
assert response .status_code == 200
55
58
assert response_json (response ) == {
56
- 'data' : {'test' : " Hello Dolly" }
59
+ 'data' : {'test' : ' Hello Dolly' }
57
60
}
58
61
59
62
@@ -163,7 +166,7 @@ def test_allows_mutation_to_exist_within_a_get(client):
163
166
164
167
assert response .status_code == 200
165
168
assert response_json (response ) == {
166
- 'data' : {'test' : " Hello World" }
169
+ 'data' : {'test' : ' Hello World' }
167
170
}
168
171
169
172
@@ -172,12 +175,16 @@ def test_allows_post_with_json_encoding(client):
172
175
173
176
assert response .status_code == 200
174
177
assert response_json (response ) == {
175
- 'data' : {'test' : " Hello World" }
178
+ 'data' : {'test' : ' Hello World' }
176
179
}
177
180
178
181
179
182
def test_allows_sending_a_mutation_via_post (client ):
180
- response = client .post (url_string (), data = j (query = 'mutation TestMutation { writeTest { test } }' ), content_type = 'application/json' )
183
+ response = client .post (
184
+ url_string (),
185
+ data = j (query = 'mutation TestMutation { writeTest { test } }' ),
186
+ content_type = 'application/json'
187
+ )
181
188
182
189
assert response .status_code == 200
183
190
assert response_json (response ) == {
@@ -186,87 +193,91 @@ def test_allows_sending_a_mutation_via_post(client):
186
193
187
194
188
195
def test_allows_post_with_url_encoding (client ):
189
- response = client .post (url_string (), data = urlencode (dict (query = '{test}' )), content_type = 'application/x-www-form-urlencoded' )
196
+ response = client .post (
197
+ url_string (),
198
+ data = urlencode (dict (query = '{test}' )),
199
+ content_type = 'application/x-www-form-urlencoded'
200
+ )
190
201
191
202
assert response .status_code == 200
192
203
assert response_json (response ) == {
193
- 'data' : {'test' : " Hello World" }
204
+ 'data' : {'test' : ' Hello World' }
194
205
}
195
206
196
207
197
208
def test_supports_post_json_query_with_string_variables (client ):
198
209
response = client .post (url_string (), data = j (
199
210
query = 'query helloWho($who: String){ test(who: $who) }' ,
200
- variables = json .dumps ({'who' : " Dolly" })
211
+ variables = json .dumps ({'who' : ' Dolly' })
201
212
), content_type = 'application/json' )
202
213
203
214
assert response .status_code == 200
204
215
assert response_json (response ) == {
205
- 'data' : {'test' : " Hello Dolly" }
216
+ 'data' : {'test' : ' Hello Dolly' }
206
217
}
207
218
208
219
209
220
def test_supports_post_json_query_with_json_variables (client ):
210
221
response = client .post (url_string (), data = j (
211
222
query = 'query helloWho($who: String){ test(who: $who) }' ,
212
- variables = {'who' : " Dolly" }
223
+ variables = {'who' : ' Dolly' }
213
224
), content_type = 'application/json' )
214
225
215
226
assert response .status_code == 200
216
227
assert response_json (response ) == {
217
- 'data' : {'test' : " Hello Dolly" }
228
+ 'data' : {'test' : ' Hello Dolly' }
218
229
}
219
230
220
231
221
232
def test_supports_post_url_encoded_query_with_string_variables (client ):
222
233
response = client .post (url_string (), data = urlencode (dict (
223
234
query = 'query helloWho($who: String){ test(who: $who) }' ,
224
- variables = json .dumps ({'who' : " Dolly" })
235
+ variables = json .dumps ({'who' : ' Dolly' })
225
236
)), content_type = 'application/x-www-form-urlencoded' )
226
237
227
238
assert response .status_code == 200
228
239
assert response_json (response ) == {
229
- 'data' : {'test' : " Hello Dolly" }
240
+ 'data' : {'test' : ' Hello Dolly' }
230
241
}
231
242
232
243
233
244
def test_supports_post_json_quey_with_get_variable_values (client ):
234
245
response = client .post (url_string (
235
- variables = json .dumps ({'who' : " Dolly" })
246
+ variables = json .dumps ({'who' : ' Dolly' })
236
247
), data = j (
237
248
query = 'query helloWho($who: String){ test(who: $who) }' ,
238
249
), content_type = 'application/json' )
239
250
240
251
assert response .status_code == 200
241
252
assert response_json (response ) == {
242
- 'data' : {'test' : " Hello Dolly" }
253
+ 'data' : {'test' : ' Hello Dolly' }
243
254
}
244
255
245
256
246
257
def test_post_url_encoded_query_with_get_variable_values (client ):
247
258
response = client .post (url_string (
248
- variables = json .dumps ({'who' : " Dolly" })
259
+ variables = json .dumps ({'who' : ' Dolly' })
249
260
), data = urlencode (dict (
250
261
query = 'query helloWho($who: String){ test(who: $who) }' ,
251
262
)), content_type = 'application/x-www-form-urlencoded' )
252
263
253
264
assert response .status_code == 200
254
265
assert response_json (response ) == {
255
- 'data' : {'test' : " Hello Dolly" }
266
+ 'data' : {'test' : ' Hello Dolly' }
256
267
}
257
268
258
269
259
270
def test_supports_post_raw_text_query_with_get_variable_values (client ):
260
271
response = client .post (url_string (
261
- variables = json .dumps ({'who' : " Dolly" })
272
+ variables = json .dumps ({'who' : ' Dolly' })
262
273
),
263
274
data = 'query helloWho($who: String){ test(who: $who) }' ,
264
275
content_type = 'application/graphql'
265
276
)
266
277
267
278
assert response .status_code == 200
268
279
assert response_json (response ) == {
269
- 'data' : {'test' : " Hello Dolly" }
280
+ 'data' : {'test' : ' Hello Dolly' }
270
281
}
271
282
272
283
@@ -396,7 +407,7 @@ def test_handles_incomplete_json_bodies(client):
396
407
397
408
def test_handles_plain_post_text (client ):
398
409
response = client .post (url_string (
399
- variables = json .dumps ({'who' : " Dolly" })
410
+ variables = json .dumps ({'who' : ' Dolly' })
400
411
),
401
412
data = 'query helloWho($who: String){ test(who: $who) }' ,
402
413
content_type = 'text/plain'
@@ -438,11 +449,10 @@ def test_passes_request_into_request_context(client):
438
449
}
439
450
440
451
441
- @pytest .mark .parametrize ('app' , [create_app (context = " CUSTOM CONTEXT" )])
452
+ @pytest .mark .parametrize ('app' , [create_app (context = ' CUSTOM CONTEXT' )])
442
453
def test_supports_pretty_printing (client ):
443
454
response = client .get (url_string (query = '{context}' ))
444
455
445
-
446
456
assert response .status_code == 200
447
457
assert response_json (response ) == {
448
458
'data' : {
@@ -455,7 +465,7 @@ def test_post_multipart_data(client):
455
465
query = 'mutation TestMutation { writeTest { test } }'
456
466
response = client .post (
457
467
url_string (),
458
- data = {
468
+ data = {
459
469
'query' : query ,
460
470
'file' : (StringIO (), 'text1.txt' ),
461
471
},
@@ -477,7 +487,7 @@ def test_batch_allows_post_with_json_encoding(client):
477
487
assert response .status_code == 200
478
488
assert response_json (response ) == [{
479
489
'id' : 1 ,
480
- 'payload' : { 'data' : {'test' : " Hello World" } },
490
+ 'payload' : {'data' : {'test' : ' Hello World' } },
481
491
'status' : 200 ,
482
492
}]
483
493
@@ -489,19 +499,19 @@ def test_batch_supports_post_json_query_with_json_variables(client):
489
499
data = jl (
490
500
id = 1 ,
491
501
query = 'query helloWho($who: String){ test(who: $who) }' ,
492
- variables = {'who' : " Dolly" }
502
+ variables = {'who' : ' Dolly' }
493
503
),
494
504
content_type = 'application/json'
495
505
)
496
506
497
507
assert response .status_code == 200
498
508
assert response_json (response ) == [{
499
509
'id' : 1 ,
500
- 'payload' : { 'data' : {'test' : " Hello Dolly" } },
510
+ 'payload' : {'data' : {'test' : ' Hello Dolly' } },
501
511
'status' : 200 ,
502
512
}]
503
-
504
-
513
+
514
+
505
515
@pytest .mark .parametrize ('app' , [create_app (batch = True )])
506
516
def test_batch_allows_post_with_operation_name (client ):
507
517
response = client .post (
0 commit comments