Exemplo n.º 1
0
 def test_move_folder(self):
     acc = self.account
     test_folder = self.test_folder
     folder1 = acc.folders.create(data={
         'parent_id': test_folder.id, 'name': self._rand()})
     folder2 = acc.folders.create(data={
         'parent_id': test_folder.id, 'name': self._rand()})
     self.assertTrue(utils.is_folder_present(folder1.name, test_folder))
     self.assertTrue(utils.is_folder_present(folder2.name, test_folder))
     folder2.parent_id = folder1.id
     folder2.save()
     self.assertFalse(utils.is_folder_present(folder2.name, test_folder))
Exemplo n.º 2
0
    def test_copy_folder(self):
        acc = self.account
        test_folder = self.test_folder

        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id, 'name': self._rand()})
        self.assertTrue(utils.is_folder_present(folder1.name, test_folder))
        folder2 = acc.folders.create(data={
            'parent_id': folder1.id, 'name': self._rand()})
        self.assertTrue(utils.is_folder_present(folder2.name, folder1))

        copy = folder1.copy_folder(parent_id=test_folder.id, name='%s copy' % folder1.name)
        self.assertTrue(utils.is_folder_present(copy.name, test_folder))
        self.assertTrue(utils.is_folder_present(folder1.name, test_folder))
        self.assertTrue(utils.is_folder_present(folder2.name, copy))
Exemplo n.º 3
0
 def test_move_folder(self):
     acc = self.account
     test_folder = self.test_folder
     folder1 = acc.folders.create(data={
         'parent_id': test_folder.id,
         'name': self._rand()
     })
     folder2 = acc.folders.create(data={
         'parent_id': test_folder.id,
         'name': self._rand()
     })
     self.assertTrue(utils.is_folder_present(folder1.name, test_folder))
     self.assertTrue(utils.is_folder_present(folder2.name, test_folder))
     folder2.parent_id = folder1.id
     folder2.save()
     self.assertFalse(utils.is_folder_present(folder2.name, test_folder))
Exemplo n.º 4
0
    def test_copy_folder(self):
        acc = self.account
        test_folder = self.test_folder

        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id,
            'name': self._rand()
        })
        self.assertTrue(utils.is_folder_present(folder1.name, test_folder))
        folder2 = acc.folders.create(data={
            'parent_id': folder1.id,
            'name': self._rand()
        })
        self.assertTrue(utils.is_folder_present(folder2.name, folder1))

        copy = folder1.copy_folder(parent_id=test_folder.id,
                                   name='%s copy' % folder1.name)
        self.assertTrue(utils.is_folder_present(copy.name, test_folder))
        self.assertTrue(utils.is_folder_present(folder1.name, test_folder))
        self.assertTrue(utils.is_folder_present(folder2.name, copy))
Exemplo n.º 5
0
 def test_copy_file(self):
     new_name = 'copied %s' % self.file.name
     folder1 = self.account.folders.create(
         data={'parent_id': self.folder.id,
               'name': 'folder %s' % random.randint(0, 10e10)})
     self.assertTrue(utils.is_folder_present(folder1.name, self.folder))
     new_file = self.file.copy_file(parent_id=folder1.id, name=new_name)
     self.assertTrue(new_file)
     self.assertTrue(new_file.name, new_name)
     self.assertTrue(utils.is_file_present(self.file.name, self.folder))
     self.assertTrue(utils.is_file_present(new_file.name, folder1))
Exemplo n.º 6
0
    def test_retrieve_folder_contents(self):
        acc = self.account
        test_folder = self.test_folder
        contents = test_folder.contents()
        self.assertTrue(hasattr(contents, 'count'))
        self.assertTrue(hasattr(contents, 'page'))
        self.assertTrue(hasattr(contents, 'next_page'))

        new_folder = acc.folders.create(data={
            'parent_id': test_folder.id, 'name': self._rand()})
        self.assertTrue(utils.is_folder_present(new_folder.name, test_folder))
Exemplo n.º 7
0
 def test_move_file(self):
     new_name = 'moved %s' % self.file.name
     folder1 = self.account.folders.create(
         data={'parent_id': self.folder.id,
               'name': 'folder %s' % random.randint(0, 10e10)})
     self.assertTrue(utils.is_folder_present(folder1.name, self.folder))
     self.file.parent_id = folder1.id
     self.file.name = new_name
     self.assertTrue(self.file.name, new_name)
     self.assertTrue(self.file.save())
     self.assertFalse(utils.is_file_present(self.file.name, self.folder))
     self.assertTrue(utils.is_file_present(self.file.name, folder1))
Exemplo n.º 8
0
    def test_retrieve_folder_contents(self):
        acc = self.account
        test_folder = self.test_folder
        contents = test_folder.contents()
        self.assertTrue(hasattr(contents, 'count'))
        self.assertTrue(hasattr(contents, 'page'))
        self.assertTrue(hasattr(contents, 'next_page'))

        new_folder = acc.folders.create(data={
            'parent_id': test_folder.id,
            'name': self._rand()
        })
        self.assertTrue(utils.is_folder_present(new_folder.name, test_folder))
