Ejemplo n.º 1
0
    def test_update_folder_with_subfolders_and_files(self):
        """
        When a Folder name is updated, its own S3 key, along with the S3 keys of its subfolders and files, should be updated
        """
        logging.info('test_update_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()

        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.name = 'f2-edit'
        f2.save()

        self.assertEqual(set(self.get_bucket_contents()), set([
            'media/f1/',
            'media/f1/file1.txt',
            'media/f1/file2.txt',
            'media/f1/f2-edit/',
            'media/f1/f2-edit/file3.txt',
            'media/f1/f2-edit/file4.txt',
            'media/f1/f2-edit/f5/',
            'media/f1/f2-edit/f6/',
            'media/f1/f2-edit/f6/file5.txt',
            'media/f1/f2-edit/f6/file6.txt',
            'media/f1/f2-edit/f6/file7.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.º 2
0
    def test_update_folder_with_files(self):
        """
        When a Folder name is updated, should update the S3 keys of it and all its Files
        """
        logging.info('test_update_folder_with_files')
        f1 = Folder(name='my-folder')
        f1.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=f1)
        file3.file.save('file3.txt', ContentFile('Content'.encode('utf-8')))
        file4 = File(name='file4', parent=f1)
        file4.file.save('file4.txt', ContentFile('Content'.encode('utf-8')))
        file5 = File(name='file5', parent=f1)
        file5.file.save('file5.txt', ContentFile('Content'.encode('utf-8')))
        file6 = File(name='file6', parent=f1)
        file6.file.save('file6.txt', ContentFile('Content'.encode('utf-8')))

        f1.name='my-folder-edit'
        f1.save()

        self.assertEqual(self.get_bucket_contents(), [
            'media/my-folder-edit/',
            'media/my-folder-edit/file1.txt',
            'media/my-folder-edit/file2.txt',
            'media/my-folder-edit/file3.txt',
            'media/my-folder-edit/file4.txt',
            'media/my-folder-edit/file5.txt',
            'media/my-folder-edit/file6.txt',
        ])
Ejemplo n.º 3
0
    def test_update_folder_with_subfolders(self):
        logging.info('test_update_folder_with_subfolders...')
        f1 = Folder(name='test_folder')
        f1.save()
        f2 = Folder(name='subfolder', parent=f1)
        f2.save()
        f1.name = 'test_folder_edit'
        f1.save()

        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/test_folder_edit/', 'media/test_folder_edit/subfolder/'])