feat: RapidOCR default OCR engine, office-only ocr_engine, drop operator toggle
ci / smoke (push) Canceled after 0s

This commit is contained in:
andrew committed 2026-09-25 16:18:41 +07:00
1 parent 080237ad3b
commit fbba169507
16 files changed
+137 -112

No files matched your search

+23 -6
View File
@@ -116,6 +116,7 @@ def test_ocr_engine_validation():
for e in OCR_ENGINES:
assert is_valid_ocr_engine(e)
assert not is_valid_ocr_engine("easyocr")
assert OCR_ENGINES[0] == "rapid" # default engine
def test_empty_do_settings_defaults():
@@ -123,7 +124,7 @@ def test_empty_do_settings_defaults():
assert s["ocr_engine"] == "tesseract"
assert s["require_do"] is True
bad = empty_do_settings({"ocr_engine": "nope"})
assert bad["ocr_engine"] == "tesseract"
assert bad["ocr_engine"] == "rapid"
def test_parse_fields_from_text():
@@ -145,6 +146,21 @@ def test_extract_do_fields_none_engine(tmp_path):
assert out["engine"] == "none"
def test_extract_do_fields_rapid_engine(tmp_path):
from src.do_ocr import extract_do_fields
Image = pytest.importorskip("PIL.Image")
p = tmp_path / "do.png"
Image.new("RGB", (200, 60), "white").save(p)
out = extract_do_fields(str(p), engine="rapid")
assert out["engine"] == "rapid"
if out["ocr_ok"]:
assert out["ocr_text"] == "" # blank image → empty text, no crash
else:
# rapid missing → explicit error (never silent fallback)
assert "rapidocr" in out["ocr_error"].lower()
# ---------------------------------------------------------------------------
# Flask API auth tests — skipped when flask/openpyxl not installed (CI)
# ---------------------------------------------------------------------------
@@ -213,17 +229,18 @@ def test_model_mode_post_operator_403(dash_client):
assert res.status_code == 403
def test_ocr_engine_post_both_ports(dash_client):
def test_ocr_engine_post_office_only(dash_client):
client, _, _, settings_path = dash_client
res = client.post("/api/do/settings", json={"ocr_engine": "paddle"},
headers={"Host": "localhost:5000"})
assert res.status_code == 403
office = {"Host": f"localhost:{cd_office_port()}"}
res = client.post("/api/do/settings", json={"ocr_engine": "paddle"}, headers=office)
assert res.status_code == 200
assert res.get_json()["ocr_engine"] == "paddle"
res = client.post("/api/do/settings", json={"ocr_engine": "tesseract"},
headers={"Host": f"localhost:{cd_office_port()}"})
res = client.post("/api/do/settings", json={"ocr_engine": "tesseract"}, headers=office)
assert res.status_code == 200
res = client.post("/api/do/settings", json={"ocr_engine": "bogus"},
headers={"Host": "localhost:5000"})
res = client.post("/api/do/settings", json={"ocr_engine": "bogus"}, headers=office)
assert res.status_code == 400