Skip to content

Commit

Permalink
Merge pull request #46 from guivaloz/guivaloz/variable-estado-clave
Browse files Browse the repository at this point in the history
Guivaloz/variable estado clave
  • Loading branch information
guivaloz authored Feb 21, 2025
2 parents f3b36da + 381af6e commit c14592a
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 85 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ DB_PASS=XXXXXXXXXXXX
# Google Cloud Storage
CLOUD_STORAGE_DEPOSITO=XXXXXXXXXXXX

# Clave INEGI del Estado, 05 = Coahuila de Zaragoza
ESTADO_CLAVE=05

# Origins
ORIGINS=http://127.0.0.1:3000

Expand Down Expand Up @@ -102,6 +105,7 @@ then
echo " DB_NAME: ${DB_NAME}"
echo " DB_USER: ${DB_USER}"
echo " DB_PASS: ${DB_PASS}"
echo " ESTADO_CLAVE: ${ESTADO_CLAVE}"
echo " ORIGINS: ${ORIGINS}"
echo " SALT: ${SALT}"
echo
Expand Down
53 changes: 29 additions & 24 deletions pjecz_carina_api_key/routers/exh_exhortos.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
)
from ..schemas.exh_exhortos_archivos import ExhExhortoArchivoItem
from ..schemas.exh_exhortos_partes import ExhExhortoParteItem
from ..settings import Settings, get_settings

exh_exhortos = APIRouter(prefix="/api/v5/exh_exhortos")

ESTADO_DESTINO_NOMBRE = "COAHUILA DE ZARAGOZA"
ESTADO_DESTINO_ID = 5


