DecisionLab / tests /test_links.py
Michael Stattelman
Add application file
6012dcc
Raw History Blame Contribute Delete
1.46 kB
"""Every link to another site opens in a new tab, safely (operator ruling 2026-09-28)."""
import re
import unittest
from pathlib import Path
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
ANCHOR = re.compile(r"<a\s[^>]*>", re.I)
def external_anchors(text):
return [a for a in ANCHOR.findall(text) if re.search(r'href="(https?:|\$\{)', a) and "#" not in a.split('href="')[1][:1]]
class ExternalLinksTest(unittest.TestCase):
def check(self, name):
anchors = external_anchors((STATIC / name).read_text(encoding="utf-8"))
self.assertTrue(anchors, f"{name} has no external links to check")
for a in anchors:
with self.subTest(file=name, anchor=a[:80]):
self.assertIn('target="_blank"', a)
self.assertIn('rel="noopener noreferrer"', a)
def test_page_links(self):
self.check("index.html")
def test_links_the_script_builds(self):
self.check("app.js")
def test_page_credits_the_hub_models(self):
html = (STATIC / "index.html").read_text(encoding="utf-8")
for repo in ("Falconsai/LightDec_Arthur", "Falconsai/LightDec_V2", "yasserrmd/enterprise-reflux-laya-v21",
"convaiinnovations/laya"):
with self.subTest(repo=repo):
self.assertIn(f'href="https://huggingface.co/{repo}"', html)
self.assertNotIn("laya-v796", html)
if __name__ == "__main__":
unittest.main()