MQL5-Google-Onedrive/scripts/test_web_dashboard.py
google-labs-jules[bot] 9d93a21039 Bolt: Optimize health check endpoint
💡 What: Separated the /health endpoint from the main dashboard rendering logic. It now returns a lightweight JSON response.
🎯 Why: The previous implementation rendered the full Markdown dashboard for every health check, consuming unnecessary CPU and I/O resources during frequent polling.
📊 Impact: Reduces health check processing time from file reading + markdown parsing (~milliseconds) to a simple JSON return (~microseconds).
🔬 Measurement: Verified with new test script scripts/test_web_dashboard.py and updated render.yaml/app.yaml to use the new endpoint.
2026-01-21 05:17:23 +00:00

38 líneas
1,3 KiB
Python

import unittest
import sys
import os
import json
# Add scripts directory to path so we can import web_dashboard
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from web_dashboard import app
class TestWebDashboard(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
self.app.testing = True
def test_dashboard_route(self):
"""Test that the root route returns HTML."""
response = self.app.get('/')
self.assertEqual(response.status_code, 200)
self.assertIn(b'<!DOCTYPE html>', response.data)
self.assertIn(b'MQL5 Trading Automation Dashboard', response.data)
def test_health_route_json(self):
"""Test that the health route returns a JSON response."""
response = self.app.get('/health')
self.assertEqual(response.status_code, 200)
# This is what we expect AFTER the optimization.
# For TDD, this test will fail initially if I ran it now against the current code
# (because current code returns HTML for /health).
try:
data = json.loads(response.data)
self.assertEqual(data.get('status'), 'healthy')
except json.JSONDecodeError:
self.fail("Response is not valid JSON")
if __name__ == '__main__':
unittest.main()