"""Pier page '3. 게이트' batch button states (2026-10-12): disabled while sections are unconfirmed, enabled after bulk confirmation, replaced by a notice when all gates are approved. Uses 검증/web_batch_test_data from test_web_batch.py (pier 배치P1 fully approved) plus a fresh pier made from it; no Rhino run. """ import os import re import shutil import sys from pathlib import Path APP = Path(__file__).resolve().parents[1] TD = APP / "검증" / "web_batch_test_data" os.environ["PIERAPP_DATA"] = str(TD) sys.path.insert(0, str(APP / "web")) import app as webapp # noqa: E402 import store # noqa: E402 sys.path.insert(0, str(Path(__file__).resolve().parent)) from testlib import confirm_required # noqa: E402 ok = True def check(name, cond, detail=""): global ok ok &= bool(cond) print("PASS" if cond else "FAIL", name, detail) c = webapp.app.test_client() shutil.rmtree(TD / "버튼P", ignore_errors=True) c.post("/pier/new", data={"name": "버튼P", "type": "T형", "template": "배치P1"}) h = c.get("/pier/버튼P").get_data(as_text=True) btn = re.search(r"]*>G1~G5 일괄 승인", h) check("unconfirmed: button shown but disabled", btn and "disabled" in btn.group(0)) confirm_required(c, webapp, store, "버튼P", "시험자") h = c.get("/pier/버튼P").get_data(as_text=True) btn = re.search(r"]*>G1~G5 일괄 승인", h) check("confirmed: button enabled", btn and "disabled" not in btn.group(0)) check("form posts to the batch route", 'action="/pier/%EB%B2%84%ED%8A%BCP/gates/run_all"' in h or "/gates/run_all" in h) h = c.get("/pier/배치P1").get_data(as_text=True) check("all approved: notice instead of button", "모든 게이트가 승인되어 있습니다" in h and "일괄 승인" not in h) check("all approved: last batch shown", "최근 일괄 실행: 완료" in h) shutil.rmtree(TD / "버튼P", ignore_errors=True) sys.exit(0 if ok else 1)