Skip to content

Repair outdated tests, add build on Travis CI #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fixed failing tests, silenced deprecationwarnings
Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
  • Loading branch information
hoefling committed Sep 24, 2019
commit 19a9b4d6af31c8fc52a48c06b3381a0654516076
13 changes: 12 additions & 1 deletion aiohttp_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,15 @@ def process_preflight(self, request):
def attach(cls, app, *, route_path='/graphql', route_name='graphql',
**kwargs):
view = cls(**kwargs)
app.router.add_route('*', route_path, view, name=route_name)
app.router.add_route('*', route_path, _asyncify(view), name=route_name)


def _asyncify(handler):
"""
This is mainly here because ``aiohttp`` can't infer the async definition of
:py:meth:`.GraphQLView.__call__` and raises a :py:class:`DeprecationWarning`
in tests. Wrapping it into an async function avoids the noisy warning.
"""
async def _dispatch(request):
return await handler(request)
return _dispatch
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ norecursedirs =
.git
.tox
testpaths = tests/
filterwarnings =
ignore:(context|root)_value has been deprecated.*:DeprecationWarning:graphql.backend.core:32
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def view_kwargs():

# aiohttp Fixtures
@pytest.fixture
def app(event_loop, executor, view_kwargs):
app = web.Application(loop=event_loop)
def app(executor, view_kwargs):
app = web.Application()
GraphQLView.attach(app, executor=executor, **view_kwargs)
return app


@pytest.fixture
async def client(event_loop, app):
client = aiohttp.test_utils.TestClient(app, loop=event_loop)
client = aiohttp.test_utils.TestClient(aiohttp.test_utils.TestServer(app), loop=event_loop)
await client.start_server()
yield client
await client.close()
Expand Down
5 changes: 2 additions & 3 deletions tests/test_graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ async def test_handles_field_errors_caught_by_graphql(client, url_builder):
assert await response.json() == {
'data': None,
'errors': [
{'locations': [{'column': 2, 'line': 1}], 'message': 'Throws!'},
{'locations': [{'column': 2, 'line': 1}], 'message': 'Throws!', 'path': ['thrower']},
],
}

Expand All @@ -447,8 +447,7 @@ async def test_handles_syntax_errors_caught_by_graphql(client, url_builder):
{
'locations': [{'column': 1, 'line': 1}],
'message': (
'Syntax Error GraphQL request (1:1) '
'Unexpected Name "syntaxerror"\n\n1: syntaxerror\n ^\n'
'Syntax Error GraphQL (1:1) Unexpected Name "syntaxerror"\n\n1: syntaxerror\n ^\n'
),
},
],
Expand Down