from my_modules.upload_content import parse_multipart_upload_body, recover_file_from_multipart_body def test_recovers_file_part_without_filename(): boundary = '----nanoshare-test-boundary' body = ( f'--{boundary}\r\n' 'Content-Disposition: form-data; name="file"\r\n' 'Content-Type: application/octet-stream\r\n' '\r\n' ).encode() + b'hello upload' + ( '\r\n' f'--{boundary}\r\n' 'Content-Disposition: form-data; name="expires"\r\n' '\r\n' '7d\r\n' f'--{boundary}--\r\n' ).encode() uploaded = recover_file_from_multipart_body(body, boundary) parts = parse_multipart_upload_body(body, boundary) assert uploaded is not None assert uploaded.filename == 'file' assert uploaded.mimetype == 'application/octet-stream' assert uploaded.stream.read() == b'hello upload' assert parts.fields == {'expires': '7d'} assert parts.file is not None assert parts.file.stream.read() == b'hello upload'