Fix auth headers in OCR/interact endpoint tests
All checks were successful
python-syntax / syntax-check (push) Successful in 1m7s

This commit is contained in:
2026-05-03 21:01:29 +02:00
parent 9e816e0417
commit c1fc97e198

View File

@@ -5,9 +5,17 @@ from fastapi.testclient import TestClient
from server import services from server import services
from server.app import app from server.app import app
from server.config import SETTINGS
from server.models import ClickTextAction from server.models import ClickTextAction
def _auth_headers() -> dict:
token = SETTINGS.get("token", "")
if not token:
return {}
return {"x-clickthrough-token": token}
def test_extract_ocr_items_normalization(monkeypatch): def test_extract_ocr_items_normalization(monkeypatch):
class FakeOutput: class FakeOutput:
DICT = "DICT" DICT = "DICT"
@@ -81,6 +89,7 @@ def test_interact_click_text_region_optional(monkeypatch):
response = client.post( response = client.post(
"/interact", "/interact",
json={"screen": 0, "action": {"action": "click_text", "dry_run": True, "click_text": {"text": "Apply", "match": "contains"}}}, json={"screen": 0, "action": {"action": "click_text", "dry_run": True, "click_text": {"text": "Apply", "match": "contains"}}},
headers=_auth_headers(),
) )
assert response.status_code == 200 assert response.status_code == 200
body = response.json()["data"] body = response.json()["data"]
@@ -97,10 +106,10 @@ def test_see_ocr_off_on_contract(monkeypatch):
monkeypatch.setattr("server.app.extract_ocr_items", lambda *args, **kwargs: [{"text": "x"}]) monkeypatch.setattr("server.app.extract_ocr_items", lambda *args, **kwargs: [{"text": "x"}])
client = TestClient(app) client = TestClient(app)
off = client.post("/see", json={"ocr": False, "with_grid": False}) off = client.post("/see", json={"ocr": False, "with_grid": False}, headers=_auth_headers())
assert off.status_code == 200 assert off.status_code == 200
assert "ocr" not in off.json()["data"]["meta"] assert "ocr" not in off.json()["data"]["meta"]
on = client.post("/see", json={"ocr": True, "with_grid": False}) on = client.post("/see", json={"ocr": True, "with_grid": False}, headers=_auth_headers())
assert on.status_code == 200 assert on.status_code == 200
assert on.json()["data"]["meta"]["ocr"][0]["text"] == "x" assert on.json()["data"]["meta"]["ocr"][0]["text"] == "x"
@@ -121,7 +130,7 @@ def test_interact_verify_success_and_timeout(monkeypatch):
"check_interval_ms": 10, "check_interval_ms": 10,
"timeout_ms": 500, "timeout_ms": 500,
} }
ok_resp = client.post("/interact/verify", json=payload) ok_resp = client.post("/interact/verify", json=payload, headers=_auth_headers())
assert ok_resp.status_code == 200 assert ok_resp.status_code == 200
ok_data = ok_resp.json()["data"] ok_data = ok_resp.json()["data"]
assert ok_data["verified"] is True assert ok_data["verified"] is True
@@ -132,7 +141,7 @@ def test_interact_verify_success_and_timeout(monkeypatch):
"_verify_ocr_text_near_point", "_verify_ocr_text_near_point",
lambda _spec: {"ok": False, "matches": [], "items_count": 0, "screen": {"selected": 0}, "region": {"x": 0, "y": 0, "width": 1, "height": 1}}, lambda _spec: {"ok": False, "matches": [], "items_count": 0, "screen": {"selected": 0}, "region": {"x": 0, "y": 0, "width": 1, "height": 1}},
) )
timeout_resp = client.post("/interact/verify", json=payload) timeout_resp = client.post("/interact/verify", json=payload, headers=_auth_headers())
assert timeout_resp.status_code == 200 assert timeout_resp.status_code == 200
timeout_data = timeout_resp.json()["data"] timeout_data = timeout_resp.json()["data"]
assert timeout_data["verified"] is False assert timeout_data["verified"] is False