Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to make test suite run, and update requirements #125

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/wagtail_tag_manager/apps.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .config import WagtailTagManagerConfig

__all__ = ["WagtailTagManagerConfig"]
3 changes: 2 additions & 1 deletion src/wagtail_tag_manager/consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/wagtail_tag_manager/models/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
try:
template = Template(self.content)
template.render(Context())
except Exception as error:
except Exception as error: # noqa

Check warning on line 134 in src/wagtail_tag_manager/models/tags.py

View check run for this annotation

Codecov / codecov/patch

src/wagtail_tag_manager/models/tags.py#L134

Added line #L134 was not covered by tests
raise ValidationError({"content": error})

return self
Expand Down
2 changes: 1 addition & 1 deletion tests/site/pages/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ class Migration(migrations.Migration):
options={
'abstract': False,
},
bases='wagtailcore.page',
bases=('wagtailcore.page',),
),
]
53 changes: 53 additions & 0 deletions tests/site/pages/migrations/0002_taggablecontentpage.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
6 changes: 3 additions & 3 deletions tests/unit/test_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})

Expand All @@ -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"},
Expand All @@ -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(
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) == {
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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()

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)


@pytest.mark.django_db
@pytest.mark.django_db(transaction=True)
def test_wtm_include_necessary(rf, site):
expected_result = '<link href="/static/test.css" rel="stylesheet" type="text/css"/>'

Expand Down Expand Up @@ -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 = '<script src="/static/test.js" type="text/javascript"></script>'

Expand Down Expand Up @@ -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"'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
44 changes: 27 additions & 17 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
[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 =
py37: python3.7
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