Files
ISSSTELEON/Core/tests/test_models.py
T
rockdrigo 66c4ba5c5f Core: cat_sistema_fuente and cat_mapeo, how each source writes the catalog's codes, in the three domains
How: `CatSistemaFuenteBase` (who sends the data, its staging table and validity) and `CatMapeoBase` (a study
code, caption or spelling of a source, mapped to `estudio_id`, `resultado_id` or a `cat_valor`, with its
validity, author and reason), with their constraints in `reglas_de_mapeo` and `vigencia_ordenada`: a known
class and the target it needs, the value's foreign key to `cat_valor`, and one row per form and start date.

Implications: the codes stay in the TOML; how a provider writes them becomes data, edited without a deploy.
Overlapping validities aren't a portable constraint and are checked by the writer and by dbt.
2026-11-13 15:29:07 -06:00

118 lines
4.1 KiB
Python

"""Smoke tests: each domain's models import cleanly and register on their
own isolated metadata (no cross-domain table-name collisions)."""
from core.cacu.base import CaCuModel
from core.cama.base import CaMaModel
from core.tea.base import TeaModel
from core.governance.base import GovernanceModel
from core.cacu import models as cacu_models
from core.cacu.indicadores import models as cacu_indicadores_models
from core.cama import models as cama_models
from core.cama.indicadores import models as cama_indicadores_models
from core.tea import models as tea_models
from core.tea.indicadores import models as tea_indicadores_models
from core.governance import models as governance_models
INDICADORES_KIT_CDM = {
"persona",
"periodo_observacion",
"carga",
"def_parametro",
"dim_periodo",
"dim_fecha",
"dim_grupo_edad",
"cat_estudio",
"cat_resultado",
"cat_valor",
"cat_sistema_fuente",
"cat_mapeo",
"procedimiento",
"observacion_clinica",
"cat_measure",
"cat_measure_resultado",
"cat_measure_valor",
"cat_measure_grupo",
"cat_estrato",
"cat_estrato_valor",
"cat_measure_estrato",
"measure_report",
"measure_report_unidad",
"measure_report_unidad_estrato",
"cohorte_armado",
"cohorte_miembro",
"cohorte_exclusion",
"cohorte_variable",
"evaluacion_riesgo_lote",
"evaluacion_riesgo",
}
def test_cacu_tables_registered():
"""Staging (hospital-shaped) and indicadores_kit CDM tables share
CaCuModel's registry (same database, per the kit's ADR-004)."""
names = set(CaCuModel.metadata.tables.keys())
assert names == {
"paciente", "ordenesestudio", "citologiacervical", "biopsiacervical",
"notamedica", "biometriahematica", "episodioclinico",
*INDICADORES_KIT_CDM,
}
def test_cama_tables_registered():
"""Staging (hospital-shaped) and indicadores_kit CDM tables share
CaMaModel's registry (same database, per the kit's ADR-004)."""
names = set(CaMaModel.metadata.tables.keys())
assert names == {
"paciente", "ordenesestudio", "mastografia", "biopsiamama",
"notamedica", "biometriahematica", "episodioclinico",
*INDICADORES_KIT_CDM,
}
def test_tea_tables_registered():
"""Staging (hospital-shaped) and indicadores_kit CDM tables share
TeaModel's registry (same database, per the kit's ADR-004), so both
module's tables are asserted together."""
names = set(TeaModel.metadata.tables.keys())
assert names == {
# Staging: fed by the hospital source via the import pipeline.
"pacientes",
"ordenes_estudio",
"mchat",
"ados2",
"evaluacion_neuropediatrica",
"eeg",
"eeg_metrica",
"eeg_metrica_electrodo",
# indicadores_kit CDM, built from staging by the webapi.orquestacion graph.
*INDICADORES_KIT_CDM,
}
def test_governance_tables_registered():
names = set(GovernanceModel.metadata.tables.keys())
assert names == {
"extractionrun",
"modelprediction",
}
def test_domains_do_not_share_metadata():
assert CaCuModel.metadata is not CaMaModel.metadata
assert CaCuModel.metadata is not TeaModel.metadata
assert CaMaModel.metadata is not TeaModel.metadata
assert CaCuModel.metadata is not GovernanceModel.metadata
assert CaMaModel.metadata is not GovernanceModel.metadata
assert TeaModel.metadata is not GovernanceModel.metadata
def test_cat_mapeo_keeps_its_rules_in_the_schema():
"""Pins down: a mapping row needs a known class with the target that class needs, a value of the catalog, and
one row per form and start date; `cat_sistema_fuente` keeps its dates in order. Fails if a constraint is
dropped from `reglas_de_mapeo` or `vigencia_ordenada`, which every engine relies on."""
from core.cama.indicadores.models import CatMapeo, CatSistemaFuente
names = {c.name for c in CatMapeo.__table__.constraints}
assert {"ck_cat_mapeo_clase", "ck_cat_mapeo_destino", "ck_cat_mapeo_vigencia", "fk_cat_mapeo_valor",
"uq_cat_mapeo"} <= names
assert "ck_cat_sistema_fuente_vigencia" in {c.name for c in CatSistemaFuente.__table__.constraints}