22
33from 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 )
2321def 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 )
3227def 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 ())
4234def 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 ))
5241def 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 )
6248def 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