93 lines
3.7 KiB
Python
93 lines
3.7 KiB
Python
"""Smoke-tests that every `ENTITY_REGISTRY` import schema is importable and
|
|
constructible, plus spot checks of enum-alias coercion."""
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from webapi.imports.schemas.registry import ENTITY_REGISTRY
|
|
from webapi.imports.schemas.cama.ordenes_estudio import OrdenesEstudioImportSchema as CamaOrdenesEstudioImportSchema
|
|
from webapi.imports.schemas.tea.eeg_estudio import EegEstudioImportSchema
|
|
from webapi.imports.schemas.cacu.biopsia_cervical import BiopsiaCervicalImportSchema
|
|
|
|
|
|
# Domains whose Core layer is fully permissive (every field Optional);
|
|
# see `tea/pacientes.py`'s docstring. CaCu/CaMa entities all carry at least
|
|
# one business-required field (`pac_id_hospital` and friends).
|
|
_FULLY_OPTIONAL_PREFIXES = ("tea.",)
|
|
|
|
|
|
@pytest.mark.parametrize("entity_key", list(ENTITY_REGISTRY.keys()))
|
|
def test_every_registered_schema_is_constructible(entity_key):
|
|
spec = ENTITY_REGISTRY[entity_key]
|
|
schema_cls = spec.schema
|
|
|
|
if entity_key.startswith(_FULLY_OPTIONAL_PREFIXES):
|
|
# Fully permissive: an empty row must construct cleanly.
|
|
instance = schema_cls()
|
|
assert instance is not None
|
|
else:
|
|
# Has at least one required field: an empty row must be rejected.
|
|
with pytest.raises(ValidationError):
|
|
schema_cls()
|
|
|
|
|
|
def test_entity_registry_has_twenty_two_entries():
|
|
assert len(ENTITY_REGISTRY) == 22
|
|
|
|
|
|
def test_entity_registry_keys_cover_all_three_domains():
|
|
keys = set(ENTITY_REGISTRY.keys())
|
|
assert "cacu.Paciente" in keys
|
|
assert "cacu.OrdenesEstudio" in keys
|
|
assert "cacu.CitologiaCervical" in keys
|
|
assert "cacu.BiopsiaCervical" in keys
|
|
assert "cacu.NotaMedica" in keys
|
|
assert "cacu.BiometriaHematica" in keys
|
|
assert "cama.Paciente" in keys
|
|
assert "cama.OrdenesEstudio" in keys
|
|
assert "cama.Mastografia" in keys
|
|
assert "cama.BiopsiaMama" in keys
|
|
assert "cama.NotaMedica" in keys
|
|
assert "cama.BiometriaHematica" in keys
|
|
assert "tea.Pacientes" in keys
|
|
assert "tea.OrdenesEstudio" in keys
|
|
assert "tea.NotaMedica" in keys
|
|
assert "tea.EvaluacionPsicologica" in keys
|
|
assert "tea.PotencialesEvocadosAuditivos" in keys
|
|
assert "tea.EegEstudio" in keys
|
|
assert "tea.AntecedentesMaternosGestacion" in keys
|
|
assert "tea.PartoNeonatal" in keys
|
|
|
|
|
|
# --- Spot checks -----------------------------------------------------------
|
|
# CaMa entity with a required, unique integer ord_numero_hospital and an
|
|
# *_ALIAS-backed enum field.
|
|
def test_cama_ordenes_estudio_requires_numero_hospital_and_coerces_tipo_estudio():
|
|
with pytest.raises(ValidationError) as excinfo:
|
|
CamaOrdenesEstudioImportSchema(pac_id_hospital="H-1")
|
|
errors = excinfo.value.errors()
|
|
assert any(e["loc"] == ("ord_numero_hospital",) for e in errors)
|
|
|
|
schema = CamaOrdenesEstudioImportSchema(
|
|
pac_id_hospital="H-1", ord_numero_hospital=12345, ord_tipo_estudio="biopsia chica"
|
|
)
|
|
assert schema.ord_tipo_estudio == "BIOPSIA_CHICA"
|
|
|
|
|
|
# TEA entity with a bare Enum field (no *_ALIAS dict), so the schema builds
|
|
# a Catalog from the Enum alone, as in tea/pacientes.py.
|
|
def test_tea_eeg_estudio_coerces_simetria_from_bare_enum_no_alias_dict():
|
|
schema = EegEstudioImportSchema(eeg_simetria="simetrico")
|
|
assert schema.eeg_simetria == "SIMETRICO"
|
|
|
|
|
|
# CaCu entity with a real *_ALIAS-backed field (GRADO_CIN_ALIAS).
|
|
def test_cacu_biopsia_cervical_coerces_cin_grado_alias():
|
|
schema = BiopsiaCervicalImportSchema(
|
|
pac_id_hospital="H-1",
|
|
bx_cin_grado="LESION INTRAEPITELIAL ESCAMOSA DE BAJO GRADO",
|
|
)
|
|
assert schema.bx_cin_grado == "LIEBG"
|
|
|
|
with pytest.raises(ValidationError):
|
|
BiopsiaCervicalImportSchema(bx_cin_grado="LIEBG") # pac_id_hospital missing
|