def get_exhorto_with_exhorto_origen_id(database: Annotated[Session, Depends(get_db)], exhorto_origen_id: str) -> ExhExhorto:
"""Consultar un exhorto con su exhorto_origen_id"""
Expand Down Expand Up @@ -77,15 +75,21 @@ def get_exhorto_with_folio_seguimiento(database: Annotated[Session, Depends(get_
return exh_exhorto


def get_municipio_destino(database: Annotated[Session, Depends(get_db)], municipio_num: int) -> Municipio:
def get_municipio_destino(
database: Annotated[Session, Depends(get_db)],
settings: Annotated[Settings, Depends(get_settings)],
municipio_num: int,
) -> Municipio:
"""Obtener el municipio de destino a partir de la clave INEGI"""
municipio_destino_clave = str(municipio_num).zfill(3)
try:
municipio_destino = (
database.query(Municipio).filter_by(estado_id=ESTADO_DESTINO_ID).filter_by(clave=municipio_destino_clave).one()
database.query(Municipio).filter_by(estado_id=settings.estado_clave).filter_by(clave=municipio_destino_clave).one()
)
except (MultipleResultsFound, NoResultFound) as error:
raise MyNotExistsError(f"No existe el municipio {municipio_destino_clave} en {ESTADO_DESTINO_NOMBRE}") from error
raise MyNotExistsError(
f"No existe el municipio {municipio_destino_clave} en el estado {settings.estado_clave}"
) from error
return municipio_destino


Expand All @@ -102,7 +106,7 @@ def get_municipio_origen(database: Annotated[Session, Depends(get_db)], estado_n
database.query(Municipio).filter_by(estado_id=estado_origen.id).filter_by(clave=municipio_origen_clave).one()
)
except (MultipleResultsFound, NoResultFound) as error:
raise MyNotExistsError(f"No existe el municipio {municipio_origen_clave} en {ESTADO_DESTINO_NOMBRE}") from error
raise MyNotExistsError(f"No existe el municipio {municipio_origen_clave} en {estado_origen_clave}") from error
return municipio_origen


Expand Down Expand Up @@ -322,6 +326,7 @@ async def consultar_exhorto_request(
async def recibir_exhorto_request(
current_user: Annotated[UsuarioInDB, Depends(get_current_active_user)],
database: Annotated[Session, Depends(get_db)],
settings: Annotated[Settings, Depends(get_settings)],
exh_exhorto_in: ExhExhortoIn,
):
"""Recepción de datos de un exhorto"""
Expand All @@ -337,32 +342,32 @@ async def recibir_exhorto_request(
errores.append("No es válido exhortoOrigenId")

# Consultar nuestro estado
estado_destino = database.query(Estado).get(ESTADO_DESTINO_ID)
estado_destino = database.query(Estado).get(settings.estado_clave)
if estado_destino is None:
errores.append(f"No existe el estado de destino {ESTADO_DESTINO_NOMBRE}")
errores.append(f"No existe el estado de destino {settings.estado_clave}")

# Validar municipioDestinoId, obligatorio y es un identificador INEGI
try:
municipio_destino = get_municipio_destino(database, exh_exhorto_in.municipioDestinoId)
municipio_destino = get_municipio_destino(database, settings, exh_exhorto_in.municipioDestinoId)
except MyAnyError as error:
errores.append(str(error))

# Consultar ExhExterno de nuestro estado
# Consultar nuestro estado en exh_externos
estado_destino_exh_externo = database.query(ExhExterno).filter_by(estado_id=estado_destino.id).first()
if estado_destino_exh_externo is None:
errores.append(f"No existe el registro de {ESTADO_DESTINO_NOMBRE} en exh_externos")

# Tomar las materias de nuestro estado
materias = estado_destino_exh_externo.materias
if materias is None:
errores.append(f"No hay materias para {ESTADO_DESTINO_NOMBRE}")

# Validar materiaClave, obligatorio
materia_clave = safe_clave(exh_exhorto_in.materiaClave)
materia = next((materia for materia in materias if materia["clave"] == materia_clave), None)
if materia is None:
errores.append(f"No tiene la materia {materia_clave} en {ESTADO_DESTINO_NOMBRE}")
materia_nombre = materia["nombre"]
errores.append(f"No existe el registro del estado {settings.estado_clave} en exh_externos")

# Validar materiaClave, que la tenga nuestro estado
if estado_destino_exh_externo:
materias = estado_destino_exh_externo.materias
if materias:
materia_clave = safe_clave(exh_exhorto_in.materiaClave)
try:
materia_nombre = materias[materia_clave]
except KeyError:
errores.append(f"No tiene la materia '{materia_clave}' el estado {settings.estado_clave} en exh_externos")
else:
errores.append(f"No hay materias en el estado {settings.estado_clave} en exh_externos")

# Validar estadoOrigenId y municipioOrigenId, enteros obligatorios y son identificadores INEGI
try:
Expand Down
3 changes: 3 additions & 0 deletions pjecz_carina_api_key/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- DB_NAME
- DB_USER
- DB_PASS
- ESTADO_CLAVE
- ORIGINS
- SALT
Expand All @@ -28,6 +29,7 @@
- pjecz_carina_api_key_db_name
- pjecz_carina_api_key_db_user
- pjecz_carina_api_key_db_pass
- pjecz_carina_api_key_estado_clave
- pjecz_carina_api_key_origins
- pjecz_carina_api_key_salt
Expand Down Expand Up @@ -77,6 +79,7 @@ class Settings(BaseSettings):
db_name: str = get_secret("db_name")
db_pass: str = get_secret("db_pass")
db_user: str = get_secret("db_user")
estado_clave: str = get_secret("estado_clave")
origins: str = get_secret("origins")
salt: str = get_secret("salt")
tz: str = "America/Mexico_City"
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Crear un archivo .env con las siguientes variables
API_KEY=XXXXXXXX.XXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXX
API_BASE_URL=http://127.0.0.1:8000/v5
TIMEOUT=10
ESTADO_CLAVE=05
FOLIO_SEGUIMIENTO=XXXXXXXXXXXXXXXX
ARCHIVO_PDF_HASHSHA1=
ARCHIVO_PDF_HASHSHA256=
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"api_key": os.getenv("API_KEY", ""),
"api_base_url": os.getenv("API_BASE_URL", "http://127.0.0.1:8000/v4"),
"timeout": int(os.getenv("TIMEOUT", "10")),
"estado_clave": os.getenv("ESTADO_CLAVE", "05"),
"folio_seguimiento": os.getenv("FOLIO_SEGUIMIENTO", ""),
"archivo_pdf_hashsha1": os.getenv("ARCHIVO_PDF_HASHSHA1", ""),
"archivo_pdf_hashsha256": os.getenv("ARCHIVO_PDF_HASHSHA256", ""),
Expand Down
8 changes: 4 additions & 4 deletions tests/test_000_consultar_estados.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def test_get_estados(self):
self.assertEqual("clave" in item, True)
self.assertEqual("nombre" in item, True)

def test_get_estado_clave_05(self):
"""GET method for estado with clave 05 nombre COAHUILA DE ZARAGOZA"""
def test_get_estado_clave(self):
"""GET method for estado with clave"""

# Consultar el estado aguascalientes
# Consultar el estado definido en la variable de entorno ESTADO_CLAVE
try:
response = requests.get(
url=f"{config['api_base_url']}/estados/05",
url=f"{config['api_base_url']}/estados/{config['estado_clave']}",
headers={"X-Api-Key": config["api_key"]},
timeout=config["timeout"],
)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_000_consultar_municipios.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
class TestsConsultarMunicipios(unittest.TestCase):
"""Tests Consultar Municipios"""

def test_get_municipios_estado_clave_05(self):
"""GET method for municipios for estado with clave 05"""
def test_get_municipios_estado_clave(self):
"""GET method for municipios for estado with clave"""

# Consultar los municipios
# Consultar los municipios del estado definido en la variable de entorno ESTADO_CLAVE
try:
response = requests.get(
url=f"{config['api_base_url']}/municipios/05",
url=f"{config['api_base_url']}/municipios/{config['estado_clave']}",
headers={"X-Api-Key": config["api_key"]},
timeout=config["timeout"],
)
Expand Down
6 changes: 0 additions & 6 deletions tests/test_010_consultar_materias.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
"""
Unit test - Consultar Materias
Listado de materias del PJ exhortado.
- GET /materias
- GET /materias/{MATERIA_CLAVE}
"""

import unittest
Expand Down
8 changes: 0 additions & 8 deletions tests/test_020_enviar_exhorto.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
"""
Unit test - Enviar Exhorto
Se manda el esquema ExhExhortoIn.
- POST /exh_exhortos
Se recibe el esquema OneExhExhortoConfirmacionDatosExhortoRecibidoOut.
"""

import random
import string
import time
import unittest
from datetime import datetime

Expand Down
6 changes: 0 additions & 6 deletions tests/test_030_enviar_exhorto_archivos.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
"""
Unit test - Enviar los Archivos del Exhorto
Se manda exhortoOrigenId y el archivo
- POST /exh_exhortos_archivos/upload
Se recibe el esquema OneExhExhortoArchivoFileOut.
"""

import time
Expand Down
7 changes: 0 additions & 7 deletions tests/test_040_consultar_exhorto.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
"""
Unit test - Consultar Exhorto
Consultar exhorto enviado al PJ exhortado para ver su información.
- DEBE CONFIGURAR en las variables de entorno FOLIO_SEGUIMIENTO
- GET /exh_exhortos/{FOLIO_SEGUIMIENTO}
- Se recibe el esquema OneExhExhortoOut.
"""

import unittest
Expand Down
9 changes: 0 additions & 9 deletions tests/test_051_enviar_respuesta.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
"""
Unit test - Enviar Respuesta
Se envían los datos que conforman la respuesta del exhorto.
- DEBE CONFIGURAR en las variables de entorno FOLIO_SEGUIMIENTO
- Se manda el esquema ExhExhortoRecibirRespuestaIn que contiene archivos (ExhExhortoArchivoIn) y videos (ExhExhortoVideoIn).
- POST /exh_exhortos/responder
- Se recibe el esquema OneExhExhortoRecibirRespuestaOut.
"""

import random
import string
import time
import unittest
from datetime import datetime

Expand Down
8 changes: 0 additions & 8 deletions tests/test_052_enviar_respuesta_archivos.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
"""
Unit test - Enviar los Archivos de la Respuesta
Se envían los documentos que conforman la respuesta del exhorto.
- DEBE CONFIGURAR en las variables de entorno FOLIO_SEGUIMIENTO
- Se envía exhortoOrigenId, respuestaOrigenId y el archivo
- POST /exh_exhortos_archivos/responder_upload
- Se recibe el esquema OneExhExhortoArchivoRecibirRespuestaExhortoDataOut.
"""

import time
Expand Down
5 changes: 0 additions & 5 deletions tests/test_060_enviar_actualizacion.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
"""
Unit test - Enviar Actualización
Se puede realizar este proceso cuando el exhorto llega a una Oficialía y se turna a un Juzgado.
Se manda el esquema ExhExhortoActualizarIn.
"""

import random
Expand Down
2 changes: 0 additions & 2 deletions tests/test_071_enviar_promocion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
Unit test - Enviar Promoción
Se pueden enviar o recibir promociones sobre exhortos radicados.
"""

import random
Expand Down
2 changes: 0 additions & 2 deletions tests/test_072_enviar_promocion_archivos.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""
Unit test - Enviar Archivos de la Promoción
Se pueden enviar o recibir promociones sobre exhortos radicados.
"""

import time
Expand Down

0 comments on commit c14592a

Please sign in to comment.