diff --git a/setup.cfg b/setup.cfg
index 9d595a6..0ae9a1f 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -7,10 +7,9 @@ tag_name = {new_version}
[tool:pytest]
DJANGO_SETTINGS_MODULE = tests.settings
minversion = 3.0
-strict = true
django_find_project = false
testpaths = tests
-python_paths = .
+pythonpath = .
[isort]
line_length = 80
diff --git a/setup.py b/setup.py
index ffbaf18..0cfa82c 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
install_requires = [
- "wagtail>=4.0,<6.0",
+ "wagtail>=4.1,<6.0",
"wagtail_modeladmin>=1.0.0,<1.1.0",
"selenium>=3.141.0,<3.142.0",
]
@@ -12,13 +12,11 @@
"Faker",
"flake8-blind-except",
"flake8-debugger",
- "flake8-imports",
"flake8",
"freezegun",
"pycodestyle",
"pytest-cov",
"pytest-django",
- "pytest-pythonpath",
"pytest-randomly",
"pytest-sugar",
"pytest",
diff --git a/src/wagtail_tag_manager/apps.py b/src/wagtail_tag_manager/apps.py
index 454c913..3481dbd 100644
--- a/src/wagtail_tag_manager/apps.py
+++ b/src/wagtail_tag_manager/apps.py
@@ -1 +1,3 @@
from .config import WagtailTagManagerConfig
+
+__all__ = ["WagtailTagManagerConfig"]
diff --git a/src/wagtail_tag_manager/consent.py b/src/wagtail_tag_manager/consent.py
index 20ca5e6..ddfded2 100644
--- a/src/wagtail_tag_manager/consent.py
+++ b/src/wagtail_tag_manager/consent.py
@@ -131,7 +131,8 @@ def _register_consent(self):
def _has_valid_consent(self, id: str) -> bool:
"""
- This function will check if the CookieConsentSettings have been changed since the last time the user has given consent.
+ This function will check if the CookieConsentSettings have been
+ changed since the last time the user has given consent.
"""
from wagtail_tag_manager.models import CookieConsent
from wagtail_tag_manager.settings import CookieConsentSettings
diff --git a/src/wagtail_tag_manager/models/tags.py b/src/wagtail_tag_manager/models/tags.py
index 7597cfe..4dab9a2 100644
--- a/src/wagtail_tag_manager/models/tags.py
+++ b/src/wagtail_tag_manager/models/tags.py
@@ -131,7 +131,7 @@ def clean(self):
try:
template = Template(self.content)
template.render(Context())
- except Exception as error:
+ except Exception as error: # noqa
raise ValidationError({"content": error})
return self
diff --git a/tests/site/pages/migrations/0001_initial.py b/tests/site/pages/migrations/0001_initial.py
index 3b37243..2b7cdb6 100644
--- a/tests/site/pages/migrations/0001_initial.py
+++ b/tests/site/pages/migrations/0001_initial.py
@@ -26,6 +26,6 @@ class Migration(migrations.Migration):
options={
'abstract': False,
},
- bases='wagtailcore.page',
+ bases=('wagtailcore.page',),
),
]
diff --git a/tests/site/pages/migrations/0002_taggablecontentpage.py b/tests/site/pages/migrations/0002_taggablecontentpage.py
new file mode 100644
index 0000000..7a83a9c
--- /dev/null
+++ b/tests/site/pages/migrations/0002_taggablecontentpage.py
@@ -0,0 +1,53 @@
+# Generated by Django 4.2.9 on 2024-01-25 14:21
+
+from django.db import migrations, models
+import django.db.models.deletion
+import modelcluster.fields
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("wagtail_tag_manager", "0019_cookieconsentsettings"),
+ ("pages", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="TaggableContentPage",
+ fields=[
+ (
+ "contentpage_ptr",
+ models.OneToOneField(
+ auto_created=True,
+ on_delete=django.db.models.deletion.CASCADE,
+ parent_link=True,
+ primary_key=True,
+ serialize=False,
+ to="pages.contentpage",
+ ),
+ ),
+ (
+ "wtm_include_children",
+ models.BooleanField(
+ default=False,
+ help_text="Also include these tags on all children of this page.",
+ verbose_name="Include children",
+ ),
+ ),
+ (
+ "wtm_tags",
+ modelcluster.fields.ParentalManyToManyField(
+ blank=True,
+ help_text="The tags to include when this page is loaded.",
+ related_name="pages",
+ to="wagtail_tag_manager.tag",
+ verbose_name="Tags",
+ ),
+ ),
+ ],
+ options={
+ "abstract": False,
+ },
+ bases=("pages.contentpage", models.Model),
+ ),
+ ]
diff --git a/tests/unit/test_consent.py b/tests/unit/test_consent.py
index b2d7ab8..8ac10d2 100644
--- a/tests/unit/test_consent.py
+++ b/tests/unit/test_consent.py
@@ -6,7 +6,7 @@
from wagtail_tag_manager.consent import ResponseConsent
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_handles_malformed_consent(client, site):
client.cookies = SimpleCookie({"wtm": "malformed"})
@@ -29,7 +29,7 @@ def test_handles_malformed_consent(client, site):
assert consent_state.get("marketing", "") == "false"
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_upgrades_legacy_consent_state(client, site):
client.cookies = SimpleCookie(
{"wtm": "necessary:true|preferences:unset|statistics:pending|marketing:false"},
@@ -54,7 +54,7 @@ def test_upgrades_legacy_consent_state(client, site):
assert consent_state.get("marketing", "") == "false"
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_upgrades_legacy_consent_meta(client, site):
client.cookies = SimpleCookie(
{
diff --git a/tests/unit/test_context_processors.py b/tests/unit/test_context_processors.py
index cbc6c8e..9a83e35 100644
--- a/tests/unit/test_context_processors.py
+++ b/tests/unit/test_context_processors.py
@@ -3,7 +3,7 @@
from wagtail_tag_manager.context_processors import consent_state
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_consent_state(rf, site):
request = rf.get(site.root_page.url)
assert consent_state(request) == {
diff --git a/tests/unit/test_endpoints.py b/tests/unit/test_endpoints.py
index dee39dc..76785e0 100644
--- a/tests/unit/test_endpoints.py
+++ b/tests/unit/test_endpoints.py
@@ -20,7 +20,7 @@
from wagtail_tag_manager.consent import ResponseConsent
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_lazy_endpoint(client, site):
response = client.get("/wtm/lazy/")
assert response.status_code == 400
@@ -37,7 +37,7 @@ def test_lazy_endpoint(client, site):
assert "tags" in data
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_lazy_cookies(client, site):
response = client.post(
"/wtm/lazy/", json.dumps({}), content_type="application/json"
@@ -57,7 +57,7 @@ def test_lazy_cookies(client, site):
assert consent_state.get("marketing", "") == "false"
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_required_lazy_cookies(client, site):
tag_lazy_necessary()
@@ -77,7 +77,7 @@ def test_required_lazy_cookies(client, site):
assert consent_state.get("necessary", "") == "true"
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_initial_lazy_cookies(client, site):
tag_instant_preferences()
tag_lazy_preferences()
@@ -105,7 +105,7 @@ def test_initial_lazy_cookies(client, site):
assert len(data["tags"]) == 2
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_statistics_lazy_cookies(client, site):
tag_instant_statistics()
tag_lazy_statistics()
@@ -128,7 +128,7 @@ def test_statistics_lazy_cookies(client, site):
assert consent_state.get("statistics", "") == "unset"
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_generic_lazy_cookies(client, site):
tag_instant_marketing()
tag_lazy_marketing()
@@ -143,7 +143,7 @@ def test_generic_lazy_cookies(client, site):
assert len(data["tags"]) == 0
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_passive_tags(client, site):
tag_necessary = TagFactory(
name="necessary lazy",
@@ -318,7 +318,7 @@ def test_passive_tags(client, site):
assert 'console.log("marketing: 4")' in data["tags"][1]["string"]
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_page_tags(client, site):
tag_necessary = TagFactory(
name="necessary lazy",
diff --git a/tests/unit/test_forms.py b/tests/unit/test_forms.py
index 0f1d440..f7319e3 100644
--- a/tests/unit/test_forms.py
+++ b/tests/unit/test_forms.py
@@ -26,7 +26,7 @@ def test_consent_form():
assert form.fields["marketing"].initial is False
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_consent_form_initial(rf, site):
request = rf.get(site.root_page.url)
request.COOKIES = {
diff --git a/tests/unit/test_middleware.py b/tests/unit/test_middleware.py
index 2155169..d57c33c 100644
--- a/tests/unit/test_middleware.py
+++ b/tests/unit/test_middleware.py
@@ -14,7 +14,7 @@
from wagtail_tag_manager.models import Tag
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_view_necessary(client, site):
response = client.get(site.root_page.url)
assert response.status_code == 200
@@ -70,7 +70,7 @@ def test_view_necessary(client, site):
assert b'console.log("necessary instant")' in response.content
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_view_preferences(client, site):
tag_instant_preferences(tag_location=Tag.TOP_BODY)
client.cookies = SimpleCookie(
@@ -90,7 +90,7 @@ def test_view_preferences(client, site):
assert b'console.log("preferences instant")' in response.content
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_view_statistics(client, site):
tag_instant_statistics(tag_location=Tag.TOP_BODY)
client.cookies = SimpleCookie(
@@ -110,7 +110,7 @@ def test_view_statistics(client, site):
assert b'console.log("statistics instant")' in response.content
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_view_marketing(client, site):
tag_instant_marketing(tag_location=Tag.BOTTOM_BODY)
client.cookies = SimpleCookie(
@@ -130,7 +130,7 @@ def test_view_marketing(client, site):
assert b'console.log("marketing instant")' in response.content
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_page_tags(client, site):
response = client.get(site.root_page.url)
assert response.status_code == 200
diff --git a/tests/unit/test_templatetags.py b/tests/unit/test_templatetags.py
index 948a519..b06651c 100644
--- a/tests/unit/test_templatetags.py
+++ b/tests/unit/test_templatetags.py
@@ -20,7 +20,7 @@
)
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_wtm_include_necessary(rf, site):
expected_result = ''
@@ -64,7 +64,7 @@ def test_wtm_include_necessary(rf, site):
assert result == expected_result
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_wtm_include_preferences(rf, site):
expected_result = ''
@@ -108,7 +108,7 @@ def test_wtm_include_preferences(rf, site):
assert result == expected_result
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_wtm_include_marketing(rf, site):
token = Token(
token_type=TokenType.TEXT, contents='wtm_include "marketing" "test.html"'
@@ -145,7 +145,7 @@ def test_wtm_include_marketing(rf, site):
node.render(context=make_context({"request": request}))
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_wtm_instant_tags(rf, site):
tag_instant_necessary(tag_location=Tag.TOP_HEAD)
tag_instant_preferences(tag_location=Tag.BOTTOM_HEAD)
@@ -216,7 +216,7 @@ def test_wtm_lazy_manager():
assert "lazy_url" in context.get("config")
-@pytest.mark.django_db
+@pytest.mark.django_db(transaction=True)
def test_wtm_cookie_bar(rf, site):
request = rf.get(site.root_page.url)
context = wtm_cookie_bar(context={"request": request})
diff --git a/tox.ini b/tox.ini
index e2a2936..30d55e8 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,11 @@
[tox]
-envlist = py{37,38,39,310}-django{22,30,31,32,40}-wagtail{211,212,213,214,215,216,30},lint
+envlist =
+ py{37,38,39,310,311}-django{41}-wagtail{41}
+ py{37,38,39,310,311}-django{41}-wagtail{42}
+ py{37,38,39,310,311}-django{41,42}-wagtail{50}
+ py{37,38,39,310,311}-django{41,42}-wagtail{51}
+ py{37,38,39,310,311}-django{41,42,50}-wagtail{52}
+ lint
[testenv]
basepython =
@@ -7,30 +13,34 @@ basepython =
py38: python3.8
py39: python3.9
py310: python3.10
-commands = coverage run --parallel -m pytest -rs {posargs}
+ py311: python3.11
+commands =
+ coverage run --parallel -m pytest -rs {posargs}
+ coverage combine
+usedevelop = true
extras = test
deps =
- django22: django>=2.2,<2.3
- django30: django>=3.0,<3.1
- django31: django>=3.1,<3.2
- django32: django>=3.2,<3.3
- django40: django>=4.0,<4.1
- wagtail211: wagtail>=2.11,<2.12
- wagtail212: wagtail>=2.12,<2.13
- wagtail213: wagtail>=2.13,<2.14
- wagtail214: wagtail>=2.14,<2.15
- wagtail215: wagtail>=2.15,<2.16
- wagtail216: wagtail>=2.16,<2.17
+ django41: django>=4.1,<4.2
+ django50: django>=5.0,<5.1
wagtail30: wagtail>=3.0,<3.1
+ wagtail41: wagtail>=4.1,<4.2
+ wagtail42: wagtail>=4.2,<4.3
+ wagtail50: wagtail>=5.0,<5.1
+ wagtail51: wagtail>=5.1,<5.2
+ wagtail52: wagtail>=5.2,<5.3
+ django-debug-toolbar
[testenv:coverage-report]
-basepython = python3.6
-deps = coverage
+basepython = python3.11
pip_pre = true
skip_install = true
+extras = test
commands =
coverage report --include="src/**/" --omit="src/**/migrations/*.py"
+deps =
+ coverage
[testenv:lint]
-basepython = python3.6
-deps = flake8==3.7.8
+basepython = python3.11
+extras = test
+commands = flake8 src