def _register_file(val, size, group_id, metadata, file_list): file_obj = copy.deepcopy(val) file_obj.pop("basename", None) file_obj.pop("nameroot", None) file_obj.pop("nameext", None) uri = file_obj.pop('location', None) checksum = file_obj.pop("checksum", None) try: file_obj_db = FileProcessor.create_file_obj( uri, size, checksum, group_id, metadata) except FileConflictException as e: logger.warning(str(e)) # TODO: Check what to do in case file already exist in DB. file_obj_db = FileProcessor.get_file_obj(uri) FileProcessor.update_file(file_obj_db, file_obj_db.path, metadata) secondary_files = file_obj.pop('secondaryFiles', []) secondary_file_list = [] secondary_files_obj = PortProcessor.process_files( secondary_files, PortAction.REGISTER_OUTPUT_FILES, group_id=group_id, metadata=metadata, file_list=secondary_file_list) if secondary_files_obj: file_obj['secondaryFiles'] = secondary_files_obj file_obj['location'] = FileProcessor.get_bid_from_file(file_obj_db) if file_list is not None: file_list.append('bid://%s' % FileProcessor.get_bid_from_file(file_obj_db)) file_list.extend([f['location'] for f in secondary_files_obj]) return file_obj
def test_create_file_obj_bad_file_group(self): file_group_id = str(uuid.uuid4()) with self.assertRaises(Exception) as context: file_obj = FileProcessor.create_file_obj( "file:///path/to/file.unknown_data_type", 123345, "sha1$calculated checksum", file_group_id, {} ) self.assertTrue("Invalid FileGroup id: %s" % file_group_id in context.exception)
def test_create_file_type_unknown(self): file_obj = FileProcessor.create_file_obj( 'file:///path/to/file.unknown_data_type', 123345, 'sha1$calculated checksum', str(self.file_group.id), {}) self.assertEqual(file_obj.file_type, self.file_type_unknown)
def test_create_file_setting_proper_file_type_based_on_extension(self): file_obj = FileProcessor.create_file_obj( 'file:///path/to/file.fastq.gz', 123345, 'sha1$calculated checksum', str(self.file_group.id), {}) self.assertEqual(file_obj.file_type, self.file_type_fastq)