ScoDoc/tests/api/test_api_formsemestre.py

335 lines
10 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""Test Logos
Utilisation :
créer les variables d'environnement: (indiquer les valeurs
pour le serveur ScoDoc que vous voulez interroger)
export SCODOC_URL="https://scodoc.xxx.net/"
export SCODOC_USER="xxx"
export SCODOC_PASSWD="xxx"
export CHECK_CERTIFICATE=0 # ou 1 si serveur de production avec certif SSL valide
(on peut aussi placer ces valeurs dans un fichier .env du répertoire tests/api).
Lancer :
pytest tests/api/test_api_formsemestre.py
"""
import requests
2022-05-05 20:06:49 +02:00
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 (
MODIMPL_FIELDS,
verify_fields,
EVAL_FIELDS,
SAISIE_NOTES_FIELDS,
)
2022-05-05 20:06:49 +02:00
from tests.api.tools_test_api import FSEM_FIELDS, UE_FIELDS, MODULE_FIELDS
2022-05-11 00:59:51 +02:00
# Etudiant pour les tests
ETUDID = 1
NIP = "1"
INE = "INE1"
def test_formsemestre(api_headers):
"""
2022-05-05 19:50:09 +02:00
Route: /formsemestre/<id>
"""
r = requests.get(
API_URL + "/formsemestre/1",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
formsemestre = r.json()
2022-05-05 19:50:09 +02:00
assert verify_fields(formsemestre, FSEM_FIELDS)
def test_etudiant_bulletin(api_headers):
"""
Route:
"""
2022-05-05 20:06:49 +02:00
formsemestre_id = 1
r = requests.get(
2022-05-05 20:06:49 +02:00
f"{API_URL}/etudiant/etudid/1/formsemestre/{formsemestre_id}/bulletin",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
2022-05-05 20:06:49 +02:00
bull_a = r.json()
r = requests.get(
2022-05-11 00:59:51 +02:00
f"{API_URL}/etudiant/nip/{NIP}/formsemestre/{formsemestre_id}/bulletin",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
2022-05-05 20:06:49 +02:00
bull_b = r.json()
r = requests.get(
2022-05-11 00:59:51 +02:00
f"{API_URL}/etudiant/ine/{INE}/formsemestre/{formsemestre_id}/bulletin",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
2022-05-05 20:06:49 +02:00
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):
"""
Route:
"""
r = requests.get(
API_URL + "/formsemestre/1/bulletins",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
# # jury
# def test_jury():
# r = requests.get(
# API_URL + "/formsemestre/1/jury",
# headers=api_headers,
# verify=CHECK_CERTIFICATE,
# )
# assert r.status_code == 200
2022-05-05 20:06:49 +02:00
def test_formsemestre_programme(api_headers):
"""
2022-05-05 20:06:49 +02:00
Route: /formsemestre/1/programme
"""
r = requests.get(
API_URL + "/formsemestre/1/programme",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
2022-05-05 20:06:49 +02:00
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]
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)
# def test_formsemestre_etudiants(api_headers):
# """
# Route: /formsemestre/<int:formsemestre_id>/etudiants, /formsemestre/<int:formsemestre_id>/etudiants/demissionnaires, /formsemestre/<int:formsemestre_id>/etudiants/defaillants
# """
# r = requests.get(
# API_URL + "/formsemestre/<int:formsemestre_id>/etudiants",
# headers=api_headers,
# verify=CHECK_CERTIFICATE,
# )
# assert r.status_code == 200
#
# r = requests.get(
# API_URL + "/formsemestre/<int:formsemestre_id>/etudiants/demissionnaires",
# headers=api_headers,
# verify=CHECK_CERTIFICATE,
# )
# assert r.status_code == 200
#
# r = requests.get(
# API_URL + "/formsemestre/<int:formsemestre_id>/etudiants/defaillants",
# headers=api_headers,
# verify=CHECK_CERTIFICATE,
# )
# assert r.status_code == 200
def test_etat_evals(
api_headers,
): # XXX TODO Vérifier les champs, vérifier qu'il n'y a pas de répétition, vérifier que les dates de "saisie_notes" sont corrects (date_debut avant celle de fin mediane OK etc..)
"""
Route : /formsemestre/<int:formsemestre_id>/etat_evals
"""
r = requests.get(
API_URL + "/formsemestre/1/etat_evals",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
etat_evals = r.json()
assert len(etat_evals) == 3
ue = etat_evals[0]
assert len(ue) == 3
assert isinstance(ue["id"], int)
assert isinstance(ue["titre"], str)
assert isinstance(ue["evaluations"], list)
eval = ue["evaluations"][0]
assert len(eval) == 11
assert verify_fields(eval, EVAL_FIELDS)
assert isinstance(eval["id"], int)
assert eval["description"] is None or isinstance(eval["description"], str)
assert isinstance(eval["datetime_epreuve"], str)
assert isinstance(eval["heure_fin"], str)
assert isinstance(eval["coef"], float)
assert isinstance(eval["comptee"], str)
assert isinstance(eval["inscrits"], int)
assert isinstance(eval["manquantes"], int)
assert isinstance(eval["ABS"], int)
assert isinstance(eval["ATT"], int)
assert isinstance(eval["EXC"], int)
assert isinstance(eval["saisie_notes"], list)
list_eval_id = [e["id"] for e in ue["evaluations"]]
all_unique = True
for id in list_eval_id:
if list_eval_id.count(id) > 1:
all_unique = False
assert all_unique is True
saisie_notes = eval["saisie_notes"]
assert verify_fields(saisie_notes, SAISIE_NOTES_FIELDS)
assert isinstance(eval["saisie_notes"]["datetime_debut"], str)
assert isinstance(eval["saisie_notes"]["datetime_fin"], str)
assert isinstance(eval["saisie_notes"]["datetime_mediane"], str)
assert (
eval["saisie_notes"]["datetime_fin"] > eval["saisie_notes"]["datetime_mediane"]
)
assert eval["saisie_notes"]["datetime_fin"] > eval["saisie_notes"]["datetime_debut"]
assert (
eval["saisie_notes"]["datetime_mediane"]
> eval["saisie_notes"]["datetime_debut"]
)
ue2 = etat_evals[1]
assert len(ue2) == 3
assert isinstance(ue2["id"], int)
assert isinstance(ue2["titre"], str)
assert isinstance(ue2["evaluations"], list)
eval2 = ue2["evaluations"][0]
assert len(eval2) == 11
assert verify_fields(eval2, EVAL_FIELDS)
assert isinstance(eval2["id"], int)
assert eval2["description"] is None or isinstance(eval2["description"], str)
assert isinstance(eval2["datetime_epreuve"], str)
assert isinstance(eval2["heure_fin"], str)
assert isinstance(eval2["coef"], float)
assert isinstance(eval2["comptee"], str)
assert isinstance(eval2["inscrits"], int)
assert isinstance(eval2["manquantes"], int)
assert isinstance(eval2["ABS"], int)
assert isinstance(eval2["ATT"], int)
assert isinstance(eval2["EXC"], int)
assert isinstance(eval2["saisie_notes"], list)
list_eval_id2 = [e["id"] for e in ue["evaluations"]]
all_unique2 = True
for id in list_eval_id2:
if list_eval_id2.count(id) > 1:
all_unique2 = False
assert all_unique2 is True
saisie_notes2 = eval2["saisie_notes"]
assert verify_fields(saisie_notes2, SAISIE_NOTES_FIELDS)
assert isinstance(eval2["saisie_notes"]["datetime_debut"], str)
assert isinstance(eval2["saisie_notes"]["datetime_fin"], str)
assert isinstance(eval2["saisie_notes"]["datetime_mediane"], str)
assert (
eval2["saisie_notes"]["datetime_fin"]
> eval2["saisie_notes"]["datetime_mediane"]
)
assert (
eval2["saisie_notes"]["datetime_fin"] > eval2["saisie_notes"]["datetime_debut"]
)
assert (
eval2["saisie_notes"]["datetime_mediane"]
> eval2["saisie_notes"]["datetime_debut"]
)
ue3 = etat_evals[2]
assert len(ue3) == 3
assert isinstance(ue3["id"], int)
assert isinstance(ue3["titre"], str)
assert isinstance(ue3["evaluations"], list)
eval3 = ue3["evaluations"][0]
assert len(eval3) == 11
assert verify_fields(eval3, EVAL_FIELDS)
assert isinstance(eval3["id"], int)
assert eval3["description"] is None or isinstance(eval3["description"], str)
assert isinstance(eval3["datetime_epreuve"], str)
assert isinstance(eval3["heure_fin"], str)
assert isinstance(eval3["coef"], float)
assert isinstance(eval3["comptee"], str)
assert isinstance(eval3["inscrits"], int)
assert isinstance(eval3["manquantes"], int)
assert isinstance(eval3["ABS"], int)
assert isinstance(eval3["ATT"], int)
assert isinstance(eval3["EXC"], int)
assert isinstance(eval3["saisie_notes"], list)
list_eval_id3 = [e["id"] for e in ue["evaluations"]]
all_unique3 = True
for id in list_eval_id3:
if list_eval_id3.count(id) > 1:
all_unique3 = False
assert all_unique3 is True
saisie_notes3 = eval2["saisie_notes"]
assert verify_fields(saisie_notes3, SAISIE_NOTES_FIELDS)
assert isinstance(eval3["saisie_notes"]["datetime_debut"], str)
assert isinstance(eval3["saisie_notes"]["datetime_fin"], str)
assert isinstance(eval3["saisie_notes"]["datetime_mediane"], str)
assert (
eval3["saisie_notes"]["datetime_fin"]
> eval3["saisie_notes"]["datetime_mediane"]
)
assert (
eval3["saisie_notes"]["datetime_fin"] > eval3["saisie_notes"]["datetime_debut"]
)
assert (
eval3["saisie_notes"]["datetime_mediane"]
> eval3["saisie_notes"]["datetime_debut"]
)
assert ue["id"] != ue2["id"]
assert ue["id"] != ue3["id"]
assert ue2["id"] != ue3["id"]
assert ue["titre"] != ue2["titre"]
assert ue["titre"] != ue3["titre"]
assert ue2["titre"] != ue3["titre"]
##### ERROR #####
fake_eval_id = 153165161656849846516511321651651
r = requests.get(
f"{API_URL}/formsemestre/{fake_eval_id}/etat_evals",
headers=api_headers,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 404