@@ -265,7 +265,7 @@ async def test_pull_file_from_remote_s3_presigned_link(
265265 "get_object" ,
266266 Params = {
267267 "Bucket" : s3_settings .S3_BUCKET_NAME ,
268- "Key" : s3_remote_file_url .path .removeprefix ("/" ) ,
268+ "Key" : f" { s3_remote_file_url .path .removeprefix ('/' ) } " ,
269269 },
270270 ExpiresIn = 30 ,
271271 )
@@ -286,6 +286,59 @@ async def test_pull_file_from_remote_s3_presigned_link(
286286 mocked_log_publishing_cb .assert_called ()
287287
288288
289+ async def test_pull_file_from_remote_s3_presigned_link_invalid_file (
290+ s3_settings : S3Settings ,
291+ s3_remote_file_url : AnyUrl ,
292+ s3_client : S3Client ,
293+ tmp_path : Path ,
294+ faker : Faker ,
295+ mocked_log_publishing_cb : mock .AsyncMock ,
296+ ):
297+ storage_kwargs = _s3fs_settings_from_s3_settings (s3_settings )
298+ # put some file on the remote
299+ TEXT_IN_FILE = faker .text ()
300+ with cast (
301+ fsspec .core .OpenFile ,
302+ fsspec .open (
303+ f"{ s3_remote_file_url } " ,
304+ mode = "wt" ,
305+ ** storage_kwargs ,
306+ ),
307+ ) as fp :
308+ fp .write (TEXT_IN_FILE )
309+
310+ # create a corresponding presigned get link
311+ assert s3_remote_file_url .path
312+ invalid_remote_file_url = TypeAdapter (AnyUrl ).validate_python (
313+ await s3_client .generate_presigned_url (
314+ "get_object" ,
315+ Params = {
316+ "Bucket" : s3_settings .S3_BUCKET_NAME ,
317+ "Key" : f"{ s3_remote_file_url .path .removeprefix ('/' )} _invalid" ,
318+ },
319+ ExpiresIn = 30 ,
320+ )
321+ )
322+ assert invalid_remote_file_url .scheme .startswith ("http" )
323+ print (f"remote_file_url: { invalid_remote_file_url } " )
324+ # now let's get the file through the util
325+ dst_path = tmp_path / faker .file_name ()
326+ with pytest .raises (
327+ FileNotFoundError ,
328+ match = rf"{ s3_remote_file_url .path .removeprefix ('/' )} _invalid" ,
329+ ):
330+ await pull_file_from_remote (
331+ src_url = invalid_remote_file_url ,
332+ target_mime_type = None ,
333+ dst_path = dst_path ,
334+ log_publishing_cb = mocked_log_publishing_cb ,
335+ s3_settings = None ,
336+ )
337+
338+ assert not dst_path .exists ()
339+ mocked_log_publishing_cb .assert_called ()
340+
341+
289342async def test_pull_compressed_zip_file_from_remote (
290343 remote_parameters : StorageParameters ,
291344 tmp_path : Path ,
0 commit comments