1
0
forked from ScoDoc/ScoDoc
ScoDoc-Front/tests/api/test_api_formsemestre.py

134 lines
3.4 KiB
Python
Raw Permalink 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
2022-05-05 20:06:49 +02:00
from tests.api.tools_test_api import MODIMPL_FIELDS, verify_fields
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)