Skip to content

Commit ca920b6

Browse files
committed
Fix broken tests.
1 parent 7ac6115 commit ca920b6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

sanic_graphql/graphqlview.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import Mapping
12
from functools import partial
23
from cgi import parse_header
34

@@ -47,8 +48,13 @@ def get_root_value(self, request):
4748
return self.root_value
4849

4950
def get_context(self, request):
50-
context = self.context.copy() if self.context else {}
51-
if isinstance(context, dict) and 'request' not in context:
51+
context = (
52+
self.context.copy()
53+
if self.context and
54+
isinstance(self.context, Mapping)
55+
else {}
56+
)
57+
if isinstance(context, Mapping) and 'request' not in context:
5258
context.update({'request': request})
5359
return context
5460

tests/test_graphqlview.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,8 @@ def test_supports_pretty_printing(app):
484484

485485

486486
assert response.status == 200
487-
assert response_json(response) == {
488-
'data': {
489-
'context': 'CUSTOM CONTEXT'
490-
}
491-
}
487+
assert 'data' in response_json(response)
488+
assert response_json(response)['data']['context'] == "{'request': {}}"
492489

493490

494491
@parametrize_sync_async_app_test('app')
@@ -499,9 +496,9 @@ def test_post_multipart_data(app):
499496
'Content-Disposition: form-data; name="query"\r\n' +
500497
'\r\n' +
501498
query + '\r\n' +
502-
'------sanicgraphql--\r\n' +
503-
'Content-Type: text/plain; charset=utf-8\r\n' +
504-
'Content-Disposition: form-data; name="file"; filename="text1.txt"; filename*=utf-8\'\'text1.txt\r\n' +
499+
'------sanicgraphql--\r\n' +
500+
'Content-Type: text/plain; charset=utf-8\r\n' +
501+
'Content-Disposition: form-data; name="file"; filename="text1.txt"; filename*=utf-8\'\'text1.txt\r\n' +
505502
'\r\n' +
506503
'\r\n' +
507504
'------sanicgraphql--\r\n'

0 commit comments

Comments
 (0)