|
3 | 3 | from jinja2 import Environment
|
4 | 4 |
|
5 | 5 | from tests.aiohttp.app import create_app, url_string
|
6 |
| -from tests.aiohttp.schema import AsyncSchema, Schema |
| 6 | +from tests.aiohttp.schema import AsyncSchema, Schema, SyncSchema |
7 | 7 |
|
8 | 8 |
|
9 | 9 | @pytest.fixture
|
@@ -102,11 +102,51 @@ async def test_graphiql_get_subscriptions(app, client):
|
102 | 102 |
|
103 | 103 |
|
104 | 104 | @pytest.mark.asyncio
|
105 |
| -@pytest.mark.parametrize("app", [create_app(schema=AsyncSchema, enable_async=True)]) |
106 |
| -async def test_graphiql_async_schema(app, client): |
| 105 | +@pytest.mark.parametrize( |
| 106 | + "app", [create_app(schema=AsyncSchema, enable_async=True, graphiql=True)] |
| 107 | +) |
| 108 | +async def test_graphiql_enabled_async_schema(app, client): |
107 | 109 | response = await client.get(
|
108 | 110 | url_string(query="{a,b,c}"), headers={"Accept": "text/html"},
|
109 | 111 | )
|
110 | 112 |
|
| 113 | + expected_response = ( |
| 114 | + ( |
| 115 | + "{\n" |
| 116 | + ' "data": {\n' |
| 117 | + ' "a": "hey",\n' |
| 118 | + ' "b": "hey2",\n' |
| 119 | + ' "c": "hey3"\n' |
| 120 | + " }\n" |
| 121 | + "}" |
| 122 | + ) |
| 123 | + .replace('"', '\\"') |
| 124 | + .replace("\n", "\\n") |
| 125 | + ) |
| 126 | + assert response.status == 200 |
| 127 | + assert expected_response in await response.text() |
| 128 | + |
| 129 | + |
| 130 | +@pytest.mark.asyncio |
| 131 | +@pytest.mark.parametrize( |
| 132 | + "app", [create_app(schema=SyncSchema, enable_async=True, graphiql=True)] |
| 133 | +) |
| 134 | +async def test_graphiql_enabled_sync_schema(app, client): |
| 135 | + response = await client.get( |
| 136 | + url_string(query="{a,b}"), headers={"Accept": "text/html"}, |
| 137 | + ) |
| 138 | + |
| 139 | + expected_response = ( |
| 140 | + ( |
| 141 | + "{\n" |
| 142 | + ' "data": {\n' |
| 143 | + ' "a": "synced_one",\n' |
| 144 | + ' "b": "synced_two"\n' |
| 145 | + " }\n" |
| 146 | + "}" |
| 147 | + ) |
| 148 | + .replace('"', '\\"') |
| 149 | + .replace("\n", "\\n") |
| 150 | + ) |
111 | 151 | assert response.status == 200
|
112 |
| - assert await response.json() == {"data": {"a": "hey", "b": "hey2", "c": "hey3"}} |
| 152 | + assert expected_response in await response.text() |
0 commit comments