blob: 690fe860c00cd44bf8fd6cf737672d165c5dc313 (
plain)
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
41
42
43
44
45
46
|
from tools import scrub
RTD_HTML = """<html><head>
<script async src="https://assets.readthedocs.org/static/javascript/readthedocs-addons.js"></script>
<link rel="stylesheet" href="https://docs.vyos.io/en/1.3/_static/css/theme.css"/>
<script>READTHEDOCS_DATA = {"project": "vyos"};</script>
</head><body>
<div id="rtd-footer-container"></div>
<p>content</p>
</body></html>"""
def test_strips_rtd_platform_js_and_containers():
out = scrub.scrub_html(RTD_HTML, slug="1.3")
assert "readthedocs-addons" not in out
assert "READTHEDOCS_DATA" not in out
assert "rtd-footer-container" not in out
assert "<p>content</p>" in out
def test_strips_analytics_ads_and_flyout(tmp_path=None):
html = """<html><head>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-X"></script>
<script>gtag('config', 'G-X');</script>
<script src="https://media.ethicalads.io/media/client/ethicalads.min.js"></script>
</head><body>
<div id="ethical-ad-placement"></div>
<div class="rst-versions" data-toggle="rst-versions">flyout</div>
<p>keep</p></body></html>"""
out = scrub.scrub_html(html, slug="1.2")
assert "googletagmanager" not in out
assert "gtag(" not in out
assert "ethicalads" not in out and "ethical-ad-placement" not in out
assert "rst-versions" not in out
assert "<p>keep</p>" in out
def test_rewrites_absolute_self_urls_to_relative():
out = scrub.scrub_html(RTD_HTML, slug="1.3")
assert 'href="/en/1.3/_static/css/theme.css"' in out
def test_injects_picker_bundle_once():
out = scrub.scrub_html(RTD_HTML, slug="1.3")
assert out.count('js/version-picker.js') == 1
assert 'id="vyos-version-picker"' in out
|