forked from ScoDoc/ScoDoc
API: tests: factorisation du code
This commit is contained in:
parent
f2718635bb
commit
2d40932b50
@ -20,8 +20,7 @@ from app.scodoc.sco_permissions import Permission
|
||||
@token_permission_required(Permission.APIView)
|
||||
def etudiants_courant(long=False):
|
||||
"""
|
||||
Retourne la liste des étudiants inscrits dans un
|
||||
formsemestre actuellement en cours.
|
||||
Liste des étudiants inscrits dans un formsemestre actuellement en cours.
|
||||
|
||||
Exemple de résultat :
|
||||
[
|
||||
|
@ -33,7 +33,7 @@ DEPARTEMENT_FIELDS = [
|
||||
|
||||
def test_departements(api_headers):
|
||||
""" "
|
||||
Routes: /departements_ids, /departement
|
||||
Routes: /departements_ids, /departement, /departement/<string:dept>/formsemestres_ids
|
||||
|
||||
"""
|
||||
# --- Liste des ids
|
||||
@ -68,6 +68,19 @@ def test_departements(api_headers):
|
||||
dept_b = r.json()
|
||||
assert dept_a == dept_b
|
||||
|
||||
# Liste des formsemestres
|
||||
r = requests.get(
|
||||
f"{API_URL}/departement/{dept_a['acronym']}/formsemestres_ids",
|
||||
headers=api_headers,
|
||||
verify=CHECK_CERTIFICATE,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
dept_ids = r.json()
|
||||
assert isinstance(dept_ids, list)
|
||||
assert all(isinstance(x, int) for x in dept_ids)
|
||||
assert len(dept_ids) > 0
|
||||
assert dept_id in dept_ids
|
||||
|
||||
|
||||
def test_list_etudiants(api_headers):
|
||||
fields = {"id", "nip", "ine", "nom", "nom_usuel", "prenom", "civilite"}
|
||||
|
@ -21,60 +21,7 @@ import requests
|
||||
|
||||
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
||||
from tests.api.tools_test_api import verify_fields
|
||||
|
||||
ETUD_FIELDS = {
|
||||
"boursier",
|
||||
"civilite",
|
||||
"code_ine",
|
||||
"code_nip",
|
||||
"codepostaldomicile",
|
||||
"date_naissance",
|
||||
"dept_naissance",
|
||||
"description",
|
||||
"domicile",
|
||||
"email",
|
||||
"emailperso",
|
||||
"etudid",
|
||||
"id",
|
||||
"lieu_naissance",
|
||||
"nationalite",
|
||||
"nom",
|
||||
"nomprenom",
|
||||
"paysdomicile",
|
||||
"prenom",
|
||||
"telephone",
|
||||
"telephonemobile",
|
||||
"typeadresse",
|
||||
"villedomicile",
|
||||
}
|
||||
|
||||
FSEM_FIELDS = {
|
||||
"block_moyennes",
|
||||
"bul_bgcolor",
|
||||
"bul_hide_xml",
|
||||
"date_debut_iso",
|
||||
"date_debut",
|
||||
"date_fin_iso",
|
||||
"date_fin",
|
||||
"dept_id",
|
||||
"elt_annee_apo",
|
||||
"elt_sem_apo",
|
||||
"ens_can_edit_eval",
|
||||
"etat",
|
||||
"formation_id",
|
||||
"formsemestre_id",
|
||||
"gestion_compensation",
|
||||
"gestion_semestrielle",
|
||||
"id",
|
||||
"modalite",
|
||||
"resp_can_change_ens",
|
||||
"resp_can_edit",
|
||||
"responsables",
|
||||
"semestre_id",
|
||||
"titre_formation",
|
||||
"titre_num",
|
||||
"titre",
|
||||
}
|
||||
from tests.api.tools_test_api import ETUD_FIELDS, FSEM_FIELDS
|
||||
|
||||
|
||||
def test_etudiants_courant(api_headers):
|
||||
|
@ -21,9 +21,9 @@ import requests
|
||||
|
||||
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
||||
from tests.api.tools_test_api import verify_fields
|
||||
from tests.api.tools_test_api import FORMATION_FIELDS, MODIMPL_FIELDS
|
||||
|
||||
|
||||
# formations
|
||||
def test_formations_ids(api_headers):
|
||||
"""
|
||||
Route: /formations_ids
|
||||
@ -41,25 +41,10 @@ def test_formations_ids(api_headers):
|
||||
assert all(isinstance(x, int) for x in formations_ids)
|
||||
|
||||
|
||||
# formations_by_id
|
||||
def test_formations_by_id(api_headers):
|
||||
"""
|
||||
Route: /formation/<int:formation_id>
|
||||
"""
|
||||
fields = [
|
||||
"id",
|
||||
"acronyme",
|
||||
"titre_officiel",
|
||||
"formation_code",
|
||||
"code_specialite",
|
||||
"dept_id",
|
||||
"titre",
|
||||
"version",
|
||||
"type_parcours",
|
||||
"referentiel_competence_id",
|
||||
"formation_id",
|
||||
]
|
||||
|
||||
r = requests.get(
|
||||
API_URL + "/formation/1",
|
||||
headers=api_headers,
|
||||
@ -67,9 +52,7 @@ def test_formations_by_id(api_headers):
|
||||
)
|
||||
assert r.status_code == 200
|
||||
formation = r.json()
|
||||
|
||||
fields_ok = verify_fields(formation, fields)
|
||||
assert fields_ok is True
|
||||
assert verify_fields(formation, FORMATION_FIELDS) is True
|
||||
# TODO tester le contenu de certains champs
|
||||
|
||||
|
||||
@ -77,31 +60,14 @@ def test_formation_export(api_headers):
|
||||
"""
|
||||
Route: /formation/formation_export/<int:formation_id>
|
||||
"""
|
||||
fields = [
|
||||
"id",
|
||||
"acronyme",
|
||||
"titre_officiel",
|
||||
"formation_code",
|
||||
"code_specialite",
|
||||
"dept_id",
|
||||
"titre",
|
||||
"version",
|
||||
"type_parcours",
|
||||
"referentiel_competence_id",
|
||||
"formation_id",
|
||||
"ue",
|
||||
]
|
||||
r = requests.get(
|
||||
API_URL + "/formation/formation_export/1",
|
||||
headers=api_headers,
|
||||
verify=CHECK_CERTIFICATE,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
export_formation = r.json()
|
||||
|
||||
fields_ok = verify_fields(export_formation, fields)
|
||||
assert fields_ok is True
|
||||
assert verify_fields(export_formation, FORMATION_FIELDS) is True
|
||||
# TODO tester le contenu de certains champs
|
||||
|
||||
|
||||
@ -119,17 +85,6 @@ def test_moduleimpl(api_headers):
|
||||
"""
|
||||
Route: /formation/moduleimpl/<int:moduleimpl_id>
|
||||
"""
|
||||
fields = [
|
||||
"id",
|
||||
"formsemestre_id",
|
||||
"computation_expr",
|
||||
"module_id",
|
||||
"responsable_id",
|
||||
"moduleimpl_id",
|
||||
"ens",
|
||||
"module",
|
||||
]
|
||||
|
||||
r = requests.get(
|
||||
API_URL + "/formation/moduleimpl/1",
|
||||
headers=api_headers,
|
||||
@ -137,42 +92,10 @@ def test_moduleimpl(api_headers):
|
||||
)
|
||||
assert r.status_code == 200
|
||||
moduleimpl = r.json()
|
||||
|
||||
fields_ok = verify_fields(moduleimpl, fields)
|
||||
assert fields_ok is True
|
||||
assert verify_fields(moduleimpl, MODIMPL_FIELDS) is True
|
||||
# TODO tester le contenu de certains champs
|
||||
|
||||
|
||||
def test_moduleimpls_sem(api_headers):
|
||||
"""
|
||||
Route: /formation/moduleimpl/formsemestre/<int:formsemestre_id>/list
|
||||
"""
|
||||
fields = [
|
||||
"id",
|
||||
"formsemestre_id",
|
||||
"computation_expr",
|
||||
"module_id",
|
||||
"responsable_id",
|
||||
"moduleimpl_id",
|
||||
"ens",
|
||||
"module",
|
||||
"moduleimpl_id",
|
||||
"ens",
|
||||
]
|
||||
r = requests.get(
|
||||
API_URL + "/formation/moduleimpl/formsemestre/1/list",
|
||||
headers=api_headers,
|
||||
verify=CHECK_CERTIFICATE,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
moduleimpls = r.json()
|
||||
moduleimpl = moduleimpls[0]
|
||||
|
||||
fields_ok = verify_fields(moduleimpl, fields)
|
||||
assert len(moduleimpls) == 21 # XXX HARDCODED !
|
||||
assert fields_ok is True
|
||||
|
||||
|
||||
def test_referentiel_competences(api_headers):
|
||||
"""
|
||||
Route: "/formation/<int:formation_id>/referentiel_competences",
|
||||
|
@ -21,11 +21,12 @@ import requests
|
||||
|
||||
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
||||
from tests.api.tools_test_api import verify_fields
|
||||
from tests.api.tools_test_api import ETUD_FIELDS, FSEM_FIELDS
|
||||
|
||||
|
||||
def test_formsemestre(api_headers):
|
||||
"""
|
||||
Route:
|
||||
Route: /formsemestre/<id>
|
||||
"""
|
||||
r = requests.get(
|
||||
API_URL + "/formsemestre/1",
|
||||
@ -33,40 +34,8 @@ def test_formsemestre(api_headers):
|
||||
verify=CHECK_CERTIFICATE,
|
||||
)
|
||||
assert r.status_code == 200
|
||||
|
||||
formsemestre = r.json()
|
||||
|
||||
fields = [
|
||||
"date_fin",
|
||||
"resp_can_edit",
|
||||
"dept_id",
|
||||
"etat",
|
||||
"resp_can_change_ens",
|
||||
"id",
|
||||
"modalite",
|
||||
"ens_can_edit_eval",
|
||||
"formation_id",
|
||||
"gestion_compensation",
|
||||
"elt_sem_apo",
|
||||
"semestre_id",
|
||||
"bul_hide_xml",
|
||||
"elt_annee_apo",
|
||||
"titre",
|
||||
"block_moyennes",
|
||||
"scodoc7_id",
|
||||
"date_debut",
|
||||
"gestion_semestrielle",
|
||||
"bul_bgcolor",
|
||||
"formsemestre_id",
|
||||
"titre_num",
|
||||
"date_debut_iso",
|
||||
"date_fin_iso",
|
||||
"responsables",
|
||||
]
|
||||
|
||||
fields_ok = verify_fields(formsemestre, fields)
|
||||
|
||||
assert fields_ok is True
|
||||
assert verify_fields(formsemestre, FSEM_FIELDS)
|
||||
|
||||
|
||||
def test_etudiant_bulletin(api_headers):
|
||||
|
@ -12,3 +12,83 @@ def verify_fields(json_response: dict, expected_fields: set) -> bool:
|
||||
Retourne True ou False
|
||||
"""
|
||||
return all(field in json_response for field in expected_fields)
|
||||
|
||||
|
||||
ETUD_FIELDS = {
|
||||
"boursier",
|
||||
"civilite",
|
||||
"code_ine",
|
||||
"code_nip",
|
||||
"codepostaldomicile",
|
||||
"date_naissance",
|
||||
"dept_naissance",
|
||||
"description",
|
||||
"domicile",
|
||||
"email",
|
||||
"emailperso",
|
||||
"etudid",
|
||||
"id",
|
||||
"lieu_naissance",
|
||||
"nationalite",
|
||||
"nom",
|
||||
"nomprenom",
|
||||
"paysdomicile",
|
||||
"prenom",
|
||||
"telephone",
|
||||
"telephonemobile",
|
||||
"typeadresse",
|
||||
"villedomicile",
|
||||
}
|
||||
|
||||
FORMATION_FIELDS = {
|
||||
"id",
|
||||
"acronyme",
|
||||
"titre_officiel",
|
||||
"formation_code",
|
||||
"code_specialite",
|
||||
"dept_id",
|
||||
"titre",
|
||||
"version",
|
||||
"type_parcours",
|
||||
"referentiel_competence_id",
|
||||
"formation_id",
|
||||
}
|
||||
|
||||
FSEM_FIELDS = {
|
||||
"block_moyennes",
|
||||
"bul_bgcolor",
|
||||
"bul_hide_xml",
|
||||
"date_debut_iso",
|
||||
"date_debut",
|
||||
"date_fin_iso",
|
||||
"date_fin",
|
||||
"dept_id",
|
||||
"elt_annee_apo",
|
||||
"elt_sem_apo",
|
||||
"ens_can_edit_eval",
|
||||
"etat",
|
||||
"formation_id",
|
||||
"formsemestre_id",
|
||||
"gestion_compensation",
|
||||
"gestion_semestrielle",
|
||||
"id",
|
||||
"modalite",
|
||||
"resp_can_change_ens",
|
||||
"resp_can_edit",
|
||||
"responsables",
|
||||
"semestre_id",
|
||||
"titre_formation",
|
||||
"titre_num",
|
||||
"titre",
|
||||
}
|
||||
|
||||
MODIMPL_FIELDS = {
|
||||
"id",
|
||||
"formsemestre_id",
|
||||
"computation_expr",
|
||||
"module_id",
|
||||
"responsable_id",
|
||||
"moduleimpl_id",
|
||||
"ens",
|
||||
"module",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user