def test_safe_folder_do_not_overwrite(job_file, empty_folder): """Safe folders should not overwrite files, but rather rename if needed""" safe_folder = SafeFolder(path=empty_folder) copy_job_file(job_file, safe_folder) copy_job_file(job_file, safe_folder) assert len([x for x in safe_folder.path.glob("*") if x.is_file()]) == 2
def test_job_folder_missing_job_id(job_file, job_folder): """job files with missing id should be saved in a special 'unknown' category""" job_file.job_id = None copy_job_file(job_file, job_folder) assert job_folder.get_job_ids() == [] assert len(job_folder.get_unknown_job_files()) == 1
def test_job_folder_unparsable_folder(job_file, job_folder): """Internally a job folder has sub folders for each job id. Handle unparsable job ids gracefully""" copy_job_file(job_file, job_folder) # introduce a folder that should be ignored because it cannot be linked to a job id (job_folder.path / "non_int_folder").mkdir() # This should still yield only 1 job id, ignoring the weird folder assert job_folder.get_job_ids() == [job_file.job_id]
def test_job_folder_do_not_overwrite(job_file, job_folder): """Files with the same name will not overwrite existing ones""" # copy the same file twice copy_job_file(job_file, job_folder) copy_job_file(job_file, job_folder) # now there should be two files, because JobFolders never overwrite files assert len(job_folder.get_files(job_file.job_id)) == 2
def test_job_folder(job_file, job_folder): """A job folder should sort job files per jobs """ # copy one jobfile to the folder copy_job_file(job_file, job_folder) # the folder should now know this id assert job_folder.get_job_ids() == [job_file.job_id] # and have one file for this id assert len(job_folder.get_files(job_file.job_id)) == 1
def download_file_to(self, file_info: FileInfo, folder: SafeFolder): """Get file described in file_info and put it in folder Parameters ---------- file_info: FileInfo information specifying a single DICOM file folder: SafeFolder path to download to Returns ------- idis.jobs.filehandling.JobFile The file """ job_file = JobFile(job_id=file_info.job.id, path=file_info.path) copy_job_file(job_file, destination=folder)