62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
"""Catálogos del SAT versionados en `seed/catalogos/sat/` (Pieza N, bloque 1)."""
|
|
|
|
import pytest
|
|
|
|
from app.services import catalogos_sat as cat
|
|
|
|
|
|
def test_cada_catalogo_declara_su_fuente_y_fecha_de_extraccion() -> None:
|
|
for nombre in cat.CATALOGOS:
|
|
fuente = cat.fuente(nombre)
|
|
assert "v4.3" in fuente and "2026-11-09" in fuente, nombre
|
|
assert len(cat.catalogo(nombre)) > 0, nombre
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("nombre", "filas"),
|
|
[
|
|
(cat.TIPO_ALERTA, 16),
|
|
(cat.PAIS, 249),
|
|
(cat.ACTIVIDAD_ECONOMICA_FISICA, 167),
|
|
(cat.GIRO_MERCANTIL_MORAL, 136),
|
|
(cat.CODIGO_POSTAL, 31942),
|
|
(cat.INSTRUMENTO_MONETARIO, 15),
|
|
(cat.MONEDA, 184),
|
|
(cat.TIPO_OPERACION, 2),
|
|
(cat.TIPO_GARANTIA, 13),
|
|
(cat.TIPO_INMUEBLE, 19),
|
|
(cat.PRIORIDAD, 2),
|
|
(cat.ACTIVIDAD_VULNERABLE, 20),
|
|
],
|
|
)
|
|
def test_conteos_de_los_catalogos(nombre: str, filas: int) -> None:
|
|
assert len(cat.catalogo(nombre)) == filas
|
|
|
|
|
|
def test_tipo_alerta_son_los_16_codigos_y_el_521_del_ejemplo_oficial_no_esta() -> None:
|
|
claves = set(cat.catalogo(cat.TIPO_ALERTA))
|
|
assert claves == {"100", "9999"} | {str(c) for c in range(2801, 2815)}
|
|
assert not cat.existe(cat.TIPO_ALERTA, "521")
|
|
assert cat.descripcion(cat.TIPO_ALERTA, 100) == "Sin alerta."
|
|
|
|
|
|
def test_claves_conocidas() -> None:
|
|
assert cat.catalogo(cat.PAIS)["MX"] == "MEXICO"
|
|
assert cat.descripcion(cat.INSTRUMENTO_MONETARIO, 8) == "Transferencia Interbancaria"
|
|
assert cat.descripcion(cat.MONEDA, 1) == "Peso mexicano"
|
|
assert set(cat.catalogo(cat.TIPO_OPERACION)) == {"401", "402"}
|
|
assert "1" not in cat.catalogo(cat.TIPO_GARANTIA) and "3" in cat.catalogo(cat.TIPO_GARANTIA)
|
|
assert cat.catalogo(cat.ACTIVIDAD_VULNERABLE)["MPC"]
|
|
|
|
|
|
def test_codigo_postal_trae_entidad_y_municipio() -> None:
|
|
assert cat.existe(cat.CODIGO_POSTAL, "01020") and not cat.existe(cat.CODIGO_POSTAL, "00000")
|
|
estado, municipio = cat.codigos_postales()["01020"]
|
|
assert estado and municipio
|
|
assert cat.descripcion(cat.CODIGO_POSTAL, "01020") == f"{municipio}, {estado}"
|
|
|
|
|
|
def test_catalogo_desconocido() -> None:
|
|
with pytest.raises(KeyError):
|
|
cat.catalogo("inexistente")
|