コード例 #1
0
def create_imagekit_image(file_name="media_test_image", folder="media"):
    config = settings.IMAGE_SERVICES["imagekit"]
    # create new file
    instance = utils.get_instance("imagekit", **config)
    with open(image_file, "rb") as ff:
        img = base64.b64encode(ff.read())
    instance.save(img, file_name=file_name, folder=folder)
    return instance
コード例 #2
0
def test_create_cloudinary_image_file():
    # create new file
    config = settings.IMAGE_SERVICES["cloudinary"]
    instance = utils.get_instance("cloudinary", **config)
    assert not instance.uploaded
    instance.save(image_file, file_name="media_test_image")
    assert instance.uploaded
    assert instance.public_id == "media_test_image"
    # test build url
    url = instance.build_url(width=40, height=40, format="jpg", secure=True)
    assert (
        url
        == f"https://res.cloudinary.com/{config['cloud_name']}/image/upload/h_40,w_40/media_test_image.jpg"
    )
    # delete image
    instance.delete()
    assert not instance.uploaded
コード例 #3
0
def test_imagekit_image_file():
    config = settings.IMAGE_SERVICES["imagekit"]
    # create new file
    instance = utils.get_instance("imagekit", **config)
    assert not instance.uploaded
    assert not instance.public_id
    with open(image_file, "rb") as ff:
        img = base64.b64encode(ff.read())
    instance.save(img, file_name="media_test_image", folder="tests")
    assert instance.uploaded
    assert "tests/media_test_image" in instance.public_id

    # test build url
    url = instance.build_url(width=40, height=40, format="jpg")
    assert (
        url
        == f"https://ik.imagekit.io/{config['cloud_name']}/tr:f-jpg,h-40,w-40/{instance.public_id}"
    )
    # delete image
    instance.delete()
    assert not instance.uploaded
    assert not instance.public_id
コード例 #4
0
def create_cloudinary_image(file_name="media_test_image"):
    config = settings.IMAGE_SERVICES["cloudinary"]
    instance = utils.get_instance("cloudinary", **config)
    instance.save(image_file, public_id=file_name)
    return instance