diff --git a/pyproject.toml b/pyproject.toml index f64382c1fcc..cff98dc01b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ python_files = ["tests*.py", "test_*.py"] filterwarnings = [ "error", "ignore:.*Use timezone-aware objects to represent datetimes in UTC.*:DeprecationWarning:(botocore|django_datadog_logger)", + "ignore:.*The 'strip_cdata' option of HTMLParser\\(\\) has never done anything and will eventually be removed.", ] addopts = [ "--reuse-db", diff --git a/tests/utils/test.py b/tests/utils/test.py index d1434e71e5a..ea2736347f0 100644 --- a/tests/utils/test.py +++ b/tests/utils/test.py @@ -126,6 +126,25 @@ def request(self, **request): # Detect rendering issues in templates assert "{{" not in content assert "{%" not in content + + # Check HTML consistency (use lxml parser for speed) + soup = BeautifulSoup(content, "lxml") + + tag_with_ids = soup.find_all(id=True) + ids = {tag.attrs["id"] for tag in tag_with_ids} + # Check for for duplicate ids + assert len(ids) == len(tag_with_ids) + + for tag in soup.find_all(attrs={"aria-labelledby": True}): + assert tag.attrs["aria-labelledby"] in ids + + for tag in soup.find_all(attrs={"aria-controls": True}): + assert tag.attrs["aria-controls"] in ids + + for tag in soup.find_all(attrs={"data-bs-target": True}): + if tag.attrs["data-bs-target"][0] == "#": + assert tag.attrs["data-bs-target"][1:] in ids + return response