@@ -479,6 +479,74 @@ def test_code():
479
479
await run_sync_test (event_loop , server , test_code )
480
480
481
481
482
+ @pytest .mark .aiohttp
483
+ @pytest .mark .asyncio
484
+ async def test_requests_file_upload_with_content_type (
485
+ event_loop , aiohttp_server , run_sync_test
486
+ ):
487
+ from aiohttp import web
488
+ from gql .transport .requests import RequestsHTTPTransport
489
+
490
+ async def single_upload_handler (request ):
491
+ from aiohttp import web
492
+
493
+ reader = await request .multipart ()
494
+
495
+ field_0 = await reader .next ()
496
+ assert field_0 .name == "operations"
497
+ field_0_text = await field_0 .text ()
498
+ assert field_0_text == file_upload_mutation_1_operations
499
+
500
+ field_1 = await reader .next ()
501
+ assert field_1 .name == "map"
502
+ field_1_text = await field_1 .text ()
503
+ assert field_1_text == file_upload_mutation_1_map
504
+
505
+ field_2 = await reader .next ()
506
+ assert field_2 .name == "0"
507
+ field_2_text = await field_2 .text ()
508
+ assert field_2_text == file_1_content
509
+
510
+ # Verifying the content_type
511
+ assert field_2 .headers ["Content-Type" ] == "application/pdf"
512
+
513
+ field_3 = await reader .next ()
514
+ assert field_3 is None
515
+
516
+ return web .Response (
517
+ text = file_upload_server_answer , content_type = "application/json"
518
+ )
519
+
520
+ app = web .Application ()
521
+ app .router .add_route ("POST" , "/" , single_upload_handler )
522
+ server = await aiohttp_server (app )
523
+
524
+ url = server .make_url ("/" )
525
+
526
+ def test_code ():
527
+ transport = RequestsHTTPTransport (url = url )
528
+
529
+ with TemporaryFile (file_1_content ) as test_file :
530
+ with Client (transport = transport ) as session :
531
+ query = gql (file_upload_mutation_1 )
532
+
533
+ file_path = test_file .filename
534
+
535
+ with open (file_path , "rb" ) as f :
536
+
537
+ # Setting the content_type
538
+ f .content_type = "application/pdf"
539
+
540
+ params = {"file" : f , "other_var" : 42 }
541
+ execution_result = session ._execute (
542
+ query , variable_values = params , upload_files = True
543
+ )
544
+
545
+ assert execution_result .data ["success" ]
546
+
547
+ await run_sync_test (event_loop , server , test_code )
548
+
549
+
482
550
@pytest .mark .aiohttp
483
551
@pytest .mark .asyncio
484
552
async def test_requests_file_upload_additional_headers (
0 commit comments