Skip to content

Commit

Permalink
Add Django 5.1 support and deprecate 3.2 (#50)
Browse files Browse the repository at this point in the history
* test also in Django 5.1, deprecate Django 3.2

* fix for Django 5.1

* fix error in testing: does not have the attribute 'urlopen'

* GitHub testing: fail-fast: false
  • Loading branch information
PetrDlouhy authored Sep 17, 2024
1 parent 24d4e3f commit 8f06748
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
max-parallel: 4
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false

steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[tox]
envlist =
py{38,39,310,311}-dj42-wagtail{52,60,61}
py{310,311,312}-dj50-wagtail{52,60,61}
py{38,39,310,311}-dj42-wagtail{52,61,62}
py{311,312}-dj{50}-wagtail{52,61,62}
py{311,312}-dj{51}-wagtail{61,62}
flake8
isort
black
Expand All @@ -21,9 +22,11 @@ setenv =
deps =
dj42: Django>=4.2,<4.3
dj50: Django>=5.0,<5.1
dj51: Django>=5.1,<5.2
wagtail52: wagtail>=5.2,<5.3
wagtail60: wagtail>=6.0,<6.1
wagtail61: wagtail>=6.1,<6.2
wagtail62: wagtail>=6.2,<6.3
wagtailmain: git+https://github.com/wagtail/wagtail.git@main#egg=Wagtail

install_command = pip install -U {opts} {packages}
Expand Down
4 changes: 2 additions & 2 deletions wagtail_storages/tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.files.storage import get_storage_class
from django.core.files.storage import default_storage
from django.test import TestCase

from storages.backends.s3boto3 import S3Boto3Storage
Expand All @@ -18,7 +18,7 @@ def test_returns_s3_boto_subclass(self):
def test_backend_overrides_settings(self):
private_backend = self.backend_class()

default_backend = get_storage_class()()
default_backend = default_storage.__class__()
self.assertIsInstance(default_backend, S3Boto3Storage)

# Make sure querystring authentication is enabled and custom domain is
Expand Down
2 changes: 1 addition & 1 deletion wagtail_storages/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_call_does_not_fail(self):
call_command("fix_document_acls")

@override_settings(
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage"
STORAGES={"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}}
)
def test_call_fails_when_s3_boto3_storage_not_used(self):
with self.assertRaisesRegex(
Expand Down
10 changes: 5 additions & 5 deletions wagtail_storages/tests/test_signal_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class TestDecorators(TestCase):
@override_settings(
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage"
STORAGES={"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}}
)
def test_skipping_s3_storage_decorator_with_non_s3_storage(self):
mock = MagicMock()
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_cache_purged_for_private_collection(self):
private_collection = CollectionViewRestrictionFactory().collection
DocumentFactory(collection=private_collection)
with mock.patch(
"wagtail.contrib.frontend_cache.backends.urlopen"
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
purge_documents_when_collection_saved_with_restrictions(
sender=private_collection._meta.model, instance=private_collection
Expand All @@ -127,7 +127,7 @@ def test_cache_not_purged_for_public_collection(self):
collection = CollectionFactory()
DocumentFactory.create_batch(10, collection=collection)
with mock.patch(
"wagtail.contrib.frontend_cache.backends.urlopen"
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
purge_documents_when_collection_saved_with_restrictions(
sender=collection._meta.model, instance=collection
Expand Down Expand Up @@ -155,7 +155,7 @@ class TestPurgeDocumentFromCacheWhenSaved(CreateBucket, TestCase):
def test_create_new_document_purges_cache_for_that_url(self):
document = DocumentFactory()
with mock.patch(
"wagtail.contrib.frontend_cache.backends.urlopen"
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
purge_document_from_cache_when_saved(
sender=document._meta.model, instance=document
Expand All @@ -180,7 +180,7 @@ def test_create_new_document_purges_cache_for_that_url(self):
def test_delete_document_purges_cache_for_that_url(self):
document = DocumentFactory()
with mock.patch(
"wagtail.contrib.frontend_cache.backends.urlopen"
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
purge_document_from_cache_when_deleted(
sender=document._meta.model, instance=document
Expand Down
6 changes: 4 additions & 2 deletions wagtail_storages/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

class TestIsS3Boto3StorageUsed(TestCase):
@override_settings(
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage"
STORAGES={"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}}
)
def test_should_return_false_if_not(self):
self.assertIs(is_s3_boto3_storage_used(), False)

@override_settings(DEFAULT_FILE_STORAGE="storages.backends.s3boto3.S3Boto3Storage")
@override_settings(
STORAGES={"default": {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"}}
)
def test_should_return_true_if_yes(self):
self.assertIs(is_s3_boto3_storage_used(), True)

Expand Down
2 changes: 1 addition & 1 deletion wagtail_storages/tests/test_wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@mock_aws
class TestWagtailHooks(CreateBucket, TestCase):
@override_settings(
DEFAULT_FILE_STORAGE="django.core.files.storage.FileSystemStorage"
STORAGES={"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}}
)
def test_non_s3_storage_returns_no_response(self):
# The hook should not return a response if S3 storage is not being
Expand Down
4 changes: 2 additions & 2 deletions wagtail_storages/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from django.conf import settings
from django.core.files.storage import get_storage_class
from django.core.files.storage import default_storage

from wagtail.contrib.frontend_cache.utils import PurgeBatch
from wagtail.documents import get_document_model
Expand Down Expand Up @@ -47,7 +47,7 @@ def build_absolute_urls_for_all_sites_for_path(path):

def is_s3_boto3_storage_used():
return issubclass(
get_storage_class(),
default_storage.__class__,
storages.backends.s3boto3.S3Boto3Storage,
)

Expand Down

0 comments on commit 8f06748

Please sign in to comment.