Skip to content

Commit 620806d

Browse files
Test sanitized upload open-error message propagation
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 47e8495 commit 620806d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_session_upload_utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import contextmanager
12
import io
23
from os import PathLike
34
from pathlib import Path
@@ -185,6 +186,38 @@ def test_open_upload_files_from_input_reuses_file_like_object():
185186
assert files == {"file": file_obj}
186187

187188

189+
def test_open_upload_files_from_input_uses_sanitized_open_error_message(
190+
monkeypatch: pytest.MonkeyPatch,
191+
):
192+
captured: dict[str, str] = {}
193+
194+
@contextmanager
195+
def _open_binary_file_stub(file_path, *, open_error_message): # type: ignore[no-untyped-def]
196+
captured["file_path"] = file_path
197+
captured["open_error_message"] = open_error_message
198+
yield io.BytesIO(b"content")
199+
200+
monkeypatch.setattr(
201+
session_upload_utils,
202+
"normalize_upload_file_input",
203+
lambda file_input: ("bad\tpath.txt", None),
204+
)
205+
monkeypatch.setattr(
206+
session_upload_utils,
207+
"open_binary_file",
208+
_open_binary_file_stub,
209+
)
210+
211+
with open_upload_files_from_input("ignored-input") as files:
212+
assert files["file"].read() == b"content"
213+
214+
assert captured["file_path"] == "bad\tpath.txt"
215+
assert (
216+
captured["open_error_message"]
217+
== "Failed to open upload file at path: bad?path.txt"
218+
)
219+
220+
188221
def test_open_upload_files_from_input_rejects_missing_normalized_file_object(
189222
monkeypatch: pytest.MonkeyPatch,
190223
):

0 commit comments

Comments
 (0)