Esempio n. 1
0
    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]
Esempio n. 2
0
    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
Esempio n. 3
0
    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])
Esempio n. 4
0
    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
Esempio n. 5
0
    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"))
Esempio n. 6
0
    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])