Files
simple-nanoshare/tests/test_upload_content.py
T
daniel156161 3194e534e0
Build and Push Docker Container / build-and-push (push) Successful in 1m40s
fix(upload): preserve fields in multipart fallback
- Recover regular multipart fields when the file part is not exposed through request.files.

- Preserve expires and note values for browser uploads that need body-based file recovery.

- Add parser coverage for file parts without filenames and recovered expiry fields.

- Extend upload route tests to assert recovered uploads keep expiry metadata.

- Bump NanoShare to 1.27.3.
2026-09-10 00:18:57 +02:00

29 lines
952 B
Python

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'