File size: 1,461 Bytes
66ee87e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6012dcc
66ee87e
6012dcc
 
66ee87e
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""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()