Ejemplo n.º 1
0
 def test_get_descendants_many_branches_inc_self_true(self):
     """
     get_all_descendants() should return the correct descendants for a multiple branch tree,
     including the current_folder if include_self is set to true
     """
     f1 = Folder(name='folder1')
     f1.save()
     f2 = Folder(name='folder2', parent=f1)
     f2.save()
     f3 = Folder(name='folder3', parent=f1)
     f3.save()
     f4 = Folder(name='folder4', parent=f1)
     f4.save()
     f5 = Folder(name='folder5', parent=f2)
     f5.save()
     f6 = Folder(name='folder6', parent=f2)
     f6.save()
     f7 = Folder(name='folder7', parent=f3)
     f7.save()
     f8 = Folder(name='folder8', parent=f6)
     f8.save()
     f9 = Folder(name='folder9', parent=f7)
     f9.save()
     f10 = Folder(name='folder10', parent=f7)
     f10.save()
     f11 = Folder(name='folder11', parent=f7)
     f11.save()
     f12 = Folder(name='folder12', parent=f10)
     f12.save()
     self.assertEqual(
         set(f1.get_all_descendants(True)),
         set([f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12]))
     f1.delete()
Ejemplo n.º 2
0
 def test_get_descendants_if_none_exist_inc_self_false(self):
     """
     get_all_descendants() should return empty, if it
     has no children and include_self is set to false
     """
     f1 = Folder(name='folder1')
     f1.save()
     self.assertEqual(f1.get_all_descendants(), [])
     f1.delete()
Ejemplo n.º 3
0
 def test_get_descendants_if_none_exist_inc_self_true(self):
     """
     get_all_descendants() should return the current_folder only, if it
     has no children and include_self is set to true
     """
     f1 = Folder(name='folder1')
     f1.save()
     self.assertEqual(f1.get_all_descendants(True), [f1])
     f1.delete()
Ejemplo n.º 4
0
    def test_delete_folder_with_subfolders_and_files(self):
        """
        When a Folder is deleted, all its subfolders and Files should also be deleted
        """
        logging.info('test_delete_folder_with_subfolders_and_files')
        f1 = Folder(name='f1')
        f1.save()
        f2 = Folder(name='f2', parent=f1)
        f2.save()
        f3 = Folder(name='f3', parent=f1)
        f3.save()
        f4 = Folder(name='f4', parent=f1)
        f4.save()
        f5 = Folder(name='f5', parent=f2)
        f5.save()
        f6 = Folder(name='f6', parent=f2)
        f6.save()
        f7 = Folder(name='f7', parent=f4)
        f7.save()
        f8 = Folder(name='f8', parent=f6)
        f8.save()

        file1 = File(name='file1', parent=f1)
        file1.file.save('file1.txt', ContentFile('Content'.encode('utf-8')))
        file2 = File(name='file2', parent=f1)
        file2.file.save('file2.txt', ContentFile('Content'.encode('utf-8')))
        file3 = File(name='file3', parent=f2)
        file3.file.save('file3.txt', ContentFile('Content'.encode('utf-8')))
        file4 = File(name='file4', parent=f2)
        file4.file.save('file4.txt', ContentFile('Content'.encode('utf-8')))
        file5 = File(name='file5', parent=f6)
        file5.file.save('file5.txt', ContentFile('Content'.encode('utf-8')))
        file6 = File(name='file6', parent=f6)
        file6.file.save('file6.txt', ContentFile('Content'.encode('utf-8')))
        file7 = File(name='file7', parent=f6)
        file7.file.save('file7.txt', ContentFile('Content'.encode('utf-8')))
        file8 = File(name='file8', parent=f7)
        file8.file.save('file8.txt', ContentFile('Content'.encode('utf-8')))
        file9 = File(name='file9', parent=f7)
        file9.file.save('file9.txt', ContentFile('Content'.encode('utf-8')))

        f2.delete()

        self.assertEqual(set(self.get_bucket_contents()), set([
            'media/f1/',
            'media/f1/file1.txt',
            'media/f1/file2.txt',
            'media/f1/f3/',
            'media/f1/f4/',
            'media/f1/f4/f7/',
            'media/f1/f4/f7/file8.txt',
            'media/f1/f4/f7/file9.txt',
        ]))
