1
0
forked from ScoDoc/ScoDoc

API: test_api_formsemestre

This commit is contained in:
Emmanuel Viennet 2022-05-05 20:06:49 +02:00
parent 2d40932b50
commit 4ab43f59c1
2 changed files with 74 additions and 77 deletions

View File

@ -18,10 +18,11 @@ Utilisation :
"""
import requests
from app.api.formsemestres import formsemestre
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
from tests.api.tools_test_api import MODIMPL_FIELDS, verify_fields
from tests.api.tools_test_api import FSEM_FIELDS, UE_FIELDS, MODULE_FIELDS
def test_formsemestre(api_headers):
@ -42,26 +43,35 @@ def test_etudiant_bulletin(api_headers):
"""
Route:
"""
formsemestre_id = 1
r = requests.get(
API_URL + "/formsemestre/1/etudiant/etudid/1/bulletin",
f"{API_URL}/etudiant/etudid/1/formsemestre/{formsemestre_id}/bulletin",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
bull_a = r.json()
r = requests.get(
API_URL + "/formsemestre/1/etudiant/nip/1/bulletin",
f"{API_URL}/etudiant/nip/1/formsemestre/{formsemestre_id}/bulletin",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
bull_b = r.json()
r = requests.get(
API_URL + "/formsemestre/1/etudiant/ine/1/bulletin",
f"{API_URL}/etudiant/ine/1/formsemestre/{formsemestre_id}/bulletin",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
bull_c = r.json()
# elimine les dates de publication pour comparer les autres champs
del bull_a["date"]
del bull_b["date"]
del bull_c["date"]
assert bull_a == bull_b == bull_c
def test_bulletins(api_headers):
@ -85,67 +95,11 @@ def test_bulletins(api_headers):
# )
# assert r.status_code == 200
# TODO A revoir
def test_semestre_index(api_headers):
"""
Route: TODO
"""
ue_fields = [
"semestre_idx",
"type",
"formation_id",
"ue_code",
"id",
"ects",
"acronyme",
"is_external",
"numero",
"code_apogee",
"titre",
"coefficient",
"color",
"ue_id",
]
ressource_fields = [
"heures_tp",
"code_apogee",
"titre",
"coefficient",
"module_type",
"id",
"ects",
"abbrev",
"ue_id",
"code",
"formation_id",
"heures_cours",
"matiere_id",
"heures_td",
"semestre_id",
"numero",
"module_id",
]
sae_fields = [
"heures_tp",
"code_apogee",
"titre",
"coefficient",
"module_type",
"id",
"ects",
"abbrev",
"ue_id",
"code",
"formation_id",
"heures_cours",
"matiere_id",
"heures_td",
"semestre_id",
"numero",
"module_id",
]
def test_formsemestre_programme(api_headers):
"""
Route: /formsemestre/1/programme
"""
r = requests.get(
API_URL + "/formsemestre/1/programme",
@ -153,16 +107,22 @@ def test_semestre_index(api_headers):
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
assert len(r.json()) == 3
prog = r.json()
assert isinstance(prog, dict)
assert "ues" in prog
assert "modules" in prog
assert "ressources" in prog
assert "saes" in prog
assert isinstance(prog["ues"], list)
assert isinstance(prog["modules"], list)
ue = prog["ues"][0]
modules = prog["modules"]
# Il y a toujours au moins une SAE et une ressources dans notre base de test
ressource = prog["ressources"][0]
sae = prog["saes"][0]
ue = r.json()["ues"][0]
ressource = r.json()["ressources"][0]
sae = r.json()["saes"][0]
fields_ue_OK = verify_fields(ue, ue_fields)
fields_ressource_OK = verify_fields(ressource, ressource_fields)
fields_sae_OK = verify_fields(sae, sae_fields)
assert fields_ue_OK is True
assert fields_ressource_OK is True
assert fields_sae_OK is True
assert verify_fields(ue, UE_FIELDS)
if len(modules) > 1:
assert verify_fields(modules[0], MODIMPL_FIELDS)
assert verify_fields(ressource, MODIMPL_FIELDS)
assert verify_fields(sae, MODIMPL_FIELDS)

View File

@ -92,3 +92,40 @@ MODIMPL_FIELDS = {
"ens",
"module",
}
MODULE_FIELDS = {
"heures_tp",
"code_apogee",
"titre",
"coefficient",
"module_type",
"id",
"ects",
"abbrev",
"ue_id",
"code",
"formation_id",
"heures_cours",
"matiere_id",
"heures_td",
"semestre_id",
"numero",
"module_id",
}
UE_FIELDS = {
"semestre_idx",
"type",
"formation_id",
"ue_code",
"id",
"ects",
"acronyme",
"is_external",
"numero",
"code_apogee",
"titre",
"coefficient",
"color",
"ue_id",
}