@@ -102,6 +102,37 @@ async def handler(request):
102
102
assert africa ["code" ] == "AF"
103
103
104
104
105
+ @pytest .mark .asyncio
106
+ async def test_aiohttp_error_code_401 (event_loop , aiohttp_server ):
107
+ from aiohttp import web
108
+ from gql .transport .aiohttp import AIOHTTPTransport
109
+
110
+ async def handler (request ):
111
+ # Will generate http error code 401
112
+ return web .Response (
113
+ text = '{"error":"Unauthorized","message":"401 Client Error: Unauthorized"}' ,
114
+ content_type = "application/json" ,
115
+ status = 401 ,
116
+ )
117
+
118
+ app = web .Application ()
119
+ app .router .add_route ("POST" , "/" , handler )
120
+ server = await aiohttp_server (app )
121
+
122
+ url = server .make_url ("/" )
123
+
124
+ sample_transport = AIOHTTPTransport (url = url )
125
+
126
+ async with Client (transport = sample_transport ,) as session :
127
+
128
+ query = gql (query1_str )
129
+
130
+ with pytest .raises (TransportServerError ) as exc_info :
131
+ await session .execute (query )
132
+
133
+ assert "401, message='Unauthorized'" in str (exc_info .value )
134
+
135
+
105
136
@pytest .mark .asyncio
106
137
async def test_aiohttp_error_code_500 (event_loop , aiohttp_server ):
107
138
from aiohttp import web
@@ -163,20 +194,20 @@ async def handler(request):
163
194
"response" : "{}" ,
164
195
"expected_exception" : (
165
196
"Server did not return a GraphQL result: "
166
- 'No "data" or "error " keys in answer: {}'
197
+ 'No "data" or "errors " keys in answer: {}'
167
198
),
168
199
},
169
200
{
170
201
"response" : "qlsjfqsdlkj" ,
171
202
"expected_exception" : (
172
- "Server did not return a GraphQL result: " " qlsjfqsdlkj"
203
+ "Server did not return a GraphQL result: Not a JSON answer: qlsjfqsdlkj"
173
204
),
174
205
},
175
206
{
176
207
"response" : '{"not_data_or_errors": 35}' ,
177
208
"expected_exception" : (
178
209
"Server did not return a GraphQL result: "
179
- 'No "data" or "error " keys in answer: {"not_data_or_errors": 35}'
210
+ 'No "data" or "errors " keys in answer: {"not_data_or_errors": 35}'
180
211
),
181
212
},
182
213
]
0 commit comments