File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ from contextlib import contextmanager
12import io
23from os import PathLike
34from 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\t path.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\t path.txt"
215+ assert (
216+ captured ["open_error_message" ]
217+ == "Failed to open upload file at path: bad?path.txt"
218+ )
219+
220+
188221def test_open_upload_files_from_input_rejects_missing_normalized_file_object (
189222 monkeypatch : pytest .MonkeyPatch ,
190223):
You can’t perform that action at this time.
0 commit comments