test_dashboard_page.py
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Test /dashboard page rendering and structure"""
import pytest
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app import app as flask_app
@pytest.fixture
def client():
flask_app.config['TESTING'] = True
with flask_app.test_client() as c:
yield c
def test_dashboard_page_returns_200(client):
"""Dashboard page serves HTTP 200"""
r = client.get('/dashboard')
assert r.status_code == 200
def test_dashboard_page_has_title(client):
"""Dashboard page contains expected title"""
r = client.get('/dashboard')
html = r.data.decode('utf-8')
assert '数据看板' in html, "Missing 数据看板 title"
def test_dashboard_page_has_fetch(client):
"""Dashboard page JS fetches /api/dashboard"""
r = client.get('/dashboard')
html = r.data.decode('utf-8')
assert '/api/dashboard' in html, "Missing /api/dashboard API call"
def test_dashboard_page_no_style_backslash_bug(client):
"""Dashboard page has no style=\\\\\\\\' escaping bug"""
r = client.get('/dashboard')
html = r.data.decode('utf-8')
# Check for the known-common escaping bug patterns
assert "style=\\\\\\\\'" not in html, "STYLE BACKSLASH BUG in dashboard.html"
assert "style=\\\\\\\\\\\\'" not in html, "STYLE TRIPLE BACKSLASH BUG in dashboard.html"
def test_dashboard_page_has_auto_refresh(client):
"""Dashboard page auto-refreshes (setInterval or similar)"""
r = client.get('/dashboard')
html = r.data.decode('utf-8')
assert 'setInterval' in html or 'setTimeout' in html, \
"Missing auto-refresh mechanism"
def test_dashboard_page_has_card_elements(client):
"""Dashboard page has card containers for modules"""
r = client.get('/dashboard')
html = r.data.decode('utf-8')
# Should have card-like structure
assert 'dashboard' in html.lower(), "Missing dashboard identifier"
if __name__ == '__main__':
pytest.main([__file__, '-v'])