1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
import django
from django.test import override_settings
import pytest
from imagekit.conf import ImageKitConf, settings
from imagekit.utils import get_storage
@pytest.mark.skipif(
django.VERSION < (4, 2),
reason="STORAGES was introduced in Django 4.2",
)
def test_custom_storages():
with override_settings(
STORAGES={
"default": {
"BACKEND": "tests.utils.CustomStorage",
}
},
):
conf = ImageKitConf()
assert conf.configure_default_file_storage(None) == "default"
@pytest.mark.skipif(
django.VERSION >= (5, 1),
reason="DEFAULT_FILE_STORAGE is removed in Django 5.1.",
)
def test_custom_default_file_storage():
with override_settings(DEFAULT_FILE_STORAGE="tests.utils.CustomStorage"):
# If we don’t remove this, Django 4.2 will keep the old value.
del settings.STORAGES
conf = ImageKitConf()
if django.VERSION >= (4, 2):
assert conf.configure_default_file_storage(None) == "default"
else:
assert (
conf.configure_default_file_storage(None) == "tests.utils.CustomStorage"
)
def test_get_storage_default():
from django.core.files.storage import FileSystemStorage
assert isinstance(get_storage(), FileSystemStorage)
@pytest.mark.skipif(
django.VERSION >= (5, 1),
reason="DEFAULT_FILE_STORAGE is removed in Django 5.1.",
)
def test_get_storage_custom_path():
from tests.utils import CustomStorage
with override_settings(IMAGEKIT_DEFAULT_FILE_STORAGE="tests.utils.CustomStorage"):
assert isinstance(get_storage(), CustomStorage)
@pytest.mark.skipif(
django.VERSION < (4, 2),
reason="STORAGES was introduced in Django 4.2",
)
def test_get_storage_custom_key():
from tests.utils import CustomStorage
with override_settings(
STORAGES={
"custom": {
"BACKEND": "tests.utils.CustomStorage",
}
},
IMAGEKIT_DEFAULT_FILE_STORAGE="custom",
):
assert isinstance(get_storage(), CustomStorage)
|