Refactor digitador bot and add runtime monitoring
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from types import SimpleNamespace
|
||||
|
||||
os.environ["DATABASE_URL"] = "sqlite:///:memory:"
|
||||
|
||||
from api import main
|
||||
|
||||
|
||||
def test_post_event_persists_live_overlay_in_job_result(monkeypatch):
|
||||
patched: list[dict] = []
|
||||
job = SimpleNamespace(result={"total": 10})
|
||||
event = SimpleNamespace(to_dict=lambda: {"id": 1})
|
||||
fake_store = SimpleNamespace(
|
||||
get_job=lambda _job_id: job,
|
||||
add_event=lambda *_args, **_kwargs: event,
|
||||
patch_job=lambda _job_id, **kwargs: patched.append(kwargs) or job,
|
||||
)
|
||||
monkeypatch.setattr(main, "store", fake_store)
|
||||
|
||||
response = main.post_event(
|
||||
"job-1",
|
||||
main.EventBody(
|
||||
event_type="radicado_processing",
|
||||
message="Procesando",
|
||||
index=4,
|
||||
total=10,
|
||||
metadata={
|
||||
"estado": "Procesando",
|
||||
"processed": 3,
|
||||
"reinicios": 1,
|
||||
"radicado_actual": "RAD-4",
|
||||
"elapsed_seconds": 90,
|
||||
"speed_per_minute": 2.0,
|
||||
},
|
||||
),
|
||||
_="token",
|
||||
)
|
||||
|
||||
assert response == {"id": 1}
|
||||
result = patched[0]["result"]
|
||||
assert result["processed"] == 3
|
||||
assert result["total"] == 10
|
||||
assert result["radicado_actual"] == "RAD-4"
|
||||
assert result["reinicios"] == 1
|
||||
Reference in New Issue
Block a user