"""S02 web flow test (2026-10-15): upload the 3 Ungok P1 DWG, the page must rank 운곡교P1형 first with 3/3; create a pier from the recommendation; the staged drawings move into the pier and pier.json keeps the six answers. Uses a temp data dir (no Rhino).""" import json import os import re import shutil import sys import tempfile from pathlib import Path APP = Path(__file__).resolve().parents[1] TD = Path(tempfile.mkdtemp(prefix="recweb_")) shutil.copytree(APP / "data" / "_템플릿", TD / "_템플릿", ignore=shutil.ignore_patterns("_이전")) os.environ["PIERAPP_DATA"] = str(TD) sys.path.insert(0, str(APP / "web")) sys.path.insert(0, str(APP)) import app as webapp # noqa: E402 ok = True def check(name, cond, detail=""): global ok ok &= bool(cond) print("PASS" if cond else "FAIL", name, str(detail)[:300], flush=True) dwgs = sorted((APP.parents[1] / "RAG").glob("C0050205-02[567]-*.dwg")) check("3 Ungok DWG found", len(dwgs) == 3, dwgs) c = webapp.app.test_client() r = c.post("/recommend", data={"dwg": [(open(p, "rb"), p.name) for p in dwgs]}, content_type="multipart/form-data") html = r.get_data(as_text=True) check("recommend page 200", r.status_code == 200, r.status_code) rows = re.findall(r"(\d)([^<]+)(\d) / (\d)", html) check("rank 1 = 운곡교P1형, 3/3", rows and rows[0][1] == "운곡교P1형" and rows[0][2] == rows[0][3] == "3", rows[:2]) check("others rank lower", all(int(a) < 3 for _, _, a, _ in rows[1:]), rows) sid = re.search(r"/recommend/(\w+)/create", html).group(1) staged = TD / "_추천" / sid check("staged drawings exist", (staged / "texts.json").exists()) r = c.post(f"/recommend/{sid}/create", data={"name": "시험교각", "type": "T형", "template": "tpl:운곡교P1형", "ans_foundation": "기초판+말뚝", "ans_soffit": "곡선", "ans_bearings": "10", "ans_rebar_shape": "예", "ans_rebar_method": "미확인"}) check("create redirects to the pier", r.status_code == 302 and "/pier/" in r.headers["Location"], r.status_code) P = TD / "시험교각" check("drawings moved into the pier, staging removed", (P / "drawings" / "texts.json").exists() and (P / "drawings" / "dxf").is_dir() and not staged.exists()) info = json.loads((P / "pier.json").read_text(encoding="utf-8")) check("six answers + three angle values saved in pier.json", info.get("fit_answers", {}).get("soffit") == "곡선" and len(info["fit_answers"]) == 8, info.get("fit_answers")) check("pier keeps template label", "운곡교P1형" in info["template"], info["template"]) check("matching answers: no mismatch recorded, no warning on the pier page", info.get("fit_mismatch") == [] and "형식 불일치 경고" not in c.get("/pier/시험교각").get_data(as_text=True), info.get("fit_mismatch")) check("result judgement area + angle inputs on the page", 'id="verdict"' in html and 'name="ans_skew_deg"' in html) # second pier from the same staged recommendation with a different soffit answer -> warning, not closable r = c.post("/recommend", data={"dwg": [(open(p, "rb"), p.name) for p in dwgs]}, content_type="multipart/form-data") sid2 = re.search(r"/recommend/(\w+)/create", r.get_data(as_text=True)).group(1) c.post(f"/recommend/{sid2}/create", data={"name": "불일치교각", "type": "T형", "template": "tpl:운곡교P1형", "ans_foundation": "기초판+말뚝", "ans_soffit": "직선 경사", "ans_bearings": "10", "ans_rebar_shape": "아니오", "ans_rebar_method": "예", "ans_skew_deg": "18"}) info2 = json.loads((TD / "불일치교각" / "pier.json").read_text(encoding="utf-8")) check("mismatch recorded: soffit + rebar shape", info2["fit_mismatch"] == ["코핑 하면 형상", "철근 형상 종류"] and info2["fit_answers"]["skew_deg"] == "18", info2["fit_mismatch"]) for page in ("/pier/불일치교각", "/pier/불일치교각/candidates", "/pier/불일치교각/gates"): check(f"warning shown on {page}", "형식 불일치 경고" in c.get(page).get_data(as_text=True)) r = c.post("/recommend", data={"dwg": [(b"x", "a.txt")]}, content_type="multipart/form-data") check("non-DWG refused", r.status_code == 302) shutil.rmtree(TD, ignore_errors=True) print("RESULT", "PASS" if ok else "FAIL") sys.exit(0 if ok else 1)