"""보호공 개편(2026-08-17) 구 저장분 마이그레이션. 개편 전 유입·유출 바닥 보호는 `*_pitching`(있음/없음)과 `*_pitching_finish`(찰/메) 두 축이었다. 도수로·산비탈수로(B4)가 유출부에서 돌붙임 대신 쓰는 공종이라 세 값을 `*_protection` 한 축(돌붙임(찰)/돌붙임(메)/도수로)으로 합쳤고, "없음"은 삭제했다 (물이 흐르는 자리라 보호공은 필수 — 사용자 확정). `parse_pipe_points`가 읽는 순간 새 키로 옮기므로 화면·수량 어느 쪽도 옛 키를 모른다. """ from common_util.common_util_drainage_pipes import parse_pipe_points def _options(payload: dict) -> dict: points = parse_pipe_points([{"chainage_m": 100.0, "options": payload}]) assert len(points) == 1 return points[0].options or {} def test_legacy_pitching_with_finish_becomes_protection(): """있음 + 찰/메 → 돌붙임(찰)/돌붙임(메). 면적은 새 키로 옮겨 탄다.""" options = _options( { "inlet_pitching": "있음", "inlet_pitching_finish": "찰", "inlet_pitching_area_m2": 9.0, "outlet_pitching": "있음", "outlet_pitching_finish": "메", "outlet_pitching_area_m2": 25.0, } ) assert options["inlet_protection"] == "돌붙임(찰)" assert options["outlet_protection"] == "돌붙임(메)" assert options["inlet_protection_area_m2"] == 9.0 assert options["outlet_protection_area_m2"] == 25.0 def test_legacy_keys_are_removed(): """옛 키가 남으면 화면·수량이 두 벌을 보게 된다.""" options = _options( {"inlet_pitching": "있음", "inlet_pitching_finish": "찰", "inlet_pitching_area_m2": 9.0} ) for gone in ("inlet_pitching", "inlet_pitching_finish", "inlet_pitching_area_m2"): assert gone not in options, gone def test_legacy_none_is_promoted_to_part_default(): """구 "없음"은 선택지가 사라졌으므로 부위 기본값(유입 찰·유출 메)으로 올린다.""" options = _options({"inlet_pitching": "없음", "outlet_pitching": "없음"}) assert options["inlet_protection"] == "돌붙임(찰)" assert options["outlet_protection"] == "돌붙임(메)" def test_legacy_without_finish_falls_back_to_part_default(): """표면처리가 빠진 구 저장분도 부위 기본값으로 채운다.""" options = _options({"outlet_pitching": "있음"}) assert options["outlet_protection"] == "돌붙임(메)" def test_new_keys_win_over_legacy(): """이미 새 키가 있으면 구 키가 덮어쓰지 않는다(재저장분 보호).""" options = _options( { "inlet_protection": "도수로", "inlet_protection_width_m": 1.0, "inlet_pitching": "있음", "inlet_pitching_finish": "찰", } ) assert options["inlet_protection"] == "도수로" assert options["inlet_protection_width_m"] == 1.0 assert "inlet_pitching" not in options def test_untouched_options_pass_through(): """보호공과 무관한 옵션은 그대로 둔다.""" options = _options({"pipe_kind": "파형강관", "pipe_diameter_mm": 1000}) assert options == {"pipe_kind": "파형강관", "pipe_diameter_mm": 1000}