def test_temp_download_filename(): temp_destination = utils.temp_download_filename("/foo/bar/bat", 12345) assert_equals(temp_destination, "/foo/bar/bat.synapse_download_12345", temp_destination) regex = r'/foo/bar/bat.synapse_download_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' assert_true( re.match(regex, utils.temp_download_filename("/foo/bar/bat", None)))
def test_resume_partial_download(): original_file = utils.make_bogus_data_file(40000) original_md5 = utils.md5_for_file(original_file).hexdigest() entity = File(original_file, parent=project['id']) entity = syn.store(entity) ## stash the original file for comparison later shutil.move(original_file, original_file+'.original') original_file += '.original' schedule_for_cleanup(original_file) temp_dir = tempfile.gettempdir() url = '%s/entity/%s/file' % (syn.repoEndpoint, entity.id) path = syn._download(url, destination=temp_dir, file_handle_id=entity.dataFileHandleId, expected_md5=entity.md5) ## simulate an imcomplete download by putting the ## complete file back into its temporary location tmp_path = utils.temp_download_filename(temp_dir, entity.dataFileHandleId) shutil.move(path, tmp_path) ## ...and truncating it to some fraction of its original size with open(tmp_path, 'r+') as f: f.truncate(3*os.path.getsize(original_file)//7) ## this should complete the partial download path = syn._download(url, destination=temp_dir, file_handle_id=entity.dataFileHandleId, expected_md5=entity.md5) assert filecmp.cmp(original_file, path), "File comparison failed"
def test_http_download__range_request_error(): # SYNPY-525 file_path = utils.make_bogus_data_file() file_entity = syn.store(File(file_path, parent=project)) syn.cache.purge(time.time()) #download once and rename to temp file to simulate range exceed file_entity = syn.get(file_entity) shutil.move( file_entity.path, utils.temp_download_filename(file_entity.path, file_entity.dataFileHandleId)) file_entity = syn.get(file_entity) assert_not_equal(file_path, file_entity.path) assert filecmp.cmp(file_path, file_entity.path)
def test_resume_partial_download(): original_file = utils.make_bogus_data_file(40000) original_md5 = utils.md5_for_file(original_file).hexdigest() entity = File(original_file, parent=project['id']) entity = syn.store(entity) ## stash the original file for comparison later shutil.move(original_file, original_file + '.original') original_file += '.original' schedule_for_cleanup(original_file) temp_dir = tempfile.gettempdir() url = '%s/entity/%s/file' % (syn.repoEndpoint, entity.id) path = syn._download_from_URL(url, destination=temp_dir, fileHandleId=entity.dataFileHandleId, expected_md5=entity.md5) ## simulate an imcomplete download by putting the ## complete file back into its temporary location tmp_path = utils.temp_download_filename(temp_dir, entity.dataFileHandleId) shutil.move(path, tmp_path) ## ...and truncating it to some fraction of its original size with open(tmp_path, 'r+') as f: f.truncate(3 * os.path.getsize(original_file) // 7) ## this should complete the partial download path = syn._download_from_URL(url, destination=temp_dir, fileHandleId=entity.dataFileHandleId, expected_md5=entity.md5) assert filecmp.cmp(original_file, path), "File comparison failed"
def test_temp_download_filename(): temp_destination = utils.temp_download_filename("/foo/bar/bat", 12345) assert temp_destination == "/foo/bar/bat.synapse_download_12345", temp_destination regex = r"/foo/bar/bat.synapse_download_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" assert re.match(regex, utils.temp_download_filename("/foo/bar/bat", None))
def test_temp_download_filename(): temp_destination = utils.temp_download_filename("/foo/bar/bat", 12345) assert_equals(temp_destination, "/foo/bar/bat.synapse_download_12345", temp_destination) regex = r'/foo/bar/bat.synapse_download_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' assert_true(re.match(regex, utils.temp_download_filename("/foo/bar/bat", None)))