Skip to content

Commit 19a9b4d

Browse files
committed
fixed failing tests, silenced deprecationwarnings
Signed-off-by: Oleg Höfling <[email protected]>
1 parent 13cf990 commit 19a9b4d

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

aiohttp_graphql/graphqlview.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,15 @@ def process_preflight(self, request):
202202
def attach(cls, app, *, route_path='/graphql', route_name='graphql',
203203
**kwargs):
204204
view = cls(**kwargs)
205-
app.router.add_route('*', route_path, view, name=route_name)
205+
app.router.add_route('*', route_path, _asyncify(view), name=route_name)
206+
207+
208+
def _asyncify(handler):
209+
"""
210+
This is mainly here because ``aiohttp`` can't infer the async definition of
211+
:py:meth:`.GraphQLView.__call__` and raises a :py:class:`DeprecationWarning`
212+
in tests. Wrapping it into an async function avoids the noisy warning.
213+
"""
214+
async def _dispatch(request):
215+
return await handler(request)
216+
return _dispatch

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ norecursedirs =
1010
.git
1111
.tox
1212
testpaths = tests/
13+
filterwarnings =
14+
ignore:(context|root)_value has been deprecated.*:DeprecationWarning:graphql.backend.core:32

tests/conftest.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def view_kwargs():
2626

2727
# aiohttp Fixtures
2828
@pytest.fixture
29-
def app(event_loop, executor, view_kwargs):
30-
app = web.Application(loop=event_loop)
29+
def app(executor, view_kwargs):
30+
app = web.Application()
3131
GraphQLView.attach(app, executor=executor, **view_kwargs)
3232
return app
3333

3434

3535
@pytest.fixture
3636
async def client(event_loop, app):
37-
client = aiohttp.test_utils.TestClient(app, loop=event_loop)
37+
client = aiohttp.test_utils.TestClient(aiohttp.test_utils.TestServer(app), loop=event_loop)
3838
await client.start_server()
3939
yield client
4040
await client.close()

tests/test_graphqlview.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ async def test_handles_field_errors_caught_by_graphql(client, url_builder):
432432
assert await response.json() == {
433433
'data': None,
434434
'errors': [
435-
{'locations': [{'column': 2, 'line': 1}], 'message': 'Throws!'},
435+
{'locations': [{'column': 2, 'line': 1}], 'message': 'Throws!', 'path': ['thrower']},
436436
],
437437
}
438438

@@ -447,8 +447,7 @@ async def test_handles_syntax_errors_caught_by_graphql(client, url_builder):
447447
{
448448
'locations': [{'column': 1, 'line': 1}],
449449
'message': (
450-
'Syntax Error GraphQL request (1:1) '
451-
'Unexpected Name "syntaxerror"\n\n1: syntaxerror\n ^\n'
450+
'Syntax Error GraphQL (1:1) Unexpected Name "syntaxerror"\n\n1: syntaxerror\n ^\n'
452451
),
453452
},
454453
],

0 commit comments

Comments
 (0)