| 41 | assert result.value == 1 |
| 42 | |
| 43 | def test_storify_with_a_binary_file_value(self): |
| 44 | # Prepare some raw multipart data with a binary file attachment |
| 45 | binary_file_content = b"\x01\x02\x03\x04\x05" |
| 46 | raw_data = b"""--boundary\r |
| 47 | Content-Disposition: form-data; name="field1"\r |
| 48 | \r |
| 49 | value1\r |
| 50 | --boundary\r |
| 51 | Content-Disposition: form-data; name="field2"\r |
| 52 | \r |
| 53 | value2\r |
| 54 | --boundary\r |
| 55 | Content-Disposition: form-data; name="file"; filename="example.bin"\r |
| 56 | Content-Type: application/octet-stream\r |
| 57 | \r |
| 58 | """ + binary_file_content + b"\r\n--boundary--\r\n" |
| 59 | |
| 60 | # Create a BytesIO object from the raw data |
| 61 | buffer = BytesIO(raw_data) |
| 62 | |
| 63 | # Parse the multipart data |
| 64 | environ = { |
| 65 | "REQUEST_METHOD": "POST", |
| 66 | "CONTENT_TYPE": "multipart/form-data; boundary=boundary", |
| 67 | "CONTENT_LENGTH": str(len(raw_data)), |
| 68 | "wsgi.input": buffer, |
| 69 | } |
| 70 | |
| 71 | _, files = parse_form_data(environ) |
| 72 | |
| 73 | # Check if 'file' and 'raw' attributes exist |
| 74 | file_obj = files.get("file") |
| 75 | assert hasattr(file_obj, "file") |
| 76 | assert hasattr(file_obj, "raw") |
| 77 | |
| 78 | # Ensure binary content matches. |
| 79 | result = utils.storify({"files": file_obj}) |
| 80 | assert result.files == binary_file_content |