@@ -0,0 +1,78 @@
|
||||
"""Тесты favicon и прочих вставок в <head>."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from flask import Response, make_response
|
||||
|
||||
from app.html_head_injects import apply_html_head_injects, inject_favicon_html
|
||||
|
||||
|
||||
class HtmlHeadInjectsTests(unittest.TestCase):
|
||||
def test_inject_favicon_into_head(self) -> None:
|
||||
html = "<!DOCTYPE html><html><head><title>x</title></head><body></body></html>"
|
||||
out = inject_favicon_html(html)
|
||||
self.assertIn('rel="icon"', out)
|
||||
self.assertIn('href="/static/favicon.svg"', out)
|
||||
self.assertIn("apple-touch-icon", out)
|
||||
|
||||
def test_inject_favicon_idempotent(self) -> None:
|
||||
html = (
|
||||
'<!DOCTYPE html><html><head>'
|
||||
'<link rel="icon" href="/custom.ico">'
|
||||
"<title>x</title></head><body></body></html>"
|
||||
)
|
||||
out = inject_favicon_html(html)
|
||||
self.assertEqual(out.count('rel="icon"'), 1)
|
||||
self.assertIn("/custom.ico", out)
|
||||
|
||||
def test_apply_on_make_response(self) -> None:
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
html = "<!DOCTYPE html><html><head><title>x</title></head><body></body></html>"
|
||||
with app.app_context():
|
||||
resp = make_response(html)
|
||||
out = apply_html_head_injects(resp, "/login")
|
||||
body = out.get_data(as_text=True)
|
||||
self.assertIn('rel="icon"', body)
|
||||
|
||||
def test_kiosk_cursor_hidden_on_calibration_path(self) -> None:
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config["WESP_KIOSK_HIDE_CURSOR"] = True
|
||||
html = "<!DOCTYPE html><html><head><title>x</title></head><body></body></html>"
|
||||
with app.app_context():
|
||||
resp = make_response(html)
|
||||
out = apply_html_head_injects(resp, "/calibration")
|
||||
body = out.get_data(as_text=True)
|
||||
self.assertIn("kiosk-cursor.css", body)
|
||||
self.assertIn("wesp-kiosk-hide-cursor", body)
|
||||
|
||||
def test_kiosk_cursor_visible_on_scales_path(self) -> None:
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config["WESP_KIOSK_HIDE_CURSOR"] = True
|
||||
html = "<!DOCTYPE html><html><head><title>x</title></head><body></body></html>"
|
||||
with app.app_context():
|
||||
resp = make_response(html)
|
||||
out = apply_html_head_injects(resp, "/scales")
|
||||
body = out.get_data(as_text=True)
|
||||
self.assertNotIn("kiosk-cursor.css", body)
|
||||
self.assertNotIn("wesp-kiosk-hide-cursor", body)
|
||||
|
||||
def test_apply_skips_direct_passthrough(self) -> None:
|
||||
resp = Response(
|
||||
"<!DOCTYPE html><html><head><title>x</title></head><body></body></html>",
|
||||
mimetype="text/html",
|
||||
direct_passthrough=True,
|
||||
)
|
||||
out = apply_html_head_injects(resp, "/login")
|
||||
self.assertIs(out, resp)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user