forked from ScoDoc/ScoDoc
Add unit test for sco_find_etud.
This commit is contained in:
parent
9bc0111ceb
commit
b78e1b8be4
@ -219,26 +219,27 @@ _identiteEditor = ndb.EditableTable(
|
||||
"identite",
|
||||
"etudid",
|
||||
(
|
||||
"etudid",
|
||||
"nom",
|
||||
"nom_usuel",
|
||||
"prenom",
|
||||
"prenom_etat_civil",
|
||||
"cas_id",
|
||||
"admission_id",
|
||||
"boursier",
|
||||
"cas_allow_login",
|
||||
"cas_allow_scodoc_login",
|
||||
"civilite", # 'M", "F", or "X"
|
||||
"cas_id",
|
||||
"civilite_etat_civil",
|
||||
"date_naissance",
|
||||
"lieu_naissance",
|
||||
"dept_naissance",
|
||||
"nationalite",
|
||||
"statut",
|
||||
"boursier",
|
||||
"foto",
|
||||
"photo_filename",
|
||||
"civilite", # 'M", "F", or "X"
|
||||
"code_ine",
|
||||
"code_nip",
|
||||
"date_naissance",
|
||||
"dept_naissance",
|
||||
"etudid",
|
||||
"foto",
|
||||
"lieu_naissance",
|
||||
"nationalite",
|
||||
"nom_usuel",
|
||||
"nom",
|
||||
"photo_filename",
|
||||
"prenom_etat_civil",
|
||||
"prenom",
|
||||
"statut",
|
||||
),
|
||||
filter_dept=True,
|
||||
sortkey="nom",
|
||||
@ -300,7 +301,7 @@ def check_nom_prenom_homonyms(
|
||||
prenom = prenom.lower().strip()
|
||||
# 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):
|
||||
return False, 0
|
||||
return False, []
|
||||
# Liste homonymes (dans tous les départements):
|
||||
query = Identite.query.filter(
|
||||
Identite.nom.ilike(nom + "%"), Identite.prenom.ilike(prenom + "%")
|
||||
@ -566,7 +567,7 @@ admission_edit = _admissionEditor.edit
|
||||
|
||||
|
||||
# Edition simultanee de identite et admission
|
||||
class EtudIdentEditor(object):
|
||||
class EtudIdentEditor:
|
||||
def create(self, cnx, args):
|
||||
admission_id = admission_create(cnx, args)
|
||||
args["admission_id"] = admission_id
|
||||
|
@ -99,6 +99,26 @@ def form_search_etud(
|
||||
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=""):
|
||||
"""Page recherche d'un etudiant.
|
||||
|
||||
@ -111,21 +131,7 @@ def search_etud_in_dept(expnom=""):
|
||||
Args:
|
||||
expnom: string, regexp sur le nom ou un code_nip ou un etudid
|
||||
"""
|
||||
if isinstance(expnom, int) or len(expnom) > 1:
|
||||
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
|
||||
etuds = search_etuds_infos_from_exp(expnom)
|
||||
|
||||
if request.method == "POST":
|
||||
vals = request.form
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
SCOVERSION = "9.6.47"
|
||||
SCOVERSION = "9.6.48"
|
||||
|
||||
SCONAME = "ScoDoc"
|
||||
|
||||
|
Binary file not shown.
@ -16,7 +16,7 @@ import app
|
||||
from app import db
|
||||
from app.models import Admission, Adresse, Departement, FormSemestre, Identite
|
||||
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 tests.unit import setup, dict_include
|
||||
@ -267,7 +267,7 @@ def test_import_etuds_xlsx(test_client):
|
||||
"civilite_etat_civil": "F",
|
||||
"civilite": "X",
|
||||
"code_ine": "ine10",
|
||||
"code_nip": "nip10",
|
||||
"code_nip": "1000010",
|
||||
"date_naissance": "",
|
||||
"dept_acronym": "TEST_",
|
||||
"dept_naissance": "",
|
||||
@ -302,7 +302,7 @@ def test_import_etuds_xlsx(test_client):
|
||||
"civilite_etat_civil": "F",
|
||||
"civilite": "X",
|
||||
"code_ine": "ine10",
|
||||
"code_nip": "nip10",
|
||||
"code_nip": "1000010",
|
||||
"date_naissance": "",
|
||||
"dept_acronym": "TEST_",
|
||||
"dept_naissance": "",
|
||||
@ -367,3 +367,13 @@ def test_import_etuds_xlsx(test_client):
|
||||
"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"
|
||||
|
Loading…
Reference in New Issue
Block a user