|
9 | 9 | - Validation constraints |
10 | 10 | - Mixed file and form data scenarios |
11 | 11 | """ |
| 12 | + |
12 | 13 | import base64 |
13 | 14 | import json |
14 | 15 | from typing import Annotated |
@@ -342,7 +343,7 @@ def upload_file(file: Annotated[bytes, File()]): |
342 | 343 | "httpMethod": "POST", |
343 | 344 | "apiId": "abcdefghij", |
344 | 345 | }, |
345 | | - "body": "--test\r\nContent-Disposition: form-data; name=\"other\"\r\n\r\nvalue\r\n--test--", |
| 346 | + "body": '--test\r\nContent-Disposition: form-data; name="other"\r\n\r\nvalue\r\n--test--', |
346 | 347 | "isBase64Encoded": False, |
347 | 348 | } |
348 | 349 |
|
@@ -383,7 +384,7 @@ def upload_file(file: Annotated[Union[bytes, None], File()] = None): |
383 | 384 | "httpMethod": "POST", |
384 | 385 | "apiId": "abcdefghij", |
385 | 386 | }, |
386 | | - "body": "--test\r\nContent-Disposition: form-data; name=\"other\"\r\n\r\nvalue\r\n--test--", |
| 387 | + "body": '--test\r\nContent-Disposition: form-data; name="other"\r\n\r\nvalue\r\n--test--', |
387 | 388 | "isBase64Encoded": False, |
388 | 389 | } |
389 | 390 |
|
@@ -616,21 +617,21 @@ def upload_with_data( |
616 | 617 | # Create multipart data with invalid UTF-8 in form field |
617 | 618 | boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW" |
618 | 619 | invalid_utf8_bytes = b"\xff\xfe\xfd" |
619 | | - |
| 620 | + |
620 | 621 | body_parts = [] |
621 | 622 | body_parts.append(f"--{boundary}") |
622 | 623 | body_parts.append('Content-Disposition: form-data; name="file"; filename="test.txt"') |
623 | 624 | body_parts.append("Content-Type: text/plain") |
624 | 625 | body_parts.append("") |
625 | 626 | body_parts.append("File content") |
626 | | - |
| 627 | + |
627 | 628 | body_parts.append(f"--{boundary}") |
628 | 629 | body_parts.append('Content-Disposition: form-data; name="metadata"') |
629 | 630 | body_parts.append("") |
630 | | - |
| 631 | + |
631 | 632 | body_start = "\r\n".join(body_parts) + "\r\n" |
632 | 633 | body_end = f"\r\n--{boundary}--" |
633 | | - |
| 634 | + |
634 | 635 | # Combine with the invalid UTF-8 bytes |
635 | 636 | full_body = body_start.encode("utf-8") + invalid_utf8_bytes + body_end.encode("utf-8") |
636 | 637 |
|
@@ -676,7 +677,7 @@ def upload_file(file: Annotated[bytes, File()]): |
676 | 677 | return {"status": "uploaded"} |
677 | 678 |
|
678 | 679 | webkit_boundary = "WebKitFormBoundary7MA4YWxkTrZu0gW123" |
679 | | - |
| 680 | + |
680 | 681 | body_lines = [ |
681 | 682 | f"--{webkit_boundary}", |
682 | 683 | 'Content-Disposition: form-data; name="file"; filename="test.txt"', |
@@ -724,7 +725,7 @@ def upload_file(file: Annotated[bytes, File()]): |
724 | 725 | return {"status": "uploaded"} |
725 | 726 |
|
726 | 727 | boundary = "test-boundary-123" |
727 | | - |
| 728 | + |
728 | 729 | body_lines = [ |
729 | 730 | f"--{boundary}", |
730 | 731 | 'Content-Disposition: form-data; name="file"; filename="test.txt"', |
|
0 commit comments