Add unit test for sco_find_etud.

This commit is contained in:
Emmanuel Viennet 2023-10-23 23:50:13 +02:00
parent 9bc0111ceb
commit b78e1b8be4
5 changed files with 66 additions and 49 deletions

View File

@ -219,26 +219,27 @@ _identiteEditor = ndb.EditableTable(
"identite", "identite",
"etudid", "etudid",
( (
"etudid", "admission_id",
"nom", "boursier",
"nom_usuel",
"prenom",
"prenom_etat_civil",
"cas_id",
"cas_allow_login", "cas_allow_login",
"cas_allow_scodoc_login", "cas_allow_scodoc_login",
"civilite", # 'M", "F", or "X" "cas_id",
"civilite_etat_civil", "civilite_etat_civil",
"date_naissance", "civilite", # 'M", "F", or "X"
"lieu_naissance",
"dept_naissance",
"nationalite",
"statut",
"boursier",
"foto",
"photo_filename",
"code_ine", "code_ine",
"code_nip", "code_nip",
"date_naissance",
"dept_naissance",
"etudid",
"foto",
"lieu_naissance",
"nationalite",
"nom_usuel",
"nom",
"photo_filename",
"prenom_etat_civil",
"prenom",
"statut",
), ),
filter_dept=True, filter_dept=True,
sortkey="nom", sortkey="nom",
@ -300,7 +301,7 @@ def check_nom_prenom_homonyms(
prenom = prenom.lower().strip() prenom = prenom.lower().strip()
# Don't allow some special cars (eg used in sql regexps) # Don't allow some special cars (eg used in sql regexps)
if scu.FORBIDDEN_CHARS_EXP.search(nom) or scu.FORBIDDEN_CHARS_EXP.search(prenom): if scu.FORBIDDEN_CHARS_EXP.search(nom) or scu.FORBIDDEN_CHARS_EXP.search(prenom):
return False, 0 return False, []
# Liste homonymes (dans tous les départements): # Liste homonymes (dans tous les départements):
query = Identite.query.filter( query = Identite.query.filter(
Identite.nom.ilike(nom + "%"), Identite.prenom.ilike(prenom + "%") Identite.nom.ilike(nom + "%"), Identite.prenom.ilike(prenom + "%")
@ -566,7 +567,7 @@ admission_edit = _admissionEditor.edit
# Edition simultanee de identite et admission # Edition simultanee de identite et admission
class EtudIdentEditor(object): class EtudIdentEditor:
def create(self, cnx, args): def create(self, cnx, args):
admission_id = admission_create(cnx, args) admission_id = admission_create(cnx, args)
args["admission_id"] = admission_id args["admission_id"] = admission_id

View File

@ -99,6 +99,26 @@ def form_search_etud(
return "\n".join(H) return "\n".join(H)
def search_etuds_infos_from_exp(expnom: str = "") -> list[dict]:
"""Cherche étudiants, expnom peut être, dans cet ordre:
un etudid (int), un code NIP, ou le début d'un nom.
"""
if not isinstance(expnom, int) and len(expnom) <= 1:
return [] # si expnom est trop court, n'affiche rien
try:
etudid = int(expnom)
except ValueError:
etudid = None
if etudid is not None:
etuds = sco_etud.get_etud_info(filled=True, etudid=expnom)
if len(etuds) == 1:
return etuds
expnom_str = str(expnom)
if scu.is_valid_code_nip(expnom_str):
return search_etuds_infos(code_nip=expnom_str)
return search_etuds_infos(expnom=expnom_str)
def search_etud_in_dept(expnom=""): def search_etud_in_dept(expnom=""):
"""Page recherche d'un etudiant. """Page recherche d'un etudiant.
@ -111,21 +131,7 @@ def search_etud_in_dept(expnom=""):
Args: Args:
expnom: string, regexp sur le nom ou un code_nip ou un etudid expnom: string, regexp sur le nom ou un code_nip ou un etudid
""" """
if isinstance(expnom, int) or len(expnom) > 1: etuds = search_etuds_infos_from_exp(expnom)
try:
etudid = int(expnom)
except ValueError:
etudid = None
if etudid is not None:
etuds = sco_etud.get_etud_info(filled=True, etudid=expnom)
if (etudid is None) or len(etuds) != 1:
expnom_str = str(expnom)
if scu.is_valid_code_nip(expnom_str):
etuds = search_etuds_infos(code_nip=expnom_str)
else:
etuds = search_etuds_infos(expnom=expnom_str)
else:
etuds = [] # si expnom est trop court, n'affiche rien
if request.method == "POST": if request.method == "POST":
vals = request.form vals = request.form

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.6.47" SCOVERSION = "9.6.48"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"

View File

@ -16,7 +16,7 @@ import app
from app import db from app import db
from app.models import Admission, Adresse, Departement, FormSemestre, Identite from app.models import Admission, Adresse, Departement, FormSemestre, Identite
from app.scodoc import sco_etud from app.scodoc import sco_etud
from app.scodoc import sco_import_etuds from app.scodoc import sco_find_etud, sco_import_etuds
from config import TestConfig from config import TestConfig
from tests.unit import setup, dict_include from tests.unit import setup, dict_include
@ -267,7 +267,7 @@ def test_import_etuds_xlsx(test_client):
"civilite_etat_civil": "F", "civilite_etat_civil": "F",
"civilite": "X", "civilite": "X",
"code_ine": "ine10", "code_ine": "ine10",
"code_nip": "nip10", "code_nip": "1000010",
"date_naissance": "", "date_naissance": "",
"dept_acronym": "TEST_", "dept_acronym": "TEST_",
"dept_naissance": "", "dept_naissance": "",
@ -302,7 +302,7 @@ def test_import_etuds_xlsx(test_client):
"civilite_etat_civil": "F", "civilite_etat_civil": "F",
"civilite": "X", "civilite": "X",
"code_ine": "ine10", "code_ine": "ine10",
"code_nip": "nip10", "code_nip": "1000010",
"date_naissance": "", "date_naissance": "",
"dept_acronym": "TEST_", "dept_acronym": "TEST_",
"dept_naissance": "", "dept_naissance": "",
@ -367,3 +367,13 @@ def test_import_etuds_xlsx(test_client):
"telephonemobilestr": "", "telephonemobilestr": "",
}, },
) )
# Test de search_etud_in_dept
etuds = sco_find_etud.search_etuds_infos_from_exp("NOM10")
assert len(etuds) == 1
assert etuds[0]["code_ine"] == "ine10"
etuds = sco_find_etud.search_etuds_infos_from_exp("NOM")
assert len(etuds) > 1
assert all(e["nom"].startswith("NOM") for e in etuds)
etuds = sco_find_etud.search_etuds_infos_from_exp("1000010")
assert len(etuds) == 1
assert etuds[0]["code_ine"] == "ine10"