(file_response_client: TestClient)
| 871 | |
| 872 | |
| 873 | def test_file_response_insert_ranges(file_response_client: TestClient) -> None: |
| 874 | response = file_response_client.get("/", headers={"Range": "bytes=100-200, 0-50"}) |
| 875 | |
| 876 | assert response.status_code == 206 |
| 877 | assert "content-range" not in response.headers |
| 878 | assert response.headers["content-type"].startswith("multipart/byteranges; boundary=") |
| 879 | boundary = response.headers["content-type"].split("boundary=")[1] |
| 880 | assert response.text.splitlines() == [ |
| 881 | f"--{boundary}", |
| 882 | "Content-Type: text/plain; charset=utf-8", |
| 883 | "Content-Range: bytes 0-50/526", |
| 884 | "", |
| 885 | "# BáiZé", |
| 886 | "", |
| 887 | "Powerful and exquisite WSGI/ASGI framewo", |
| 888 | f"--{boundary}", |
| 889 | "Content-Type: text/plain; charset=utf-8", |
| 890 | "Content-Range: bytes 100-200/526", |
| 891 | "", |
| 892 | "ds required in the Web framework. No redundant implementation means that you can freely customize fun", |
| 893 | f"--{boundary}--", |
| 894 | ] |
| 895 | |
| 896 | parts = parse_multipart_data(response._content, boundary) |
| 897 | assert all( |
| 898 | value == b"text/plain; charset=utf-8" |
| 899 | for part in parts |
| 900 | for key, value in part.headers.items() |
| 901 | if key == b"Content-Type" |
| 902 | ) |
| 903 | assert len(parts) == 2 |
| 904 | assert parts[0].headers[b"Content-Range"] == b"bytes 0-50/526" |
| 905 | assert parts[0].data == "# BáiZé\n\nPowerful and exquisite WSGI/ASGI framewo".encode() |
| 906 | assert parts[1].headers[b"Content-Range"] == b"bytes 100-200/526" |
| 907 | assert ( |
| 908 | parts[1].data |
| 909 | == b"ds required in the Web framework. No redundant implementation means that you can freely customize fun" |
| 910 | ) |
| 911 | |
| 912 | |
| 913 | def test_file_response_range_without_dash(file_response_client: TestClient) -> None: |
nothing calls this directly
no test coverage detected