summaryrefslogtreecommitdiff
path: root/tools/test_scrub.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test_scrub.py')
-rw-r--r--tools/test_scrub.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/test_scrub.py b/tools/test_scrub.py
new file mode 100644
index 0000000..690fe86
--- /dev/null
+++ b/tools/test_scrub.py
@@ -0,0 +1,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