Skip to content

Commit

Permalink
Add tests for new Django 4.2 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexerson committed Apr 27, 2023
1 parent c309837 commit e86a40b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import django
from django.test import override_settings
import pytest
from imagekit.conf import ImageKitConf, settings


@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) == "tests.utils.CustomStorage"


@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()
assert conf.configure_default_file_storage(None) == "tests.utils.CustomStorage"
5 changes: 5 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from bs4 import BeautifulSoup
from django.core.files import File
from django.core.files.storage import FileSystemStorage
from django.template import Context, Template
from PIL import Image

Expand Down Expand Up @@ -79,6 +80,10 @@ def assert_file_is_truthy(file):
assert bool(file), 'File is not truthy'


class CustomStorage(FileSystemStorage):
pass


class DummyAsyncCacheFileBackend(Simple):
"""
A cache file backend meant to simulate async generation.
Expand Down

0 comments on commit e86a40b

Please sign in to comment.