Example #1
0
    def test_list_object_names(self):
        """Test the `list_object_names` method."""
        node = Node()
        node.put_object_from_tree(self.tempdir, '')

        self.assertEqual(sorted(node.list_object_names()), ['c.txt', 'subdir'])
        self.assertEqual(sorted(node.list_object_names('subdir')), ['a.txt', 'b.txt', 'nested'])
Example #2
0
    def test_erase_unstored(self):
        """
        Test that _repository.erase removes the content of an unstored
        node.
        """
        node = Node()
        node.put_object_from_tree(self.tempdir, '')

        self.assertEqual(sorted(node.list_object_names()), ['c.txt', 'subdir'])
        self.assertEqual(sorted(node.list_object_names('subdir')),
                         ['a.txt', 'b.txt', 'nested'])

        node._repository.erase()  # pylint: disable=protected-access
        self.assertEqual(node.list_object_names(), [])
Example #3
0
    def test_get_object(self):
        """Test the `get_object` method."""
        node = Node()
        node.put_object_from_tree(self.tempdir, '')

        self.assertEqual(node.get_object('c.txt'), File('c.txt', FileType.FILE))
        self.assertEqual(node.get_object('subdir'), File('subdir', FileType.DIRECTORY))
        self.assertEqual(node.get_object('subdir/a.txt'), File('a.txt', FileType.FILE))
        self.assertEqual(node.get_object('subdir/nested'), File('nested', FileType.DIRECTORY))

        with self.assertRaises(IOError):
            node.get_object('subdir/not_existant')

        with self.assertRaises(IOError):
            node.get_object('subdir/not_existant.dat')
Example #4
0
    def test_put_object_from_tree(self):
        """Test the `put_object_from_tree` method."""
        basepath = ''
        node = Node()
        node.put_object_from_tree(self.tempdir, basepath)

        key = os.path.join('subdir', 'a.txt')
        content = self.get_file_content(key)
        self.assertEqual(node.get_object_content(key), content)

        basepath = 'base'
        node = Node()
        node.put_object_from_tree(self.tempdir, basepath)

        key = os.path.join(basepath, 'subdir', 'a.txt')
        content = self.get_file_content(os.path.join('subdir', 'a.txt'))
        self.assertEqual(node.get_object_content(key), content)

        basepath = 'base/further/nested'
        node = Node()
        node.put_object_from_tree(self.tempdir, basepath)

        key = os.path.join(basepath, 'subdir', 'a.txt')
        content = self.get_file_content(os.path.join('subdir', 'a.txt'))
        self.assertEqual(node.get_object_content(key), content)