Add tests for unique body classes
This commit is contained in:
parent
82f3163ff5
commit
d17b0af9f6
4 changed files with 24 additions and 2 deletions
3
justfile
3
justfile
|
@ -23,3 +23,6 @@ install:
|
|||
|
||||
@collectstatic:
|
||||
./manage.py collectstatic --noinput -v2
|
||||
|
||||
test *ARGS:
|
||||
./manage.py test {{ ARGS }}
|
||||
|
|
|
@ -7,6 +7,7 @@ class BasePage(Page):
|
|||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
def body_class(self):
|
||||
return "page-" + self._meta.db_table.replace("_", "-")
|
||||
def body_class(cls):
|
||||
return "page-" + cls._meta.db_table.replace("_", "-")
|
||||
|
|
12
website/common/tests.py
Normal file
12
website/common/tests.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.test import SimpleTestCase
|
||||
from .utils import get_page_models
|
||||
from .models import BasePage
|
||||
|
||||
class BasePageTestCase(SimpleTestCase):
|
||||
def test_unique_body_classes(self):
|
||||
body_classes = [page.body_class for page in get_page_models()]
|
||||
self.assertEqual(len(body_classes), len(set(body_classes)))
|
||||
|
||||
def test_pages_inherit_base_page(self):
|
||||
for page_model in get_page_models():
|
||||
self.assertTrue(issubclass(page_model, BasePage), f"{page_model} does not inherit from {BasePage}.")
|
6
website/common/utils.py
Normal file
6
website/common/utils.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from wagtail.models import get_page_models as get_wagtail_page_models, Page
|
||||
|
||||
def get_page_models():
|
||||
page_models = get_wagtail_page_models().copy()
|
||||
page_models.remove(Page)
|
||||
return page_models
|
Loading…
Reference in a new issue