51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
"""Тесты подсказок «не переводить» для страниц киоска."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from flask import Response
|
|
|
|
from app.kiosk_page_hints import (
|
|
apply_kiosk_translate_hints,
|
|
inject_no_translate_html,
|
|
is_kiosk_cursor_hidden_path,
|
|
is_kiosk_html_path,
|
|
)
|
|
|
|
|
|
class KioskPageHintsTests(unittest.TestCase):
|
|
def test_paths(self) -> None:
|
|
self.assertTrue(is_kiosk_html_path("/scales"))
|
|
self.assertTrue(is_kiosk_html_path("/starting"))
|
|
self.assertFalse(is_kiosk_html_path("/login"))
|
|
|
|
def test_cursor_hidden_except_scales(self) -> None:
|
|
self.assertFalse(is_kiosk_cursor_hidden_path("/scales"))
|
|
self.assertTrue(is_kiosk_cursor_hidden_path("/starting"))
|
|
self.assertTrue(is_kiosk_cursor_hidden_path("/calibration"))
|
|
self.assertFalse(is_kiosk_cursor_hidden_path("/login"))
|
|
|
|
def test_apply_hints_passthrough_response(self) -> None:
|
|
resp = Response(
|
|
"<html><body></body></html>",
|
|
mimetype="text/html",
|
|
direct_passthrough=True,
|
|
)
|
|
out = apply_kiosk_translate_hints(resp, "/starting")
|
|
self.assertIs(out, resp)
|
|
self.assertEqual(out.headers.get("Content-Language"), "ru")
|
|
self.assertEqual(out.headers.get("Google-Translate"), "no")
|
|
self.assertTrue(getattr(out, "direct_passthrough", False))
|
|
|
|
def test_inject_meta_and_html_attrs(self) -> None:
|
|
html = "<!DOCTYPE html><html lang='ru'><head><title>x</title></head><body></body></html>"
|
|
out = inject_no_translate_html(html)
|
|
self.assertIn('content="notranslate"', out)
|
|
self.assertIn('translate="no"', out)
|
|
self.assertIn("notranslate", out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|