Files
Aislo/resources/tester/test_322_0_version.py
T
eomsangdonandClaude Opus 5.5 e4b9b3e5a3 refactor(859-5 ②): 구조물 정의 코드 M02 StructOptions → M01_MasterData/StructOptions
- 파일 23 개 git mv · 이름 M02_SO_* → M01_SO_* · 내용 · 동작 · 화면 글 그대로
- 서버 주소 /api/m02 → /api/m01(이름만 · 10 길 · 수 469 그대로) · main.py 등록 이름 m01_so_*
- 화면 부름 = common_util_m02_call 의 call 에 base 인자(기본 /m02 · 구조물 정의만 /m01)
- import 고침 = B05 · B07 · B08 · M01 · M02 · main · 시험 · 도우미
- 소스 글자만 보던 시험 셋 지움(구조물 정의 옮김에 걸림 · 결과를 안 봄):
  test_m02_structure_options 좌측 줄 · test_m02_structure_option_groups 좌측 정의 줄 · test_136_3 M02 미리보기 단추 CSS
- test_553_5 부품 훑기 폴더 = 옮긴 자리

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 21:42:33 +09:00

59 lines
2.4 KiB
Python

"""PLAN 322-0 ③ — 판 확인: 서버 관 기본값 · 판 읽기 길이 정의 사본을 바로 따름(서버 다시 켜기 없음).
- `_registry_defaults` = 정의 파일이 바뀌면 다음 부름부터 새 기본값(옛 lru = 서버 다시 켤 때까지 옛 값).
- `GET /api/m01/structure-definition/version` = 지금 판 `{판}` 만(화면 종류 캐시가 판을 볼 때 · 한 벌 안 받음).
화면 캐시 쪽은 `test_322_0_golden.py::test_type_cache_follows_definition_version`.
"""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from B05_Profile import B05_Profile_Structures_Schema as schema
from B06_Section.B06_Section_Engine_Culvert import _registry_defaults
from common_util.common_util_auth import verify_session
from M01_MasterData.StructOptions.M01_SO_Router import read_router
@pytest.fixture
def copy(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""정의 사본 — 마스터 정본은 안 씀."""
path = tmp_path / "구조물정의.json"
path.write_text(Path(schema.DEFINITION_PATH).read_text("utf-8"), "utf-8")
monkeypatch.setattr(schema, "DEFINITION_PATH", str(path))
return path
def _rewrite(path: Path, change) -> None:
doc = json.loads(path.read_text("utf-8"))
change(doc)
path.write_text(json.dumps(doc, ensure_ascii=False), "utf-8")
def test_registry_defaults_follow_definition_file(copy: Path) -> None:
before = _registry_defaults("pipe")["pipe_diameter_mm"]
def bump(doc: dict) -> None:
pipe = next(t for t in doc["types"] if t["type_id"] == "pipe")
option = next(o for o in pipe["options"] if o["key"] == "pipe_diameter_mm")
option["default"] = "1200" if before != "1200" else "800"
_rewrite(copy, bump)
assert _registry_defaults("pipe")["pipe_diameter_mm"] != before
def test_version_endpoint_reads_current_version(copy: Path) -> None:
app = FastAPI()
app.include_router(read_router)
app.dependency_overrides[verify_session] = lambda: {"role": "USER", "user_id": 2}
client = TestClient(app)
now = json.loads(copy.read_text("utf-8"))["판"]
assert client.get("/api/m01/structure-definition/version").json() == {"판": now}
_rewrite(copy, lambda doc: doc.update(판=now + 3))
assert client.get("/api/m01/structure-definition/version").json() == {"판": now + 3}