Ejemplo n.º 1
0
    def test_upload_large(self):
        """ should support uploading large files """
        with tempfile.NamedTemporaryFile() as temp_file:
            populate_large_file(temp_file, LARGE_FILE_SIZE)
            temp_file_name = temp_file.name

            self.assertEqual(LARGE_FILE_SIZE, os.path.getsize(temp_file_name))

            resource = uploader.upload_large(temp_file_name, chunk_size=LARGE_CHUNK_SIZE,
                                             tags=["upload_large_tag", UNIQUE_TAG])

            self.assertEqual(resource["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource["resource_type"], "raw")

            resource2 = uploader.upload_large(temp_file_name, chunk_size=LARGE_CHUNK_SIZE,
                                              tags=["upload_large_tag", UNIQUE_TAG], resource_type="image")

            self.assertEqual(resource2["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource2["resource_type"], "image")
            self.assertEqual(resource2["width"], LARGE_FILE_WIDTH)
            self.assertEqual(resource2["height"], LARGE_FILE_HEIGHT)

            resource3 = uploader.upload_large(temp_file_name, chunk_size=LARGE_FILE_SIZE,
                                              tags=["upload_large_tag", UNIQUE_TAG])

            self.assertEqual(resource3["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource3["resource_type"], "raw")
Ejemplo n.º 2
0
    def test_upload_large(self):
        """ should support uploading large files """
        filename = UNIQUE_ID + "_cld_upload_large"
        with tempfile.NamedTemporaryFile(prefix=filename, suffix='.bmp') as temp_file:
            populate_large_file(temp_file, LARGE_FILE_SIZE)
            temp_file_name = temp_file.name
            temp_file_filename = os.path.splitext(os.path.basename(temp_file_name))[0]

            self.assertEqual(LARGE_FILE_SIZE, os.path.getsize(temp_file_name))

            resource = uploader.upload_large(temp_file_name, chunk_size=LARGE_CHUNK_SIZE,
                                             tags=["upload_large_tag", UNIQUE_TAG])

            self.assertEqual(resource["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource["resource_type"], "raw")
            self.assertEqual(resource["original_filename"], temp_file_filename)

            resource2 = uploader.upload_large(temp_file_name, chunk_size=LARGE_CHUNK_SIZE,
                                              tags=["upload_large_tag", UNIQUE_TAG], resource_type="image",
                                              use_filename=True, unique_filename=False, filename=filename)

            self.assertEqual(resource2["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource2["resource_type"], "image")
            self.assertEqual(resource2["original_filename"], filename)
            self.assertEqual(resource2["original_filename"], resource2["public_id"])
            self.assertEqual(resource2["width"], LARGE_FILE_WIDTH)
            self.assertEqual(resource2["height"], LARGE_FILE_HEIGHT)

            resource3 = uploader.upload_large(temp_file_name, chunk_size=LARGE_FILE_SIZE,
                                              tags=["upload_large_tag", UNIQUE_TAG])

            self.assertEqual(resource3["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource3["resource_type"], "raw")
Ejemplo n.º 3
0
    def test_upload_large_file_io(self):
        """Should support uploading large streams"""
        with io.BytesIO() as temp_file:
            populate_large_file(temp_file, LARGE_FILE_SIZE)
            resource = uploader.upload_large(temp_file, chunk_size=LARGE_CHUNK_SIZE,
                                             tags=["upload_large_tag", UNIQUE_TAG], resource_type="image")

            self.assertEqual(resource["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource["resource_type"], "image")
            self.assertEqual(resource["width"], LARGE_FILE_WIDTH)
            self.assertEqual(resource["height"], LARGE_FILE_HEIGHT)
Ejemplo n.º 4
0
    def test_upload_large_file_io(self):
        """Should support uploading large streams"""
        with io.BytesIO() as temp_file:
            populate_large_file(temp_file, LARGE_FILE_SIZE)
            resource = uploader.upload_large(temp_file, chunk_size=LARGE_CHUNK_SIZE,
                                             tags=["upload_large_tag", UNIQUE_TAG], resource_type="image")

            self.assertEqual(resource["tags"], ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource["resource_type"], "image")
            self.assertEqual(resource["width"], LARGE_FILE_WIDTH)
            self.assertEqual(resource["height"], LARGE_FILE_HEIGHT)
Ejemplo n.º 5
0
    def test_upload_large(self):
        """ should support uploading large files """
        filename = UNIQUE_ID + "_cld_upload_large"
        with tempfile.NamedTemporaryFile(prefix=filename,
                                         suffix='.bmp') as temp_file:
            populate_large_file(temp_file, LARGE_FILE_SIZE)
            temp_file_name = temp_file.name
            temp_file_filename = os.path.splitext(
                os.path.basename(temp_file_name))[0]

            self.assertEqual(LARGE_FILE_SIZE, os.path.getsize(temp_file_name))

            resource = uploader.upload_large(
                temp_file_name,
                chunk_size=LARGE_CHUNK_SIZE,
                tags=["upload_large_tag", UNIQUE_TAG])

            self.assertEqual(resource["tags"],
                             ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource["resource_type"], "raw")
            self.assertEqual(resource["original_filename"], temp_file_filename)

            resource2 = uploader.upload_large(
                temp_file_name,
                chunk_size=LARGE_CHUNK_SIZE,
                tags=["upload_large_tag", UNIQUE_TAG],
                resource_type="image",
                use_filename=True,
                unique_filename=False,
                filename=filename)

            self.assertEqual(resource2["tags"],
                             ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource2["resource_type"], "image")
            self.assertEqual(resource2["original_filename"], filename)
            self.assertEqual(resource2["original_filename"],
                             resource2["public_id"])
            self.assertEqual(resource2["width"], LARGE_FILE_WIDTH)
            self.assertEqual(resource2["height"], LARGE_FILE_HEIGHT)

            resource3 = uploader.upload_large(
                temp_file_name,
                chunk_size=LARGE_FILE_SIZE,
                tags=["upload_large_tag", UNIQUE_TAG])

            self.assertEqual(resource3["tags"],
                             ["upload_large_tag", UNIQUE_TAG])
            self.assertEqual(resource3["resource_type"], "raw")