Files
Aislo/resources/tester/test_est_multi_search.py
T

56 lines
2.7 KiB
Python

"""EST 테스트 앱 통합 검색(원본 TFRMMULTISERCH, 검색위치 = 저장된 작업)."""
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def test_search_finds_words_in_selected_kinds(tmp_path):
sample = json.loads((ROOT / "tools/est-test/sample.json").read_text(encoding="utf-8"))
sample["name"] = "검색 시험 공사"
(tmp_path / ("a" * 24 + ".json")).write_text(json.dumps(sample), encoding="utf-8")
(tmp_path / ("b" * 24 + ".json")).write_text("{bad json", encoding="utf-8")
(tmp_path / "forms.json").write_text("[]", encoding="utf-8")
script = """
const s = require('./tools/est-test/search-store.cjs'), dir = process.argv[1];
const out = {};
out.labor = s.search(dir, '건설기계 운전사', ['6']);
out.none = s.search(dir, '건설기계', ['5']);
out.excluded = s.search(dir, '건설기계', ['6'], 'a'.repeat(24));
const err = [];
for (const args of [['', ['6']], ['x', ['999']]]) { try { s.search(dir, ...args); } catch (e) { err.push(e.message.slice(0, 4)); } }
out.err = err;
process.stdout.write(JSON.stringify(out));
"""
result = json.loads(
subprocess.check_output(["node", "-e", script, str(tmp_path)], cwd=ROOT).decode("utf-8")
)
hit = result["labor"]["hits"][0]
assert result["labor"]["total"] >= 1
assert hit["project"] == "검색 시험 공사" and hit["kind"] == 6 and hit["label"] == "노임단가"
assert "건설기계운전사" in hit["Name"].replace(" ", "")
assert result["none"]["total"] == 0
assert result["excluded"]["total"] == 0
assert result["err"] == ["검색어를", "검색할 "]
def test_search_price_range_and_main_data_only(tmp_path):
sample = json.loads((ROOT / "tools/est-test/sample.json").read_text(encoding="utf-8"))
(tmp_path / ("a" * 24 + ".json")).write_text(json.dumps(sample), encoding="utf-8")
(tmp_path / ("c" * 24 + ".json")).write_text(json.dumps(sample), encoding="utf-8")
script = """
const s = require('./tools/est-test/search-store.cjs'), dir = process.argv[1];
const range = s.search(dir, '1~999999999', ['5']);
const exact = s.search(dir, String(range.hits[0].price), ['5']);
const only = s.search(dir, '1~999999999', ['5'], '', ['c'.repeat(24)]);
process.stdout.write(JSON.stringify({ range: range.hits.map((h) => h.price), exact: exact.total, only: only.hits.map((h) => h.id), total: range.total }));
"""
out = json.loads(
subprocess.check_output(["node", "-e", script, str(tmp_path)], cwd=ROOT).decode("utf-8")
)
assert out["range"] and all(1 <= p <= 999999999 for p in out["range"])
assert out["exact"] >= 2
assert set(out["only"]) == {"c" * 24} and len(out["only"]) == out["total"] // 2