77from gql import Client , gql
88from gql .graphql_request import GraphQLRequest
99from gql .transport .exceptions import (
10- TransportAlreadyConnected ,
1110 TransportClosed ,
1211 TransportConnectionFailed ,
1312 TransportProtocolError ,
@@ -199,6 +198,22 @@ async def handler(request):
199198 assert "Internal Server Error" in str (exc_info .value )
200199
201200
201+ @pytest .mark .asyncio
202+ async def test_aiohttp_multipart_transport_not_connected (multipart_server ):
203+ from gql .transport .aiohttp import AIOHTTPTransport
204+
205+ parts = create_multipart_response ([book1 ])
206+ server = await multipart_server (parts )
207+ transport = AIOHTTPTransport (url = server .make_url ("/" ))
208+
209+ query = gql (subscription_str )
210+ request = GraphQLRequest (query )
211+
212+ with pytest .raises (TransportClosed ):
213+ async for result in transport .subscribe (request ):
214+ pass
215+
216+
202217@pytest .mark .asyncio
203218async def test_aiohttp_multipart_transport_level_error (multipart_server ):
204219 from gql .transport .aiohttp import AIOHTTPTransport
@@ -276,38 +291,6 @@ async def test_aiohttp_multipart_graphql_errors(multipart_server):
276291 assert exc_info .value .data ["book" ]["title" ] == "Book 1"
277292
278293
279- @pytest .mark .asyncio
280- async def test_aiohttp_multipart_transport_already_connected (multipart_server ):
281- from gql .transport .aiohttp import AIOHTTPTransport
282-
283- parts = create_multipart_response ([])
284- server = await multipart_server (parts )
285- transport = AIOHTTPTransport (url = server .make_url ("/" ))
286-
287- await transport .connect ()
288-
289- with pytest .raises (TransportAlreadyConnected ):
290- await transport .connect ()
291-
292- await transport .close ()
293-
294-
295- @pytest .mark .asyncio
296- async def test_aiohttp_multipart_transport_not_connected (multipart_server ):
297- from gql .transport .aiohttp import AIOHTTPTransport
298-
299- parts = create_multipart_response ([book1 ])
300- server = await multipart_server (parts )
301- transport = AIOHTTPTransport (url = server .make_url ("/" ))
302-
303- query = gql (subscription_str )
304- request = GraphQLRequest (query )
305-
306- with pytest .raises (TransportClosed ):
307- async for result in transport .subscribe (request ):
308- pass
309-
310-
311294@pytest .mark .asyncio
312295async def test_aiohttp_multipart_newline_separator (multipart_server ):
313296 """Test that LF-only separators are rejected (spec requires CRLF)."""
@@ -328,44 +311,6 @@ async def test_aiohttp_multipart_newline_separator(multipart_server):
328311 pass
329312
330313
331- @pytest .mark .asyncio
332- async def test_aiohttp_multipart_transport_connection_failed_error ():
333- from gql .transport .aiohttp import AIOHTTPTransport
334-
335- # Use an invalid URL that will fail to connect
336- transport = AIOHTTPTransport (url = "http://invalid.local:-1/graphql" , timeout = 1 )
337-
338- query = gql (subscription_str )
339-
340- async with Client (transport = transport ) as session :
341- with pytest .raises (TransportConnectionFailed ):
342- async for result in session .subscribe (query ):
343- pass
344-
345-
346- @pytest .mark .asyncio
347- async def test_aiohttp_multipart_connector_owner_false (multipart_server ):
348- """Test closing transport with connector_owner=False."""
349- from gql .transport .aiohttp import AIOHTTPTransport
350-
351- parts = create_multipart_response ([book1 ])
352- server = await multipart_server (parts )
353- url = server .make_url ("/" )
354-
355- transport = AIOHTTPTransport (
356- url = url , client_session_args = {"connector_owner" : False }
357- )
358-
359- query = gql (subscription_str )
360-
361- async with Client (transport = transport ) as session :
362- results = []
363- async for result in session .subscribe (query ):
364- results .append (result )
365-
366- assert len (results ) == 1
367-
368-
369314@pytest .mark .asyncio
370315async def test_aiohttp_multipart_ssl_close_timeout (multipart_server ):
371316 """Test SSL close timeout during transport close."""
0 commit comments