78 lines
2.9 KiB
Python
78 lines
2.9 KiB
Python
"""STMATE 재현 앱 변환 API(api_conv.py) — 화면이 부르는 길로 한 바퀴 · 쓰기는 임시 폴더(server.WORK_DBF_ROOT 바꿈).
|
|
|
|
정답 = 원본 STC 저장값(PRJLST 직접비 · 행 수). 코드에 값을 박지 않음.
|
|
"""
|
|
|
|
import base64
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "tools/stmate-test"))
|
|
import api_conv as A # noqa: E402
|
|
import server # noqa: E402
|
|
from dbf_rw import DbfTable # noqa: E402
|
|
from stc_read import Source # noqa: E402
|
|
|
|
DOCS = ROOT / "resources/knowledge/original/실무문서"
|
|
BH = DOCS / "04.산불 봉화/01. 내역서"
|
|
STC = BH / "13-2024년 산불진화임도 실시설계(기번41_현동)_ L=3.46km.STC"
|
|
XLSX = BH / "2024년 산불진화임도 실시설계(기번41_현동)_ L=3.46km.xlsx"
|
|
|
|
|
|
@pytest.fixture
|
|
def work(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(server, "WORK_DBF_ROOT", tmp_path)
|
|
return tmp_path
|
|
|
|
|
|
def _prj(path):
|
|
return DbfTable(Source(path).files["PRJLST.DBF"])
|
|
|
|
|
|
def test_xls_boq_and_register_api(work):
|
|
b64 = base64.b64encode(XLSX.read_bytes()).decode()
|
|
r = A.api_xls_boq(
|
|
A.XlsBoqReq(source_path=str(STC), xlsx=A.FileIn(b64=b64), target_folder_name="xb")
|
|
)
|
|
assert r["report"]["row_count"] == len(DbfTable(Source(str(STC)).files["BOQ11.DBF"]))
|
|
assert Path(r["saved_stc"]).parent == work
|
|
r2 = A.api_xls_register(
|
|
A.XlsRegReq(template_path=str(STC), xlsx=A.FileIn(path=str(XLSX)), target_folder_name="xr")
|
|
)
|
|
a, b = _prj(str(STC)), _prj(r2["saved_stc"])
|
|
assert b.get(0, "TCOST1") == a.get(0, "TCOST1") and b.get(0, "PNAME") == a.get(0, "PNAME")
|
|
|
|
|
|
def test_boq_xlsx_download_reimports(work):
|
|
resp = A.api_boq_xlsx(A.SrcReq(source_path=str(STC)))
|
|
assert resp.media_type == A.XLSX
|
|
b64 = base64.b64encode(resp.body).decode()
|
|
r = A.api_xls_boq(
|
|
A.XlsBoqReq(source_path=str(STC), xlsx=A.FileIn(b64=b64), target_folder_name="own")
|
|
)
|
|
assert Source(r["saved_stc"]).files["PRJLST.DBF"] == Source(str(STC)).files["PRJLST.DBF"]
|
|
|
|
|
|
def test_code_and_split_and_jaje_api(work):
|
|
r = A.api_code_change(
|
|
A.CodeChgReq(source_path=str(STC), mapping={"M00001": "M99991"}, target_folder_name="cc")
|
|
)
|
|
assert r["change_count"] > 0
|
|
codes = {DbfTable(Source(r["saved_stc"]).files["COSTN.DBF"]).get(i, "CODE") for i in range(3)}
|
|
assert "M00001" not in codes or "M99991" in codes
|
|
sp = A.api_split_change(A.SplitReq(source_path=str(STC), target_folder_name="sp"))
|
|
p = _prj(sp["saved_stc"])
|
|
assert p.get(0, "K_ORD") == "1" and p.get(0, "TCOST2") == p.get(0, "TCOST1") == _prj(
|
|
str(STC)
|
|
).get(0, "TCOST1")
|
|
x = A.api_jaje_xlsx(A.SrcReq(source_path=str(STC))).body
|
|
r3 = A.api_jaje_import(
|
|
A.JajeImportReq(source_path=str(STC), xlsx=A.FileIn(b64=base64.b64encode(x).decode()))
|
|
)
|
|
assert r3["count"] == 0
|
|
with pytest.raises(Exception):
|
|
A.api_jb_read(A.JbReq(path=str(STC))) # 설치 폴더 JB_* 만
|