"""真实 HTTP 启动检查: 等待端口 -> 登录 -> 看板渲染""" import urllib.request, urllib.parse, http.cookiejar, time, sys BASE = "http://127.0.0.1:8080" cj = http.cookiejar.CookieJar() op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) def get(path): return op.open(BASE + path, timeout=5).read().decode("utf-8", "ignore") # 等待服务起来 for i in range(20): try: html = get("/login") if "物料入库系统" in html: print("[OK] 服务已启动, 登录页正常") break except Exception: time.sleep(0.5) else: print("[FAIL] 服务未在 10s 内就绪") sys.exit(1) # 登录 data = urllib.parse.urlencode({"username": "admin", "password": "admin123"}).encode() op.open(urllib.request.Request(BASE + "/login", data=data, method="POST")) html = get("/dashboard") assert "库存看板" in html, "看板未渲染" print("[OK] 登录后看板渲染正常") # 物料页 html = get("/materials") assert "物料" in html print("[OK] 物料页渲染正常") # 入库页 html = get("/inbound") assert "入库登记" in html print("[OK] 入库页渲染正常") print("\n真实服务冒烟通过 ✅")