1
+ from typing import Optional
2
+
1
3
import pytest
2
4
from quart import Quart , Response , url_for
3
- from quart .testing import QuartClient
5
+ from quart .typing import TestClientProtocol
4
6
from werkzeug .datastructures import Headers
5
7
6
8
from .app import create_app
@@ -18,16 +20,16 @@ def app() -> Quart:
18
20
19
21
20
22
@pytest .fixture
21
- def client (app : Quart ) -> QuartClient :
23
+ def client (app : Quart ) -> TestClientProtocol :
22
24
return app .test_client ()
23
25
24
26
25
27
@pytest .mark .asyncio
26
28
async def execute_client (
27
29
app : Quart ,
28
- client : QuartClient ,
30
+ client : TestClientProtocol ,
29
31
method : str = "GET" ,
30
- headers : Headers = None ,
32
+ headers : Optional [ Headers ] = None ,
31
33
** extra_params
32
34
) -> Response :
33
35
test_request_context = app .test_request_context (path = "/" , method = method )
@@ -37,15 +39,15 @@ async def execute_client(
37
39
38
40
39
41
@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 ):
41
43
response = await execute_client (
42
44
app , client , headers = Headers ({"Accept" : "text/html" }), externals = False
43
45
)
44
46
assert response .status_code == 200
45
47
46
48
47
49
@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 ):
49
51
response = await execute_client (
50
52
app , client , headers = Headers ({"Accept" : "text/html" }), query = "{test}"
51
53
)
@@ -57,26 +59,26 @@ async def test_graphiql_renders_pretty(app: Quart, client: QuartClient):
57
59
" }\n "
58
60
"}" .replace ('"' , '\\ "' ).replace ("\n " , "\\ n" )
59
61
)
60
- result = await response .get_data (raw = False )
62
+ result = await response .get_data (as_text = True )
61
63
assert pretty_response in result
62
64
63
65
64
66
@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 ):
66
68
response = await execute_client (
67
69
app , client , headers = Headers ({"Accept" : "text/html" })
68
70
)
69
- result = await response .get_data (raw = False )
71
+ result = await response .get_data (as_text = True )
70
72
assert "<title>GraphiQL</title>" in result
71
73
72
74
73
75
@pytest .mark .asyncio
74
76
@pytest .mark .parametrize (
75
77
"app" , [create_app (graphiql = True , graphiql_html_title = "Awesome" )]
76
78
)
77
- async def test_graphiql_custom_title (app : Quart , client : QuartClient ):
79
+ async def test_graphiql_custom_title (app : Quart , client : TestClientProtocol ):
78
80
response = await execute_client (
79
81
app , client , headers = Headers ({"Accept" : "text/html" })
80
82
)
81
- result = await response .get_data (raw = False )
83
+ result = await response .get_data (as_text = True )
82
84
assert "<title>Awesome</title>" in result
0 commit comments