def test_sha224_MS1_file_hash(self): ''' tests that get_hash() function returns the correct hash for an input filepath (using MS1 filepath here) ''' self.assertTrue(views_helpers.get_hash(self.ms1_file_path), '6106c18f239c260ac6501f97323e606b46ba0bad3bcbf0e22919a097')
def save_new_file(file_obj): ''' Saves a new file (specified by file_obj) to new_file_path by calculating its SHA224 hash and saving as 'SHA224_digest.[file_extension]' Returns new_file_path for new saved file. ''' uploads_dir = app.config['UPLOAD_FOLDER']+'/' tmp_file_path = mkstemp()[1] file_obj.save(tmp_file_path) hash_val = views_helpers.get_hash(tmp_file_path) original_filename = secure_filename(file_obj.filename) new_file_path = uploads_dir+hash_val+original_filename[-4:] shutil.move(tmp_file_path, new_file_path) app.logger.info('Saved uploaded file {} to {}'.format(file_obj.filename, new_file_path)) return new_file_path, original_filename