La barra lateral y el recorrido quedan en el orden nuevo: 1 Carga de información, 2 Cartera, 3 Expediente, 4 Beneficiario controlador, 5 Créditos y operaciones (solo consulta), 6 Screening, 7 Clasificación de riesgo, 8 Alertas y casos, 9 Evidencia, 10 Laboratorio. El número de paso de cada pantalla sale de NAVEGACION (ceja_paso), no de las plantillas. El módulo muestra la última carga (fecha, quién, conteos y resultado), la plantilla, la subida (solo oficial), el historial con su reporte de rechazos y un aviso cuando la empresa lleva más de su periodo de carga sin cargar. Inicio muestra primero la tarjeta de carga.
99 lines
4.6 KiB
Python
99 lines
4.6 KiB
Python
"""El módulo 1 en la interfaz (Pieza K, bloque 4): primer paso de la barra, números del
|
||
recorrido desde NAVEGACION, permisos, historial con su reporte de rechazos, tarjeta en Inicio y
|
||
aviso de periodo sin cargar."""
|
||
|
||
# ruff: noqa: F811 (las fixtures vienen de tests/test_expediente)
|
||
from __future__ import annotations
|
||
|
||
import io
|
||
from datetime import UTC, datetime, timedelta
|
||
|
||
import pytest
|
||
from fastapi.testclient import TestClient
|
||
from sqlalchemy.orm import Session, sessionmaker
|
||
|
||
from app.models import LoteCarga
|
||
from app.models.usuario import Rol
|
||
from app.routers import NAVEGACION
|
||
from app.services import operaciones as servicio
|
||
from tests.test_carga import FISICA, PAGO, archivo, csv_de, xlsx
|
||
from tests.test_expediente import cliente, entrar, fabrica # noqa: F401
|
||
|
||
|
||
def subir_y_cargar(c: TestClient, contenido: bytes, nombre: str) -> int:
|
||
subida = c.post("/carga", files={"archivo": (nombre, contenido, "application/octet-stream")})
|
||
destino = subida.headers["location"]
|
||
lote_id = int(destino.split("?")[0].rsplit("/", 1)[1])
|
||
if "Cargar las aceptadas" in c.get(destino).text:
|
||
c.post(f"/carga/lotes/{lote_id}/confirmar")
|
||
servicio.esperar(lote_id)
|
||
return lote_id
|
||
|
||
|
||
def test_la_carga_es_el_primer_paso_y_los_numeros_salen_de_navegacion(cliente: TestClient) -> None:
|
||
pasos = [e for e in NAVEGACION if e.paso]
|
||
assert [(e.paso, e.ruta) for e in pasos[:3]] == [(1, "/carga"), (2, "/cartera"),
|
||
(3, "/expediente")] # fmt: skip
|
||
assert [e.paso for e in pasos] == list(range(1, 11))
|
||
entrar(cliente, Rol.AUDITOR)
|
||
lateral = cliente.get("/inicio").text.split('<nav class="nav"')[1].split("</nav>")[0]
|
||
assert lateral.index("1 Carga de información") < lateral.index("3 Expediente")
|
||
for ruta, paso in (("/carga", 1), ("/expediente", 3), ("/riesgo", 7), ("/alertas", 8),
|
||
("/laboratorio", 10)): # fmt: skip
|
||
assert f"Paso {paso:02d} del recorrido" in cliente.get(ruta).text, ruta
|
||
|
||
|
||
@pytest.mark.parametrize("rol", [Rol.ANALISTA, Rol.AUDITOR])
|
||
def test_solo_el_oficial_sube_analista_y_auditor_consultan(cliente: TestClient, rol: Rol) -> None:
|
||
entrar(cliente, rol)
|
||
pantalla = cliente.get("/carga")
|
||
assert pantalla.status_code == 200 and "Historial de cargas" in pantalla.text
|
||
assert 'action="/carga"' not in pantalla.text # sin formulario de subida
|
||
assert cliente.get("/carga/plantilla?formato=xlsx").status_code == 200
|
||
archivo_ = {"archivo": ("c.xlsx", xlsx(archivo(clientes=[FISICA])), "x")}
|
||
assert cliente.post("/carga", files=archivo_).status_code == 403
|
||
assert cliente.post("/carga/lotes/1/confirmar").status_code == 403
|
||
|
||
|
||
def test_el_historial_muestra_el_lote_con_su_reporte_de_rechazos(
|
||
cliente: TestClient, fabrica: sessionmaker[Session]
|
||
) -> None:
|
||
entrar(cliente, Rol.OFICIAL)
|
||
lote_id = subir_y_cargar(cliente, csv_de("pagos", [{**PAGO, "id_credito": "NO"}]), "p.csv")
|
||
entrar(cliente, Rol.ANALISTA)
|
||
historial = cliente.get("/carga").text
|
||
assert f'href="/carga/lotes/{lote_id}"' in historial
|
||
assert f'href="/carga/lotes/{lote_id}/rechazos"' in historial and "Rechazado" in historial
|
||
reporte = cliente.get(f"/carga/lotes/{lote_id}/rechazos")
|
||
assert reporte.status_code == 200 and "crédito inexistente" in reporte.text
|
||
|
||
|
||
def test_el_aviso_de_periodo_sin_cargar_aparece_y_desaparece(
|
||
cliente: TestClient, fabrica: sessionmaker[Session]
|
||
) -> None:
|
||
entrar(cliente, Rol.OFICIAL)
|
||
assert "data-carga-vencida" in cliente.get("/carga").text # nunca se ha cargado
|
||
assert "Sin cargas en este periodo" in cliente.get("/inicio").text
|
||
|
||
lote_id = subir_y_cargar(cliente, xlsx(archivo(clientes=[FISICA])), "c.xlsx")
|
||
assert "data-carga-vencida" not in cliente.get("/carga").text
|
||
inicio = cliente.get("/inicio").text
|
||
assert "Última carga:" in inicio and "1 clientes nuevos" in inicio
|
||
assert inicio.index("Carga de información") < inicio.index("Sujeto obligado")
|
||
|
||
with fabrica() as sesion: # la última carga quedó hace dos meses (periodo: un mes)
|
||
lote = sesion.get(LoteCarga, lote_id)
|
||
lote.created_at = datetime.now(UTC) - timedelta(days=62)
|
||
sesion.commit()
|
||
assert "data-carga-vencida" in cliente.get("/carga").text
|
||
assert "Sin cargas en este periodo" in cliente.get("/inicio").text
|
||
|
||
|
||
def test_el_csv_de_la_plantilla_lleva_bom(cliente: TestClient) -> None:
|
||
import zipfile
|
||
|
||
entrar(cliente, Rol.ANALISTA)
|
||
contenido = cliente.get("/carga/plantilla?formato=csv").content
|
||
with zipfile.ZipFile(io.BytesIO(contenido)) as z:
|
||
assert all(z.read(n).startswith("".encode()) for n in z.namelist())
|