Skip to content

Commit

Permalink
add test for wagtail hook icon registration (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas authored Mar 23, 2024
1 parent 1d8d4b3 commit 359ecf3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dev = [
"nox[uv]",
"pytest",
"pytest-cov",
"pytest-django",
"pytest-randomly",
"pytest-xdist",
"ruff",
Expand Down Expand Up @@ -79,6 +80,7 @@ exclude_lines = [
"if TYPE_CHECKING:",
'def __str__\(self\)\s?\-?\>?\s?\w*\:'
]
fail_under = 100

[tool.coverage.run]
branch = true
Expand Down Expand Up @@ -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"]

Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
}
18 changes: 18 additions & 0 deletions tests/test_wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 359ecf3

Please sign in to comment.