Skip to content

Commit 8226ccc

Browse files
committed
Cleaned up mess with parametrize decorators, added two more tests
1 parent f490835 commit 8226ccc

3 files changed

Lines changed: 81 additions & 165 deletions

File tree

tests/app.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from functools import partial
1+
import pytest
22

33
try:
44
from urllib import urlencode
@@ -44,3 +44,12 @@ def url_string(uri='/graphql', **url_params):
4444

4545
return string
4646

47+
48+
def parametrize_sync_async_app_test(arg, **extra_options):
49+
def decorator(test):
50+
apps = []
51+
for ae in [False, True]:
52+
apps.append(create_app(async_executor=ae, **extra_options))
53+
54+
return pytest.mark.parametrize('app', apps)(test)
55+
return decorator

tests/test_graphiqlview.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from jinja2 import Environment
44

5-
from .app import create_app, url_string
5+
from .app import create_app, url_string, parametrize_sync_async_app_test
6+
from .schema import AsyncSchema
67

78

89
@pytest.fixture
@@ -16,49 +17,61 @@ def pretty_response():
1617
).replace('\"','\\\"').replace('\n', '\\n')
1718

1819

19-
@pytest.mark.parametrize('app', [
20-
(create_app(async_executor=False, graphiql=True)),
21-
(create_app(async_executor=True, graphiql=True)),
22-
])
20+
@parametrize_sync_async_app_test('app', graphiql=True)
2321
def test_graphiql_is_enabled(app):
2422
_, response = app.client.get( uri=url_string(), headers={'Accept': 'text/html'})
2523
assert response.status == 200
2624

2725

28-
@pytest.mark.parametrize('app', [
29-
(create_app(async_executor=False, graphiql=True)),
30-
(create_app(async_executor=True, graphiql=True)),
31-
])
26+
@parametrize_sync_async_app_test('app', graphiql=True)
3227
def test_graphiql_simple_renderer(app, pretty_response):
3328
_, response = app.client.get(uri=url_string(query='{test}'), headers={'Accept': 'text/html'})
3429
assert response.status == 200
3530
assert pretty_response in response.body.decode('utf-8')
3631

3732

38-
@pytest.mark.parametrize('app', [
39-
(create_app(async_executor=False, graphiql=True, jinja_env=Environment())),
40-
(create_app(async_executor=True, graphiql=True, jinja_env=Environment())),
41-
])
33+
@parametrize_sync_async_app_test('app', graphiql=True, jinja_env=Environment())
4234
def test_graphiql_jinja_renderer(app, pretty_response):
4335
_, response = app.client.get(uri=url_string(query='{test}'), headers={'Accept': 'text/html'})
4436
assert response.status == 200
4537
assert pretty_response in response.body.decode('utf-8')
4638

4739

48-
@pytest.mark.parametrize('app', [
49-
(create_app(async_executor=False, graphiql=True, jinja_env=Environment(enable_async=True))),
50-
(create_app(async_executor=True, graphiql=True, jinja_env=Environment(enable_async=True))),
51-
])
40+
@parametrize_sync_async_app_test('app', graphiql=True, jinja_env=Environment(enable_async=True))
5241
def test_graphiql_jinja_async_renderer(app, pretty_response):
5342
_, response = app.client.get(uri=url_string(query='{test}'), headers={'Accept': 'text/html'})
5443
assert response.status == 200
5544
assert pretty_response in response.body.decode('utf-8')
5645

5746

58-
@pytest.mark.parametrize('app', [
59-
(create_app(async_executor=False, graphiql=True, jinja_env=Environment())),
60-
(create_app(async_executor=True, graphiql=True, jinja_env=Environment())),
61-
])
47+
@parametrize_sync_async_app_test('app', graphiql=True)
6248
def test_graphiql_html_is_not_accepted(app):
6349
_, response = app.client.get(uri=url_string(), headers={'Accept': 'application/json'})
6450
assert response.status == 400
51+
52+
53+
@parametrize_sync_async_app_test('app', graphiql=True)
54+
def test_graphiql_get_mutation(app, pretty_response):
55+
query = 'mutation TestMutation { writeTest { test } }'
56+
_, response = app.client.get(uri=url_string(query=query), headers={'Accept': 'text/html'})
57+
assert response.status == 200
58+
assert 'response: null' in response.body.decode('utf-8')
59+
60+
61+
@pytest.mark.parametrize('app', [create_app(async_executor=True, graphiql=True, schema=AsyncSchema)])
62+
def test_graphiql_asyncio_schema(app):
63+
query = '{a,b,c}'
64+
_, response = app.client.get(uri=url_string(query=query), headers={'Accept': 'text/html'})
65+
66+
expected_response = (
67+
'{\n'
68+
' "data": {\n'
69+
' "a": "hey",\n'
70+
' "b": "hey2",\n'
71+
' "c": "hey3"\n'
72+
' }\n'
73+
'}'
74+
).replace('\"','\\\"').replace('\n', '\\n')
75+
76+
assert response.status == 200
77+
assert expected_response in response.body.decode('utf-8')

0 commit comments

Comments
 (0)