def test_get_virtual_file_path(self): fo = FileObject(binary=b'file_object') assert fo.uid in fo.get_virtual_file_paths().keys(), 'not correct if path _ name not set' fo.file_name = 'the_file_name.txt' assert fo.get_virtual_file_paths()[fo.uid][0] == fo.uid, 'not correct if path not set' fo.virtual_file_path = {fo.uid: '/foo/bar/the_file_name.txt'} assert fo.get_virtual_file_paths()[fo.uid] == '/foo/bar/the_file_name.txt', 'not correct if path set'
def _convert_to_file_object(self, entry: dict, analysis_filter: List[str] = None) -> FileObject: file_object = FileObject() file_object.uid = entry['_id'] file_object.size = entry['size'] file_object.file_name = entry['file_name'] file_object.virtual_file_path = entry['virtual_file_path'] file_object.parents = entry['parents'] file_object.processed_analysis = self.retrieve_analysis(entry['processed_analysis'], analysis_filter=analysis_filter) file_object.files_included = set(entry['files_included']) file_object.parent_firmware_uids = set(entry['parent_firmware_uids']) file_object.analysis_tags = entry['analysis_tags'] if 'analysis_tags' in entry else dict() for attribute in ['comments']: # for backwards compatibility if attribute in entry: setattr(file_object, attribute, entry[attribute]) return file_object