From 1a36871cc700c9509da2f7cca2e4222d6cb8470a Mon Sep 17 00:00:00 2001 From: ai-bot Date: Thu, 1 Oct 2026 12:48:28 +0000 Subject: [PATCH] Test dashboard HTTP routes and language --- tests/test_app.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test_app.py diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..482b36c --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,49 @@ +"""HTTP tests for the dashboard server.""" + +from http.server import ThreadingHTTPServer +import json +import threading +import unittest +from urllib.error import HTTPError +from urllib.request import urlopen + +from app import AppHandler + + +class AppHandlerTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.server = ThreadingHTTPServer(("127.0.0.1", 0), AppHandler) + cls.thread = threading.Thread(target=cls.server.serve_forever, daemon=True) + cls.thread.start() + cls.base_url = f"http://127.0.0.1:{cls.server.server_port}" + + @classmethod + def tearDownClass(cls): + cls.server.shutdown() + cls.server.server_close() + cls.thread.join(timeout=2) + + def test_health_endpoint_returns_json(self): + with urlopen(f"{self.base_url}/health") as response: + self.assertEqual(response.status, 200) + self.assertEqual(json.load(response), {"status": "ok"}) + self.assertEqual(response.headers["X-Content-Type-Options"], "nosniff") + + def test_dashboard_is_english(self): + with urlopen(self.base_url) as response: + body = response.read().decode("utf-8") + + self.assertEqual(response.status, 200) + self.assertIn('', body) + self.assertIn("Start annual health check", body) + self.assertNotIn("Ã…rleg", body) + + def test_unknown_path_returns_not_found(self): + with self.assertRaises(HTTPError) as error: + urlopen(f"{self.base_url}/missing") + self.assertEqual(error.exception.code, 404) + + +if __name__ == "__main__": + unittest.main()