API Test: fix

This commit is contained in:
Emmanuel Viennet 2022-05-05 19:13:12 +02:00
parent be51032b8a
commit f8a3ef8bb5

View File

@ -16,26 +16,72 @@ Utilisation :
Lancer :
pytest tests/api/test_api_etudiants.py
"""
from random import randint
import requests
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
from tests.api.tools_test_api import verify_fields
# etudiants_courant
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",
}
def test_etudiants_courant(api_headers):
"""
Route: /etudiants/courant
"""
fields = [
"id",
"nip",
"nom",
"nom_usuel",
"prenom",
"civilite",
]
fields = {"id", "nip", "ine", "nom", "nom_usuel", "prenom", "civilite"}
r = requests.get(
API_URL + "/etudiants/courant",
@ -44,43 +90,12 @@ def test_etudiants_courant(api_headers):
)
assert r.status_code == 200
etudiants = r.json()
assert len(etudiants) == 16 # XXX HARDCODED
assert len(etudiants) > 0
etud = etudiants[-1]
fields_ok = verify_fields(etud, fields)
assert fields_ok is True
assert verify_fields(etud, fields) is True
########## Version long ################
fields_long = [
"civilite",
"code_ine",
"code_nip",
"date_naissance",
"email",
"emailperso",
"etudid",
"nom",
"prenom",
"nomprenom",
"lieu_naissance",
"dept_naissance",
"nationalite",
"boursier",
"id",
"codepostaldomicile",
"paysdomicile",
"telephonemobile",
"typeadresse",
"domicile",
"villedomicile",
"telephone",
"fax",
"description",
]
r = requests.get(
API_URL + "/etudiants/courant/long",
headers=api_headers,
@ -91,41 +106,13 @@ def test_etudiants_courant(api_headers):
assert len(etudiants) == 16 # HARDCODED
etud = etudiants[-1]
fields_ok = verify_fields(etud, fields_long)
assert fields_ok is True
assert verify_fields(etud, ETUD_FIELDS) is True
def test_etudiant(api_headers):
"""
Route:
"""
fields = [
"civilite",
"code_ine",
"code_nip",
"date_naissance",
"email",
"emailperso",
"etudid",
"nom",
"prenom",
"nomprenom",
"lieu_naissance",
"dept_naissance",
"nationalite",
"boursier",
"id",
"domicile",
"villedomicile",
"telephone",
"fax",
"description",
"codepostaldomicile",
"paysdomicile",
"telephonemobile",
"typeadresse",
]
######### Test etudid #########
r = requests.get(
@ -135,10 +122,8 @@ def test_etudiant(api_headers):
)
assert r.status_code == 200
etud = r.json()
assert len(etud) == 24 # ? HARDCODED
fields_ok = verify_fields(etud, fields)
assert fields_ok is True
assert verify_fields(etud, ETUD_FIELDS) is True
######### Test code nip #########
@ -149,8 +134,7 @@ def test_etudiant(api_headers):
)
assert r.status_code == 200
etud = r.json()
assert len(etud) == 24
fields_ok = verify_fields(etud, fields)
fields_ok = verify_fields(etud, ETUD_FIELDS)
assert fields_ok is True
######### Test code ine #########
@ -163,7 +147,7 @@ def test_etudiant(api_headers):
assert r.status_code == 200
etud = r.json()
assert len(etud) == 24
fields_ok = verify_fields(etud, fields)
fields_ok = verify_fields(etud, ETUD_FIELDS)
assert fields_ok is True
@ -171,33 +155,6 @@ def test_etudiant_formsemestres(api_headers):
"""
Route: /etudiant/etudid/<etudid:int>/formsemestres
"""
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",
]
######### Test etudid #########
@ -211,9 +168,7 @@ def test_etudiant_formsemestres(api_headers):
assert len(formsemestres) == 1
formsemestre = formsemestres[0]
fields_ok = verify_fields(formsemestre, fields)
assert fields_ok is True
assert verify_fields(formsemestre, FSEM_FIELDS) is True
######### Test code nip #########
r = requests.get(
@ -226,9 +181,7 @@ def test_etudiant_formsemestres(api_headers):
assert len(formsemestres) == 1
formsemestre = formsemestres[0]
fields_ok = verify_fields(formsemestre, fields)
assert fields_ok is True
assert verify_fields(formsemestre, FSEM_FIELDS) is True
######### Test code ine #########
r = requests.get(
@ -241,9 +194,7 @@ def test_etudiant_formsemestres(api_headers):
assert len(formsemestres) == 1
formsemestre = formsemestres[0]
fields_ok = verify_fields(formsemestre, fields)
assert fields_ok is True
assert verify_fields(formsemestre, FSEM_FIELDS) is True
def test_etudiant_bulletin_semestre(api_headers):