Skip to content

Commit bc74eed

Browse files
committed
Empty fields are not contained in formatted errors any more
1 parent 384ae78 commit bc74eed

File tree

7 files changed

+116
-187
lines changed

7 files changed

+116
-187
lines changed

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
]
1313

1414
dev_requires = [
15-
"flake8>=3.7,<4",
16-
"isort>=4,<5",
17-
"black==19.10b0",
15+
"flake8>=4,<5",
16+
"isort>=5,<6",
17+
"black>=19.10b0",
1818
"mypy>=0.761,<0.770",
1919
"check-manifest>=0.40,<1",
2020
] + tests_requires
@@ -28,7 +28,7 @@
2828
]
2929

3030
install_webob_requires = [
31-
"webob>=1.8.6,<2",
31+
"webob>=1.8.7,<2",
3232
]
3333

3434
install_aiohttp_requires = [

tests/aiohttp/test_graphqlview.py

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ async def test_reports_validation_errors(client):
7676
{
7777
"message": "Cannot query field 'unknownOne' on type 'QueryRoot'.",
7878
"locations": [{"line": 1, "column": 9}],
79-
"path": None,
8079
},
8180
{
8281
"message": "Cannot query field 'unknownTwo' on type 'QueryRoot'.",
8382
"locations": [{"line": 1, "column": 21}],
84-
"path": None,
8583
},
8684
],
8785
}
@@ -107,8 +105,6 @@ async def test_errors_when_missing_operation_name(client):
107105
"Must provide operation name if query contains multiple "
108106
"operations."
109107
),
110-
"locations": None,
111-
"path": None,
112108
},
113109
]
114110
}
@@ -128,8 +124,6 @@ async def test_errors_when_sending_a_mutation_via_get(client):
128124
"errors": [
129125
{
130126
"message": "Can only perform a mutation operation from a POST request.",
131-
"locations": None,
132-
"path": None,
133127
},
134128
],
135129
}
@@ -152,8 +146,6 @@ async def test_errors_when_selecting_a_mutation_within_a_get(client):
152146
"errors": [
153147
{
154148
"message": "Can only perform a mutation operation from a POST request.",
155-
"locations": None,
156-
"path": None,
157149
},
158150
],
159151
}
@@ -174,10 +166,8 @@ async def test_errors_when_selecting_a_subscription_within_a_get(client):
174166
assert await response.json() == {
175167
"errors": [
176168
{
177-
"message": "Can only perform a subscription operation from a POST "
178-
"request.",
179-
"locations": None,
180-
"path": None,
169+
"message": "Can only perform a subscription operation"
170+
" from a POST request.",
181171
},
182172
],
183173
}
@@ -215,7 +205,11 @@ async def test_allows_post_with_json_encoding(client):
215205
async def test_allows_sending_a_mutation_via_post(client):
216206
response = await client.post(
217207
"/graphql",
218-
data=json.dumps(dict(query="mutation TestMutation { writeTest { test } }",)),
208+
data=json.dumps(
209+
dict(
210+
query="mutation TestMutation { writeTest { test } }",
211+
)
212+
),
219213
headers={"content-type": "application/json"},
220214
)
221215

@@ -292,7 +286,11 @@ async def test_supports_post_url_encoded_query_with_string_variables(client):
292286
async def test_supports_post_json_quey_with_get_variable_values(client):
293287
response = await client.post(
294288
url_string(variables=json.dumps({"who": "Dolly"})),
295-
data=json.dumps(dict(query="query helloWho($who: String){ test(who: $who) }",)),
289+
data=json.dumps(
290+
dict(
291+
query="query helloWho($who: String){ test(who: $who) }",
292+
)
293+
),
296294
headers={"content-type": "application/json"},
297295
)
298296

@@ -304,7 +302,11 @@ async def test_supports_post_json_quey_with_get_variable_values(client):
304302
async def test_post_url_encoded_query_with_get_variable_values(client):
305303
response = await client.post(
306304
url_string(variables=json.dumps({"who": "Dolly"})),
307-
data=urlencode(dict(query="query helloWho($who: String){ test(who: $who) }",)),
305+
data=urlencode(
306+
dict(
307+
query="query helloWho($who: String){ test(who: $who) }",
308+
)
309+
),
308310
headers={"content-type": "application/x-www-form-urlencoded"},
309311
)
310312

@@ -421,7 +423,6 @@ async def test_handles_syntax_errors_caught_by_graphql(client):
421423
{
422424
"locations": [{"column": 1, "line": 1}],
423425
"message": "Syntax Error: Unexpected Name 'syntaxerror'.",
424-
"path": None,
425426
},
426427
],
427428
}
@@ -433,25 +434,23 @@ async def test_handles_errors_caused_by_a_lack_of_query(client):
433434

