add import audit trail, live indicator recompute, reportes endpoints; production hardening
This commit is contained in:
@@ -6,6 +6,11 @@ import pytest
|
||||
from sqlalchemy import create_engine, text
|
||||
|
||||
|
||||
def _patients(client) -> dict[str, dict]:
|
||||
rows = client.get("/data/cacu.Paciente", query_string={"limit": 500}).get_json()["rows"]
|
||||
return {row["pac_id_hospital"]: row for row in rows}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def client(wire_domain):
|
||||
wire_domain("cacu")
|
||||
@@ -81,8 +86,7 @@ def test_validate_reports_row_errors_without_writing(client):
|
||||
assert body["valid_count"] == 1
|
||||
assert body["error_count"] == 1
|
||||
assert body["errors"][0]["field"] == "pac_id_hospital"
|
||||
# not written
|
||||
assert client.get("/cacu/pacientes/999").status_code == 404
|
||||
assert "H-VALIDATE-1" not in _patients(client)
|
||||
|
||||
|
||||
def test_commit_multi_source_batch_mixes_file_and_sql_within_one_domain(client, tmp_path):
|
||||
@@ -115,12 +119,7 @@ def test_commit_multi_source_batch_mixes_file_and_sql_within_one_domain(client,
|
||||
assert body["ok"] is True
|
||||
assert [r["target"] for r in body["results"]] == ["cacu.Paciente", "cacu.Paciente"]
|
||||
assert sum(r["created"] for r in body["results"]) == 2
|
||||
|
||||
# First test in this file to write into cacu.Paciente, so autoincrement
|
||||
# ids 1/2 are deterministic (pytest runs this module's tests in
|
||||
# definition order).
|
||||
created_hospital_ids = {client.get(f"/cacu/pacientes/{i}").get_json()["pac_id_hospital"] for i in (1, 2)}
|
||||
assert created_hospital_ids == {"H-BATCH-1", "H-SQL-BATCH-1"}
|
||||
assert {"H-BATCH-1", "H-SQL-BATCH-1"} <= set(_patients(client))
|
||||
|
||||
|
||||
def test_commit_rejects_a_batch_mixing_domains(client):
|
||||
@@ -129,7 +128,7 @@ def test_commit_rejects_a_batch_mixing_domains(client):
|
||||
|
||||
response = client.post("/imports/commit", json={"sources": [cacu_source, tea_source], "on_conflict": "reject"})
|
||||
assert response.status_code == 400
|
||||
assert "domain" in response.get_json()["error"].lower()
|
||||
assert "dominios" in response.get_json()["error"]
|
||||
|
||||
|
||||
def test_commit_on_conflict_reject_then_upsert(client):
|
||||
@@ -179,8 +178,8 @@ def test_tea_patient_keeps_the_source_id_and_reimport_updates_it(client):
|
||||
assert body["results"][0]["created"] == 0
|
||||
assert body["results"][0]["updated"] == 1
|
||||
|
||||
paciente = client.get("/tea/pacientes/9001").get_json()
|
||||
assert paciente["pac_id_hospital"] == "T-SRC-1"
|
||||
[paciente] = client.get("/data/tea.Pacientes").get_json()["rows"]
|
||||
assert paciente["pac_id"] == 9001 and paciente["pac_id_hospital"] == "T-SRC-1"
|
||||
assert paciente["pac_sexo"] == "M"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user