Exemplo n.º 9
0
    def test_delete_folder(self):
        acc = self.account
        test_folder = self.test_folder

        # Test deleting an empty folder
        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id,
            'name': self._rand()
        })
        folder1_name = folder1.name  # Deletion removes the name.
        self.assertTrue(utils.is_folder_present(folder1_name, test_folder))
        folder1.delete()
        self.assertFalse(utils.is_folder_present(folder1_name, test_folder))

        # Same as above with recursive=True
        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id,
            'name': self._rand()
        })
        folder1_name = folder1.name
        self.assertTrue(utils.is_folder_present(folder1_name, test_folder))
        folder1.delete(recursive=True)
        self.assertFalse(utils.is_folder_present(folder1_name, test_folder))

        # Error case: test deleting a non-empty folder without recursive=True
        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id,
            'name': self._rand()
        })
        folder1_name = folder1.name
        self.assertTrue(utils.is_folder_present(folder1_name, test_folder))
        folder2 = acc.folders.create(data={
            'parent_id': folder1.id,
            'name': self._rand()
        })
        folder2_name = folder2.name
        self.assertTrue(utils.is_folder_present(folder2_name, folder1))
        try:
            folder1.delete()
        except:
            pass
        self.assertTrue(utils.is_folder_present(folder2_name, folder1))

        # Test deleting a non-empty folder with recursive=True
        folder1.delete(recursive=True)
        self.assertFalse(utils.is_folder_present(folder1_name, test_folder))
Exemplo n.º 10
0
    def test_create_folder(self):
        acc = self.account
        folder_name = '%s sub-%s' % (self.test_folder.name, self._rand())

        acc.folders.create(data={
            'parent_id': self.test_folder.id, 'name': folder_name})
        self.assertTrue(utils.is_folder_present(folder_name, self.test_folder))

        new_folder = acc.folders.create(
            data={'parent_id': self.test_folder.id, 'name': folder_name},
            params={'conflict_if_exists': 'false'})
        self.assertEqual(new_folder.name, folder_name)

        with self.assertRaises(sdk.exceptions.KloudlessException) as cm:
            acc.folders.create(
                data={'parent_id': self.test_folder.id, 'name': folder_name},
                params={'conflict_if_exists': 'true'})
        self.assertEqual(cm.exception.status, 409)
Exemplo n.º 11
0
    def test_delete_folder(self):
        acc = self.account
        test_folder = self.test_folder

        # Test deleting an empty folder
        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id, 'name': self._rand()})
        folder1_name = folder1.name # Deletion removes the name.
        self.assertTrue(utils.is_folder_present(folder1_name, test_folder))
        folder1.delete()
        self.assertFalse(utils.is_folder_present(folder1_name, test_folder))

        # Same as above with recursive=True
        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id, 'name': self._rand()})
        folder1_name = folder1.name
        self.assertTrue(utils.is_folder_present(folder1_name, test_folder))
        folder1.delete(recursive=True)
        self.assertFalse(utils.is_folder_present(folder1_name, test_folder))

        # Error case: test deleting a non-empty folder without recursive=True
        folder1 = acc.folders.create(data={
            'parent_id': test_folder.id, 'name': self._rand()})
        folder1_name = folder1.name
        self.assertTrue(utils.is_folder_present(folder1_name, test_folder))
        folder2 = acc.folders.create(data={
            'parent_id': folder1.id, 'name': self._rand()})
        folder2_name = folder2.name
        self.assertTrue(utils.is_folder_present(folder2_name, folder1))
        try:
            folder1.delete()
        except:
            pass
        self.assertTrue(utils.is_folder_present(folder2_name, folder1))

        # Test deleting a non-empty folder with recursive=True
        folder1.delete(recursive=True)
        self.assertFalse(utils.is_folder_present(folder1_name, test_folder))
Exemplo n.º 12
0
    def test_create_folder(self):
        acc = self.account
        folder_name = '%s sub-%s' % (self.test_folder.name, self._rand())

        acc.folders.create(data={
            'parent_id': self.test_folder.id,
            'name': folder_name
        })
        self.assertTrue(utils.is_folder_present(folder_name, self.test_folder))

        new_folder = acc.folders.create(data={
            'parent_id': self.test_folder.id,
            'name': folder_name
        },
                                        params={'conflict_if_exists': 'false'})
        self.assertEqual(new_folder.name, folder_name)

        with self.assertRaises(sdk.exceptions.KloudlessException) as cm:
            acc.folders.create(data={
                'parent_id': self.test_folder.id,
                'name': folder_name
            },
                               params={'conflict_if_exists': 'true'})
        self.assertEqual(cm.exception.status, 409)