434435
assert response.status == 400
435436
assert await response.json() == {
436-
"errors": [
437-
{"message": "Must provide query string.", "locations": None, "path": None}
438-
]
437+
"errors": [{"message": "Must provide query string."}]
439438
}
440439

441440

442441
@pytest.mark.asyncio
443442
async def test_handles_batch_correctly_if_is_disabled(client):
444443
response = await client.post(
445-
"/graphql", data="[]", headers={"content-type": "application/json"},
444+
"/graphql",
445+
data="[]",
446+
headers={"content-type": "application/json"},
446447
)
447448

448449
assert response.status == 400
449450
assert await response.json() == {
450451
"errors": [
451452
{
452453
"message": "Batch GraphQL requests are not enabled.",
453-
"locations": None,
454-
"path": None,
455454
}
456455
]
457456
}
@@ -460,16 +459,16 @@ async def test_handles_batch_correctly_if_is_disabled(client):
460459
@pytest.mark.asyncio
461460
async def test_handles_incomplete_json_bodies(client):
462461
response = await client.post(
463-
"/graphql", data='{"query":', headers={"content-type": "application/json"},
462+
"/graphql",
463+
data='{"query":',
464+
headers={"content-type": "application/json"},
464465
)
465466

466467
assert response.status == 400
467468
assert await response.json() == {
468469
"errors": [
469470
{
470471
"message": "POST body sent invalid JSON.",
471-
"locations": None,
472-
"path": None,
473472
}
474473
]
475474
}
@@ -484,9 +483,7 @@ async def test_handles_plain_post_text(client):
484483
)
485484
assert response.status == 400
486485
assert await response.json() == {
487-
"errors": [
488-
{"message": "Must provide query string.", "locations": None, "path": None}
489-
]
486+
"errors": [{"message": "Must provide query string."}]
490487
}
491488

492489

@@ -499,9 +496,7 @@ async def test_handles_poorly_formed_variables(client):
499496
)
500497
assert response.status == 400
501498
assert await response.json() == {
502-
"errors": [
503-
{"message": "Variables are invalid JSON.", "locations": None, "path": None}
504-
]
499+
"errors": [{"message": "Variables are invalid JSON."}]
505500
}
506501

507502

@@ -514,8 +509,6 @@ async def test_handles_unsupported_http_methods(client):
514509
"errors": [
515510
{
516511
"message": "GraphQL only supports GET and POST requests.",
517-
"locations": None,
518-
"path": None,
519512
}
520513
]
521514
}
@@ -576,16 +569,15 @@ async def test_post_multipart_data(client):
576569

577570
data = (
578571
"------aiohttpgraphql\r\n"
579-
+ 'Content-Disposition: form-data; name="query"\r\n'
580-
+ "\r\n"
581-
+ query
582-
+ "\r\n"
583-
+ "------aiohttpgraphql--\r\n"
584-
+ "Content-Type: text/plain; charset=utf-8\r\n"
585-
+ 'Content-Disposition: form-data; name="file"; filename="text1.txt"; filename*=utf-8\'\'text1.txt\r\n' # noqa: ignore
586-
+ "\r\n"
587-
+ "\r\n"
588-
+ "------aiohttpgraphql--\r\n"
572+
'Content-Disposition: form-data; name="query"\r\n'
573+
"\r\n" + query + "\r\n"
574+
"------aiohttpgraphql--\r\n"
575+
"Content-Type: text/plain; charset=utf-8\r\n"
576+
'Content-Disposition: form-data; name="file"; filename="text1.txt";'
577+
" filename*=utf-8''text1.txt\r\n"
578+
"\r\n"
579+
"\r\n"
580+
"------aiohttpgraphql--\r\n"
589581
)
590582

591583
response = await client.post(
@@ -595,7 +587,7 @@ async def test_post_multipart_data(client):
595587
)
596588

597589
assert response.status == 200
598-
assert await response.json() == {"data": {u"writeTest": {u"test": u"Hello World"}}}
590+
assert await response.json() == {"data": {"writeTest": {"test": "Hello World"}}}
599591

600592

601593
@pytest.mark.asyncio
@@ -674,7 +666,8 @@ async def test_async_schema(app, client):
674666
@pytest.mark.asyncio
675667
async def test_preflight_request(client):
676668
response = await client.options(
677-
"/graphql", headers={"Access-Control-Request-Method": "POST"},
669+
"/graphql",
670+
headers={"Access-Control-Request-Method": "POST"},
678671
)
679672

680673
assert response.status == 200
@@ -683,7 +676,8 @@ async def test_preflight_request(client):
683676
@pytest.mark.asyncio
684677
async def test_preflight_incorrect_request(client):
685678
response = await client.options(
686-
"/graphql", headers={"Access-Control-Request-Method": "OPTIONS"},
679+
"/graphql",
680+
headers={"Access-Control-Request-Method": "OPTIONS"},
687681
)
688682

689683
assert response.status == 400

0 commit comments

Comments
 (0)