66from pathlib import Path
77
88from API_operations .helpers .Service import Service
9+ from FS .UserFilesDir import get_tus_files_dir
910from helpers .AppConfig import Config
1011from sqlalchemy import text
1112from starlette import status
@@ -112,6 +113,16 @@ def mock_getctime(path):
112113 recent_trash_file .write_text ("recent trashed file" )
113114 os .utime (recent_trash_file , (recent_trash_time , recent_trash_time ))
114115
116+ # 6. TUS uploads directory (old should be removed, recent should NOT be removed)
117+ tus_dir = Path (get_tus_files_dir ())
118+ old_tus_file = tus_dir / "old_tus_upload.tmp"
119+ old_tus_file .write_text ("old tus file" )
120+ os .utime (old_tus_file , (old_time , old_time ))
121+
122+ recent_tus_file = tus_dir / "recent_tus_upload.tmp"
123+ recent_tus_file .write_text ("recent tus file" )
124+ os .utime (recent_tus_file , (recent_time , recent_time ))
125+
115126 return {
116127 "users_files_dir" : users_files_dir ,
117128 "user_dir" : user_dir ,
@@ -122,6 +133,8 @@ def mock_getctime(path):
122133 "recent_in_mixed" : recent_in_mixed ,
123134 "recent_dir" : recent_dir ,
124135 "recent_trash_file" : recent_trash_file ,
136+ "old_tus_file" : old_tus_file ,
137+ "recent_tus_file" : recent_tus_file ,
125138 }
126139
127140
@@ -140,6 +153,8 @@ def test_nightly_job(fastapi, caplog, tstlogs, mock_taxoserver, monkeypatch):
140153 recent_in_mixed = fake_dirs ["recent_in_mixed" ]
141154 recent_dir = fake_dirs ["recent_dir" ]
142155 recent_trash_file = fake_dirs ["recent_trash_file" ]
156+ old_tus_file = fake_dirs ["old_tus_file" ]
157+ recent_tus_file = fake_dirs ["recent_tus_file" ]
143158
144159 # Generate a few jobs however, and warp them back in time
145160 test_export_roundtrip (fastapi , tstlogs ) # Import/Export/Import
@@ -166,11 +181,13 @@ def test_nightly_job(fastapi, caplog, tstlogs, mock_taxoserver, monkeypatch):
166181 assert not old_dir .exists ()
167182 assert not old_trash_subdir .exists ()
168183 assert not old_trash_file .exists ()
184+ assert not old_tus_file .exists ()
169185 assert mixed_dir .exists ()
170186 assert recent_in_mixed .exists ()
171187 assert recent_dir .exists ()
172188 assert (recent_dir / "recent_file.txt" ).exists ()
173189 assert recent_trash_file .exists ()
190+ assert recent_tus_file .exists ()
174191
175192 maintenance_log_file = (
176193 users_files_dir
@@ -181,6 +198,7 @@ def test_nightly_job(fastapi, caplog, tstlogs, mock_taxoserver, monkeypatch):
181198 assert "old_folder" in maintenance_log_content
182199 assert "old_trash_sub" in maintenance_log_content
183200 assert "old_trash_file.txt" in maintenance_log_content
201+ assert "old_tus_upload.tmp" in maintenance_log_content
184202
185203 # Second cleanup must do nothing
186204 log = do_nightly (fastapi )
@@ -191,7 +209,9 @@ def test_nightly_job(fastapi, caplog, tstlogs, mock_taxoserver, monkeypatch):
191209 assert not old_dir .exists ()
192210 assert not old_trash_subdir .exists ()
193211 assert not old_trash_file .exists ()
212+ assert not old_tus_file .exists ()
194213 assert mixed_dir .exists ()
195214 assert recent_in_mixed .exists ()
196215 assert recent_dir .exists ()
197216 assert recent_trash_file .exists ()
217+ assert recent_tus_file .exists ()
0 commit comments