22
33import aiohttp
44import pytest
5+ from pathlib import Path
56
67from connexion import AioHttpApp
78
@@ -37,13 +38,17 @@ async def test_single_file_upload(aiohttp_app, aiohttp_client):
3738 data = await resp .json ()
3839 assert resp .status == 200
3940 assert data ['fileName' ] == f'{ __name__ } .py'
41+ assert data ['content' ] == Path (__file__ ).read_bytes ().decode ('utf8' )
4042
4143
4244async def test_many_files_upload (aiohttp_app , aiohttp_client ):
4345 app_client = await aiohttp_client (aiohttp_app .app )
4446
4547 dir_name = os .path .dirname (__file__ )
46- files_field = [('files' , open (f'{ dir_name } /{ file_name } ' , 'rb' )) for file_name in os .listdir (dir_name ) if file_name .endswith ('.py' )]
48+ files_field = [
49+ ('files' , open (f'{ dir_name } /{ file_name } ' , 'rb' )) \
50+ for file_name in os .listdir (dir_name ) if file_name .endswith ('.py' )
51+ ]
4752
4853 form_data = aiohttp .FormData (fields = files_field )
4954
@@ -75,13 +80,18 @@ async def test_mixed_multipart_single_file(aiohttp_app, aiohttp_client):
7580 assert resp .status == 200
7681 assert data ['dirName' ] == os .path .dirname (__file__ )
7782 assert data ['fileName' ] == f'{ __name__ } .py'
83+ assert data ['content' ] == Path (__file__ ).read_bytes ().decode ('utf8' )
84+
7885
7986
8087async def test_mixed_multipart_many_files (aiohttp_app , aiohttp_client ):
8188 app_client = await aiohttp_client (aiohttp_app .app )
8289
8390 dir_name = os .path .dirname (__file__ )
84- files_field = [('files' , open (f'{ dir_name } /{ file_name } ' , 'rb' )) for file_name in os .listdir (dir_name ) if file_name .endswith ('.py' )]
91+ files_field = [
92+ ('files' , open (f'{ dir_name } /{ file_name } ' , 'rb' )) \
93+ for file_name in sorted (os .listdir (dir_name )) if file_name .endswith ('.py' )
94+ ]
8595
8696 form_data = aiohttp .FormData (fields = files_field )
8797 form_data .add_field ('dirName' , os .path .dirname (__file__ ))
@@ -98,3 +108,7 @@ async def test_mixed_multipart_many_files(aiohttp_app, aiohttp_client):
98108 assert data ['dirName' ] == os .path .dirname (__file__ )
99109 assert data ['testCount' ] == len (files_field )
100110 assert data ['filesCount' ] == len (files_field )
111+ assert data ['contents' ] == [
112+ Path (f'{ dir_name } /{ file_name } ' ).read_bytes ().decode ('utf8' ) \
113+ for file_name in sorted (os .listdir (dir_name )) if file_name .endswith ('.py' )
114+ ]
0 commit comments