def test_node_merging(self): parent_node = FileTreeNode('123', virtual=False, name='parent', size=1, mime_type='somefile') child_node_folder_1 = FileTreeNode(None, virtual=True, name='folder') child_node_folder_2 = FileTreeNode(None, virtual=True, name='folder') child_node_file_1 = FileTreeNode('abc', virtual=False, name='file_1') child_node_file_2 = FileTreeNode('def', virtual=False, name='file_2') child_node_folder_1.add_child_node(child_node_file_1) child_node_folder_2.add_child_node(child_node_file_2) parent_node.add_child_node(child_node_folder_1) parent_node.add_child_node(child_node_folder_2) assert parent_node.has_children assert len(parent_node.get_list_of_child_nodes()) == 1 assert list( parent_node.children.keys()) == [child_node_folder_1.get_id()] assert child_node_folder_1 in parent_node assert child_node_folder_2 in parent_node assert len(parent_node.children[ child_node_folder_1.get_id()].get_list_of_child_nodes()) == 2 folder_id = child_node_folder_1.get_id() assert child_node_file_1 in parent_node.children[folder_id] assert child_node_file_2 in parent_node.children[folder_id]
def test_node_creation(self): parent_node = FileTreeNode('123', virtual=False, name='parent', size=1, mime_type='somefile') child_node = FileTreeNode('456', root_uid='123', virtual=True, name='child') parent_node.add_child_node(child_node) assert parent_node.uid == '123' assert parent_node.root_uid is None assert child_node.root_uid == '123' assert not parent_node.virtual assert parent_node.size == 1 assert parent_node.type == 'somefile' assert parent_node.has_children assert parent_node.get_list_of_child_nodes() == [child_node] assert parent_node.get_id() == ('parent', False) assert list(parent_node.children.keys()) == [child_node.get_id()] assert parent_node.get_names_of_children() == [child_node.name] assert not child_node.has_children assert child_node in parent_node assert 'Node ' in parent_node.__repr__() assert parent_node != child_node assert parent_node.print_tree() is None
def test_node_merging(self): parent_node = FileTreeNode('123', virtual=False, name='parent', size=1, mime_type='somefile') child_node_folder_1 = FileTreeNode(None, virtual=True, name='folder') child_node_folder_2 = FileTreeNode(None, virtual=True, name='folder') child_node_file_1 = FileTreeNode('abc', virtual=False, name='file_1') child_node_file_2 = FileTreeNode('def', virtual=False, name='file_2') child_node_folder_1.add_child_node(child_node_file_1) child_node_folder_2.add_child_node(child_node_file_2) parent_node.add_child_node(child_node_folder_1) parent_node.add_child_node(child_node_folder_2) self.assertTrue(parent_node.has_children) self.assertEqual(len(parent_node.get_list_of_child_nodes()), 1) self.assertEqual(list(parent_node.children.keys()), [child_node_folder_1.get_id()]) self.assertTrue(child_node_folder_1 in parent_node) self.assertTrue(child_node_folder_2 in parent_node) self.assertEqual( len(parent_node.children[ child_node_folder_1.get_id()].get_list_of_child_nodes()), 2) folder_id = child_node_folder_1.get_id() self.assertTrue(child_node_file_1 in parent_node.children[folder_id]) self.assertTrue(child_node_file_2 in parent_node.children[folder_id])
def test_node_creation(self): parent_node = FileTreeNode('123', virtual=False, name='parent', size=1, mime_type='somefile') child_node = FileTreeNode('456', root_uid='123', virtual=True, name='child') parent_node.add_child_node(child_node) self.assertEqual(parent_node.uid, '123') self.assertEqual(parent_node.root_uid, None) self.assertEqual(child_node.root_uid, '123') self.assertFalse(parent_node.virtual) self.assertEqual(parent_node.size, 1) self.assertEqual(parent_node.type, 'somefile') self.assertTrue(parent_node.has_children) self.assertEqual(parent_node.get_list_of_child_nodes(), [child_node]) self.assertEqual(parent_node.get_id(), ('parent', False)) self.assertEqual(list(parent_node.children.keys()), [child_node.get_id()]) self.assertEqual(parent_node.get_names_of_children(), [child_node.name]) self.assertFalse(child_node.has_children) self.assertTrue(child_node in parent_node) assert 'Node ' in parent_node.__repr__() self.assertNotEqual(parent_node, child_node) assert parent_node.print_tree() is None
def _ajax_get_tree_children(self, uid, root_uid=None, compare_id=None): exclusive_files = self._get_exclusive_files(compare_id, root_uid) children = [] root = FileTreeNode(None) with ConnectTo(FrontEndDbInterface, self._config) as sc: child_uids = sc.get_specific_fields_of_db_entry( uid, {'files_included': 1})['files_included'] for child_uid in child_uids: if not exclusive_files or child_uid in exclusive_files: for node in sc.generate_file_tree_node( child_uid, root_uid, whitelist=exclusive_files): root.add_child_node(node) for child_node in root.get_list_of_child_nodes(): child = self._generate_jstree_node(child_node) children.append(child) return jsonify(children)
def test_node_creation(self): parent_node = FileTreeNode("123", False, "parent", 1, "somefile") child_node = FileTreeNode("456", True, "child") parent_node.add_child_node(child_node) self.assertEqual(parent_node.uid, "123") self.assertFalse(parent_node.virtual) self.assertEqual(parent_node.size, 1) self.assertEqual(parent_node.type, "somefile") self.assertTrue(parent_node.has_children) self.assertEqual(parent_node.get_list_of_child_nodes(), [child_node]) self.assertEqual(parent_node.get_id(), ("parent", False)) self.assertEqual(list(parent_node.children.keys()), [child_node.get_id()]) self.assertEqual(parent_node.get_names_of_children(), [child_node.name]) self.assertFalse(child_node.has_children) self.assertTrue(child_node in parent_node) self.assertTrue(parent_node, FileTreeNode("123", False, "parent", 1, "somefile"))
def test_node_merging(self): parent_node = FileTreeNode("123", False, "parent", 1, "somefile") child_node_folder_1 = FileTreeNode(None, True, "folder") child_node_folder_2 = FileTreeNode(None, True, "folder") child_node_file_1 = FileTreeNode("abc", False, "file_1") child_node_file_2 = FileTreeNode("def", False, "file_2") child_node_folder_1.add_child_node(child_node_file_1) child_node_folder_2.add_child_node(child_node_file_2) parent_node.add_child_node(child_node_folder_1) parent_node.add_child_node(child_node_folder_2) self.assertTrue(parent_node.has_children) self.assertEqual(len(parent_node.get_list_of_child_nodes()), 1) self.assertEqual(list(parent_node.children.keys()), [child_node_folder_1.get_id()]) self.assertTrue(child_node_folder_1 in parent_node) self.assertTrue(child_node_folder_2 in parent_node) self.assertEqual(len(parent_node.children[child_node_folder_1.get_id()].get_list_of_child_nodes()), 2) folder_id = child_node_folder_1.get_id() self.assertTrue(child_node_file_1 in parent_node.children[folder_id]) self.assertTrue(child_node_file_2 in parent_node.children[folder_id])