Ejemplo n.º 5
0
 def test_get_descendants_single_branch_inc_self_true(self):
     """
     get_all_descendants() should return the correct descendants for a single branch tree,
     including the current_folder if include_self is set to true
     """
     f1 = Folder(name='folder1')
     f1.save()
     f2 = Folder(name='folder2', parent=f1)
     f2.save()
     f3 = Folder(name='folder3', parent=f2)
     f3.save()
     self.assertEqual(set(f1.get_all_descendants(True)), set([f1, f2, f3]))
     f1.delete()
Ejemplo n.º 6
0
    def test_delete_folder_with_subfolders(self):
        logging.info('test_delete_folder_with_subfolders...')
        f1 = Folder(name='test_folder')
        f1.save()
        f2 = Folder(name='subfolder', parent=f1)
        f2.save()
        f3 = Folder(name='second_folder')
        f3.save()
        f1.delete()

        bucket_contents = []
        for obj in s3_utils.s3.list_objects(Bucket = s3_utils.bucket)['Contents']:
            bucket_contents.append(obj['Key'])

        self.assertEqual(bucket_contents, ['media/second_folder/'])
Ejemplo n.º 7
0
 def test_get_descendants_single_branch_including_files_inc_self_false(
         self):
     """
     get_all_descendants should return the correct descendants for a single branch tree, including files,
     excluding the current_folder if include_self is set to false
     """
     f1 = Folder(name='folder1')
     f1.save()
     f2 = Folder(name='folder2', parent=f1)
     f2.save()
     f3 = Folder(name='folder3', parent=f2)
     f3.save()
     file1 = File(name='file1', parent=f3)
     file1.save()
     file2 = File(name='file2', parent=f3)
     file2.save()
     self.assertEqual(set(f1.get_all_descendants()),
                      set([f2, f3, file1, file2]))
     f1.delete()
Ejemplo n.º 8
0
    def test_delete_folder_with_files(self):
        """
        When a Folder is deleted, all its Files should also be deleted
        """
        logging.info('test_delete_folder_with_files')
        f1 = Folder(name='f1')
        f1.save()
        f2 = Folder(name='f2', parent=f1)
        f2.save()
        f3 = Folder(name='f3', parent=f1)
        f3.save()

        file1 = File(name='file1', parent=f2)
        file1.file.save('file1.txt', ContentFile('Content'.encode('utf-8')))
        file2 = File(name='file2', parent=f2)
        file2.file.save('file2.txt', ContentFile('Content'.encode('utf-8')))
        file3 = File(name='file3', parent=f2)

        f2.delete()

        self.assertEqual(set(self.get_bucket_contents()), set([
            'media/f1/',
            'media/f1/f3/'
        ]))
Ejemplo n.º 9
0
 def test_get_descendants_many_branch_including_files_inc_self_true(self):
     """
     get_all_descendants should return the correct descendants for a multiple branch tree, including files,
     including the current_folder if include_self is set to true
     """
     f1 = Folder(name='folder1')
     f1.save()
     f2 = Folder(name='folder2', parent=f1)
     f2.save()
     f3 = Folder(name='folder3', parent=f2)
     f3.save()
     f4 = Folder(name='folder4', parent=f1)
     f4.save()
     file1 = File(name='file1', parent=f3)
     file1.save()
     file2 = File(name='file2', parent=f3)
     file2.save()
     file3 = File(name='file3', parent=f4)
     file3.save()
     file4 = File(name='file4', parent=f4)
     file4.save()
     self.assertEqual(set(f1.get_all_descendants(True)),
                      set([f1, f2, f3, f4, file1, file2, file3, file4]))
     f1.delete()