test_s2_status_ui.py
2.26 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
65
66
67
68
69
70
71
72
"""S2 RED/GREEN: Test learn_detail.html status dropdown"""
import requests, sys
BASE = "http://127.0.0.1:5000"
errors = []
def check(label, ok, detail=""):
if not ok:
errors.append(f"FAIL: {label}: {detail}")
print(f" ❌ {label}: {detail}")
else:
print(f" ✅ {label}")
print("=== S2: learn_detail.html status dropdown ===")
# Get a learn item
r = requests.get(f"{BASE}/api/learn-queue?status=pending_review")
items = (r.json().get("data", []) or [])
if not items:
for s in ["pending_learn", "applied", "approved", "failed"]:
r = requests.get(f"{BASE}/api/learn-queue?status={s}")
items = (r.json().get("data", []) or [])
if items:
break
if not items:
print("⚠️ No learn items found, skipping frontend test")
sys.exit(0)
test_id = items[0]["id"]
print(f"Using learn item id={test_id}")
# Get the detail page
r = requests.get(f"{BASE}/learn/{test_id}")
html = r.text
check("HTTP 200", r.status_code == 200, f"Got {r.status_code}")
# TC4: Status dropdown exists
check("Status dropdown exists", 'status-select' in html,
"No status-select element found")
# TC5: No JS escape errors
check("No triple backslash escape", '\\\\\\' not in html and '\\\\\\\\' not in html,
"Found backslash escape issue")
check("No Jinja2 template literal quote bug", 'data-action=\\"' not in html,
"Found escaped quotes in template literal")
check("No style backslash", "style=\\\\" not in html,
"Found style backslash bug")
# TC6: Status options include valid values
for status_label in ["待审核", "待学习", "已吸收", "已通过", "失败", "已拒绝"]:
check(f"Option: {status_label}", status_label in html,
f"Missing status option: {status_label}")
# Verify the PUT endpoint still works with the actual ID from the page
print(f"\nVerifying backend compatibility...")
r2 = requests.put(
f"{BASE}/api/learn/{test_id}/status",
json={"status": "pending_review"},
headers={"Content-Type": "application/json"}
)
check("Backend PUT still works", r2.status_code == 200,
f"Got {r2.status_code}: {r2.text[:200]}")
print(f"\n=== Results: {len(errors)} failures ===")
if errors:
print("\n".join(errors))
sys.exit(1)
else:
print("ALL TESTS PASSED ✅")
sys.exit(0)