Skip to content

Commit

Permalink
tests: detect issues with our HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Nov 7, 2024
1 parent cd27ed5 commit a17ba2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions tests/utils/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit a17ba2b

Please sign in to comment.