Skip to content

Commit

Permalink
Merge pull request #560 from Alexerson/django42
Browse files Browse the repository at this point in the history
Upgrade project to latest versions of python and django
  • Loading branch information
vstoykov committed Apr 29, 2023
2 parents 468120f + e86a40b commit 3113ed8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 4 additions & 1 deletion imagekit/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ def configure_cache_timeout(self, value):

def configure_default_file_storage(self, value):
if value is None:
value = settings.DEFAULT_FILE_STORAGE
try:
value = settings.STORAGES["default"]["BACKEND"]
except AttributeError:
value = settings.DEFAULT_FILE_STORAGE
return value
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
16 changes: 10 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
[tox]
envlist =
py{36,37,38,39,310}-django{22,31,32},
py310-djangomain,
py37-django{32}
py38-django{42, 41, 32}
py39-django{42, 41, 32}
py310-django{42, 41, 32}
py311-django{42, 41}
py311-djangomain,
coverage-report

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38
3.9: py39
3.10: py310, coverage-report
3.10: py310
3.11: py311, coverage-report

[testenv]
deps =
-r test-requirements.txt
django22: django~=2.2.0
django31: django~=3.1.0
django32: django~=3.2.0
django41: django~=4.1.0
django42: django~=4.2.0
djangomain: https://github.com/django/django/archive/refs/heads/main.zip

setenv = COVERAGE_FILE=.coverage.{envname}
Expand Down

0 comments on commit 3113ed8

Please sign in to comment.