@@ -57,6 +57,37 @@ async def multipart():
5757 return client
5858
5959
60+ @pytest .fixture (scope = "function" )
61+ def multipart_stream_client (current , client , tmpdir : Path ):
62+ app = client .application
63+
64+ @app .route ("/" , output = "str" )
65+ async def multipart ():
66+ target = tmpdir / "save.txt"
67+ files = await current .request .files
68+ with target .open ("wb" ) as tf :
69+ for chunk in files .test :
70+ tf .write (chunk )
71+ return ""
72+
73+ return client
74+
75+
76+ @pytest .fixture (scope = "function" )
77+ def multipart_copy_client (current , client , tmpdir : Path ):
78+ app = client .application
79+
80+ @app .route ("/" , output = "str" )
81+ async def multipart ():
82+ target = tmpdir / "save.txt"
83+ files = await current .request .files
84+ with target .open ("wb" ) as tf :
85+ tf .write (files .test .read ())
86+ return ""
87+
88+ return client
89+
90+
6091def test_multipart_request_data (multipart_client ):
6192 response = multipart_client .post ("/" , data = {"some" : "data" }, content_type = "multipart/form-data" )
6293 assert response .json () == {"params" : {"some" : ["data" ]}, "files" : {}}
@@ -340,8 +371,8 @@ def test_multipart_request_file_save(tmpdir: Path, multipart_save_client):
340371 target = tmpdir / "save.txt"
341372 with path .open ("wb" ) as file :
342373 file .write (b"<" )
343- for i in range (8192 ):
344- file .write (f"{ i } " .zfill (5 ).encode ("utf8" ))
374+ for i in range (8192 * 128 ):
375+ file .write (f"{ i } " .zfill (7 ).encode ("utf8" ))
345376 file .write (b">" )
346377
347378 with path .open ("rb" ) as f :
@@ -350,3 +381,37 @@ def test_multipart_request_file_save(tmpdir: Path, multipart_save_client):
350381
351382 with path .open ("rb" ) as f1 , target .open ("rb" ) as f2 :
352383 assert f1 .read () == f2 .read ()
384+
385+
386+ def test_multipart_request_file_stream (tmpdir : Path , multipart_stream_client ):
387+ path = tmpdir / "test.txt"
388+ target = tmpdir / "save.txt"
389+ with path .open ("wb" ) as file :
390+ file .write (b"<" )
391+ for i in range (8192 * 128 ):
392+ file .write (f"{ i } " .zfill (7 ).encode ("utf8" ))
393+ file .write (b">" )
394+
395+ with path .open ("rb" ) as f :
396+ response = multipart_stream_client .post ("/" , data = {"test" : (f , "test.txt" , "text/plain" )})
397+ assert response .status == 200
398+
399+ with path .open ("rb" ) as f1 , target .open ("rb" ) as f2 :
400+ assert f1 .read () == f2 .read ()
401+
402+
403+ def test_multipart_request_file_copy (tmpdir : Path , multipart_copy_client ):
404+ path = tmpdir / "test.txt"
405+ target = tmpdir / "save.txt"
406+ with path .open ("wb" ) as file :
407+ file .write (b"<" )
408+ for i in range (8192 * 128 ):
409+ file .write (f"{ i } " .zfill (7 ).encode ("utf8" ))
410+ file .write (b">" )
411+
412+ with path .open ("rb" ) as f :
413+ response = multipart_copy_client .post ("/" , data = {"test" : (f , "test.txt" , "text/plain" )})
414+ assert response .status == 200
415+
416+ with path .open ("rb" ) as f1 , target .open ("rb" ) as f2 :
417+ assert f1 .read () == f2 .read ()
0 commit comments