DocScoDoc/tests/api/test_api_etudiants.py

179 lines
4.7 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_etudiants.py
"""
from random import randint
import requests
from tests.api.setup_test_api import SCODOC_URL, CHECK_CERTIFICATE, HEADERS
# etudiants
def test_etudiants():
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiants",
headers=HEADERS,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
assert len(r.json()) == 16
# Choisis aléatoirement un étudiant dans la liste des étudiants
etu = r.json()[randint(0, len(r.json())) - 1]
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",
]
fields_OK = True
# Vérifie si tous les champs sont bien présents
for field in etu:
if field not in fields:
fields_OK = False
assert fields_OK is True
# etudiants_courant
def test_etudiants_courant(): # XXX TODO pour Seb
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiants/courant",
headers=HEADERS,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
assert len(r.json()) == 16
# etudiant
def test_etudiant(): # XXX TODO pour Seb
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1",
headers=HEADERS,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
assert len(r.json()) == 24
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiant/nip/1",
headers=HEADERS, verify=CHECK_CERTIFICATE
)
assert r.status_code == 200
assert len(r.json()) == 24
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiant/ine/1",
headers=HEADERS, verify=CHECK_CERTIFICATE
)
assert r.status_code == 200
assert len(r.json()) == 24
# etudiant_formsemestres
def test_etudiant_formsemestres(): # XXX TODO pour Seb
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestres",
headers=HEADERS,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
assert len(r.json()) == 1
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/formsemestres",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200
#
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/ine/<int:ine>/formsemestres",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200
# etudiant_bulletin_semestre
# def test_etudiant_bulletin_semestre():
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/formsemestre/1/bulletin",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200
# assert len(r.json()) == 1
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/formsemestre/<int:formsemestre_id>/bulletin",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200
#
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/ine/<int:ine>/formsemestre/<int:formsemestre_id>/bulletin",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200
# etudiant_groups
def test_etudiant_groups():
r = requests.get(
SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1/semestre/1/groups",
headers=HEADERS,
verify=CHECK_CERTIFICATE,
)
assert r.status_code == 200
assert len(r.json()) == 1
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>/semestre/<int:formsemestre_id>/groups",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200
#
# r = requests.get(
# SCODOC_URL + "/ScoDoc/api/etudiant/ine/<int:ine>/semestre/<int:formsemestre_id>/groups",
# headers=HEADERS, verify=CHECK_CERTIFICATE
# )
# assert r.status_code == 200