@@ -41,6 +41,21 @@ def copy_transfer_cb(total_bytes_copied: int, *, file_name: str) -> None:
4141 return copy_transfer_cb
4242
4343
44+ @pytest .fixture
45+ async def cleanup_when_done (
46+ simcore_s3_dsm : SimcoreS3DataManager , user_id : UserID
47+ ) -> AsyncIterable [Callable [[SimcoreS3FileID ], None ]]:
48+ to_remove : set [SimcoreS3FileID ] = set ()
49+
50+ def _ (file_id : SimcoreS3FileID ) -> None :
51+ to_remove .add (file_id )
52+
53+ yield _
54+
55+ for file_id in to_remove :
56+ await simcore_s3_dsm .delete_file (user_id , file_id )
57+
58+
4459async def test__copy_path_s3_s3 (
4560 simcore_s3_dsm : SimcoreS3DataManager ,
4661 create_directory_with_files : Callable [
@@ -51,11 +66,14 @@ async def test__copy_path_s3_s3(
5166 user_id : UserID ,
5267 mock_copy_transfer_cb : Callable [..., None ],
5368 sqlalchemy_async_engine : AsyncEngine ,
69+ cleanup_when_done : Callable [[SimcoreS3FileID ], None ],
5470):
5571 def _get_dest_file_id (src : SimcoreS3FileID ) -> SimcoreS3FileID :
56- return TypeAdapter (SimcoreS3FileID ).validate_python (
72+ copy_file_id = TypeAdapter (SimcoreS3FileID ).validate_python (
5773 f"{ Path (src ).parent } /the-copy"
5874 )
75+ cleanup_when_done (copy_file_id )
76+ return copy_file_id
5977
6078 async def _copy_s3_path (s3_file_id_to_copy : SimcoreS3FileID ) -> None :
6179 async with sqlalchemy_async_engine .connect () as conn :
@@ -182,6 +200,7 @@ async def test_create_s3_export(
182200 user_id : UserID ,
183201 paths_for_export : set [StorageFileID ],
184202 sqlalchemy_async_engine : AsyncEngine ,
203+ cleanup_when_done : Callable [[SimcoreS3FileID ], None ],
185204):
186205 selection_to_export = _get_folder_and_files_selection (paths_for_export )
187206
@@ -194,6 +213,7 @@ async def _progress_cb(report: ProgressReport) -> None:
194213 file_id = await simcore_s3_dsm .create_s3_export (
195214 user_id , selection_to_export , progress_cb = _progress_cb
196215 )
216+ cleanup_when_done (file_id )
197217 # count=2 -> the direcotory and the .zip export
198218 await _assert_meta_data_entries_count (sqlalchemy_async_engine , count = 2 )
199219
0 commit comments