Skip to content

Commit d184cdc

Browse files
Choongkyukiendang
authored andcommitted
Fixes for quart >=0.15
Fix quart.request.get_data signature QuartClient -> TestClientProtocol
1 parent 7b45e70 commit d184cdc

File tree

3 files changed

+120
-91
lines changed

3 files changed

+120
-91
lines changed

graphql_server/quart/graphqlview.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ async def parse_body():
165165
# information provided by content_type
166166
content_type = request.mimetype
167167
if content_type == "application/graphql":
168-
refined_data = await request.get_data(raw=False)
168+
refined_data = await request.get_data(as_text=True)
169169
return {"query": refined_data}
170170

171171
elif content_type == "application/json":
172-
refined_data = await request.get_data(raw=False)
172+
refined_data = await request.get_data(as_text=True)
173173
return load_json_body(refined_data)
174174

175175
elif content_type == "application/x-www-form-urlencoded":

tests/quart/test_graphiqlview.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from typing import Optional
2+
13
import pytest
24
from quart import Quart, Response, url_for
3-
from quart.testing import QuartClient
5+
from quart.typing import TestClientProtocol
46
from werkzeug.datastructures import Headers
57

68
from .app import create_app
@@ -18,16 +20,16 @@ def app() -> Quart:
1820

1921

2022
@pytest.fixture
21-
def client(app: Quart) -> QuartClient:
23+
def client(app: Quart) -> TestClientProtocol:
2224
return app.test_client()
2325

2426

2527
@pytest.mark.asyncio
2628
async def execute_client(
2729
app: Quart,
28-
client: QuartClient,
30+
client: TestClientProtocol,
2931
method: str = "GET",
30-
headers: Headers = None,
32+
headers: Optional[Headers] = None,
3133
**extra_params
3234
) -> Response:
3335
test_request_context = app.test_request_context(path="/", method=method)
@@ -37,15 +39,15 @@ async def execute_client(
3739

3840

3941
@pytest.mark.asyncio
40-
async def test_graphiql_is_enabled(app: Quart, client: QuartClient):
42+
async def test_graphiql_is_enabled(app: Quart, client: TestClientProtocol):
4143
response = await execute_client(
4244
app, client, headers=Headers({"Accept": "text/html"}), externals=False
4345
)
4446
assert response.status_code == 200
4547

4648

4749
@pytest.mark.asyncio
48-
async def test_graphiql_renders_pretty(app: Quart, client: QuartClient):
50+
async def test_graphiql_renders_pretty(app: Quart, client: TestClientProtocol):
4951
response = await execute_client(
5052
app, client, headers=Headers({"Accept": "text/html"}), query="{test}"
5153
)
@@ -57,26 +59,26 @@ async def test_graphiql_renders_pretty(app: Quart, client: QuartClient):
5759
" }\n"
5860
"}".replace('"', '\\"').replace("\n", "\\n")
5961
)
60-
result = await response.get_data(raw=False)
62+
result = await response.get_data(as_text=True)
6163
assert pretty_response in result
6264

6365

6466
@pytest.mark.asyncio
65-
async def test_graphiql_default_title(app: Quart, client: QuartClient):
67+
async def test_graphiql_default_title(app: Quart, client: TestClientProtocol):
6668
response = await execute_client(
6769
app, client, headers=Headers({"Accept": "text/html"})
6870
)
69-
result = await response.get_data(raw=False)
71+
result = await response.get_data(as_text=True)
7072
assert "<title>GraphiQL</title>" in result
7173

7274

7375
@pytest.mark.asyncio
7476
@pytest.mark.parametrize(
7577
"app", [create_app(graphiql=True, graphiql_html_title="Awesome")]
7678
)
77-
async def test_graphiql_custom_title(app: Quart, client: QuartClient):
79+
async def test_graphiql_custom_title(app: Quart, client: TestClientProtocol):
7880
response = await execute_client(
7981
app, client, headers=Headers({"Accept": "text/html"})
8082
)
81-
result = await response.get_data(raw=False)
83+
result = await response.get_data(as_text=True)
8284
assert "<title>Awesome</title>" in result

0 commit comments

Comments
 (0)