Skip to content

Commit

Permalink
Deprecate Django < 4.2 and fix old mock paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tm-kn committed Sep 17, 2024
1 parent 8f06748 commit 305c80e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers =
Framework :: Django
Framework :: Django :: 4.2
Framework :: Django :: 5.0
Framework :: Django :: 5.1
Framework :: Wagtail
Framework :: Wagtail :: 5
Framework :: Wagtail :: 6
Expand All @@ -33,6 +34,7 @@ keywords =
[options]
packages = find:
install_requires =
Django >=4.2
Wagtail >=5.2
django-storages[boto3] <2
python_requires = >=3.8
Expand Down
14 changes: 10 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[tox]
skipsdist = True
usedevelop = True
envlist =
py{38,39,310,311}-dj42-wagtail{52,61,62}
py{311,312}-dj{50}-wagtail{52,61,62}
Expand Down Expand Up @@ -29,27 +31,31 @@ deps =
wagtail62: wagtail>=6.2,<6.3
wagtailmain: git+https://github.com/wagtail/wagtail.git@main#egg=Wagtail

install_command = pip install -U {opts} {packages}
install_command = pip install -e ".[testing]" -U {opts} {packages}
commands =
coverage run --source="{toxinidir}/wagtail_storages" -m django test wagtail_storages
django-admin check
django-admin makemigrations --check --noinput
coverage report -m --omit="{toxinidir}/wagtail_storages/tests/*" --fail-under=80
extras = testing

[testenv:black]
basepython = python3
deps =
black
commands =
black --check ./

[testenv:flake8]
basepython = python3
deps =
flake8
commands =
flake8 wagtail_storages

[testenv:isort]
basepython = python3
usedevelop = false
deps =
isort
changedir = {toxinidir}
commands =
isort --recursive --check-only --diff wagtail_storages
isort --check-only --diff wagtail_storages
23 changes: 11 additions & 12 deletions wagtail_storages/tests/test_signal_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.db.models.signals import post_save
from django.test import TestCase, override_settings

import wagtail

import factory
from moto import mock_aws

Expand All @@ -23,6 +25,11 @@
from wagtail_storages.tests.base import CreateBucket
from wagtail_storages.tests.utils import is_s3_object_is_public

URLOPEN_PATH = "wagtail.contrib.frontend_cache.backends.http.urlopen"

if wagtail.VERSION < (6, 2):
URLOPEN_PATH = "wagtail.contrib.frontend_cache.backends.urlopen"


class TestDecorators(TestCase):
@override_settings(
Expand Down Expand Up @@ -100,9 +107,7 @@ class TestPurgeDocumentsWhenCollectionSavedWithRestrictions(CreateBucket, TestCa
def test_cache_purged_for_private_collection(self):
private_collection = CollectionViewRestrictionFactory().collection
DocumentFactory(collection=private_collection)
with mock.patch(
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
with mock.patch(URLOPEN_PATH) as urlopen_mock:
purge_documents_when_collection_saved_with_restrictions(
sender=private_collection._meta.model, instance=private_collection
)
Expand All @@ -126,9 +131,7 @@ def test_cache_purged_for_private_collection(self):
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.http.urlopen"
) as urlopen_mock:
with mock.patch(URLOPEN_PATH) as urlopen_mock:
purge_documents_when_collection_saved_with_restrictions(
sender=collection._meta.model, instance=collection
)
Expand All @@ -154,9 +157,7 @@ class TestPurgeDocumentFromCacheWhenSaved(CreateBucket, TestCase):
@factory.django.mute_signals(post_save)
def test_create_new_document_purges_cache_for_that_url(self):
document = DocumentFactory()
with mock.patch(
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
with mock.patch(URLOPEN_PATH) as urlopen_mock:
purge_document_from_cache_when_saved(
sender=document._meta.model, instance=document
)
Expand All @@ -179,9 +180,7 @@ def test_create_new_document_purges_cache_for_that_url(self):
@factory.django.mute_signals(post_save)
def test_delete_document_purges_cache_for_that_url(self):
document = DocumentFactory()
with mock.patch(
"wagtail.contrib.frontend_cache.backends.http.urlopen"
) as urlopen_mock:
with mock.patch(URLOPEN_PATH) as urlopen_mock:
purge_document_from_cache_when_deleted(
sender=document._meta.model, instance=document
)
Expand Down

0 comments on commit 305c80e

Please sign in to comment.