diff --git a/pyproject.toml b/pyproject.toml index 7aa1bff..4ce97a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ dev = [ "nox[uv]", "pytest", "pytest-cov", + "pytest-django", "pytest-randomly", "pytest-xdist", "ruff", @@ -79,6 +80,7 @@ exclude_lines = [ "if TYPE_CHECKING:", 'def __str__\(self\)\s?\-?\>?\s?\w*\:' ] +fail_under = 100 [tool.coverage.run] branch = true @@ -115,8 +117,9 @@ module = ["tests.*", "wagtail.*"] [tool.pytest.ini_options] addopts = "-n auto --dist loadfile --doctest-modules" +django_find_project = false norecursedirs = ".* bin build dist *.egg htmlcov logs node_modules templates venv" -python_files = "tests.py test_*.py *_tests.py" +python_files = ["tests.py", "test_*.py", "*_tests.py"] pythonpath = "src" testpaths = ["tests"] diff --git a/tests/conftest.py b/tests/conftest.py index 6889a2a..f15874b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,6 +21,16 @@ def pytest_configure(config): TEST_SETTINGS = { "INSTALLED_APPS": [ "wagtail_heroicons", + "django.contrib.auth", + "django.contrib.contenttypes", "wagtail", ], + "STATIC_URL": "/static/", + "TEMPLATES": [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + }, + ], } diff --git a/tests/test_wagtail_hooks.py b/tests/test_wagtail_hooks.py new file mode 100644 index 0000000..9a5c0bd --- /dev/null +++ b/tests/test_wagtail_hooks.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +import itertools + +from django.template.utils import get_app_template_dirs +from wagtail import hooks + + +def test_register_icons(): + icon_hooks = hooks.get_hooks("register_icons") + all_icons = sorted(itertools.chain.from_iterable(hook([]) for hook in icon_hooks)) + + app_template_dirs = get_app_template_dirs("templates") + template_files = [ + str(filepath) for dir_ in app_template_dirs for filepath in dir_.rglob("*") + ] + + assert all(icon in template_files for icon in all_icons)