Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef3f607

Browse filesBrowse files
committed
Add context tests
1 parent 021e9a2 commit ef3f607
Copy full SHA for ef3f607

File tree

3 files changed

+19
-1
lines changed
Filter options

3 files changed

+19
-1
lines changed

‎flask_graphql/graphqlview.py

Copy file name to clipboardExpand all lines: flask_graphql/graphqlview.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def get_root_value(self, request):
4848
return self.root_value
4949

5050
def get_context(self, request):
51-
return self.context or request
51+
if self.context is not None:
52+
return self.context
53+
return request
5254

5355
def get_middleware(self, request):
5456
return self.middleware

‎tests/schema.py

Copy file name to clipboardExpand all lines: tests/schema.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def resolve_raises(*_):
1313
'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
1414
'request': GraphQLField(GraphQLNonNull(GraphQLString),
1515
resolver=lambda obj, args, context, info: context.args.get('q')),
16+
'context': GraphQLField(GraphQLNonNull(GraphQLString),
17+
resolver=lambda obj, args, context, info: context),
1618
'test': GraphQLField(
1719
type=GraphQLString,
1820
args={

‎tests/test_graphqlview.py

Copy file name to clipboardExpand all lines: tests/test_graphqlview.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,20 @@ def test_passes_request_into_request_context(client):
426426
}
427427
}
428428

429+
430+
@pytest.mark.parametrize('app', [create_app(context="CUSTOM CONTEXT")])
431+
def test_supports_pretty_printing(client):
432+
response = client.get(url_string(query='{context}'))
433+
434+
435+
assert response.status_code == 200
436+
assert response_json(response) == {
437+
'data': {
438+
'context': 'CUSTOM CONTEXT'
439+
}
440+
}
441+
442+
429443
def test_post_multipart_data(client):
430444
query = 'mutation TestMutation { writeTest { test } }'
431445
response = client.post(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.