Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: détection automatique d'incohérence d'id dans notre HTML #5055

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions tests/utils/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ def request(self, **request):
# Detect rendering issues in templates
assert "{{" not in content
assert "{%" not in content

if request.get("HTTP_HX_REQUEST") != "true": # Do not check htmx requests that contain partial documents
# 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
Loading