147 lines
4.3 KiB
Python
147 lines
4.3 KiB
Python
# -*- 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, HEADERS, CHECK_CERTIFICATE
|
|
|
|
|
|
# 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"]
|
|
|
|
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():
|
|
r = requests.get(
|
|
SCODOC_URL + "/ScoDoc/api/etudiants/courant",
|
|
headers=HEADERS, verify=CHECK_CERTIFICATE
|
|
)
|
|
assert r.status_code == 200
|
|
assert len(r.json()) == 0
|
|
|
|
|
|
# etudiant
|
|
def test_etudiant():
|
|
r = requests.get(
|
|
SCODOC_URL + "/ScoDoc/api/etudiant/etudid/1",
|
|
headers=HEADERS, verify=CHECK_CERTIFICATE
|
|
)
|
|
assert r.status_code == 200
|
|
assert len(r.json()) == 10
|
|
|
|
# r = requests.get(
|
|
# SCODOC_URL + "/ScoDoc/api/etudiant/nip/<int:nip>",
|
|
# headers=HEADERS, verify=CHECK_CERTIFICATE
|
|
# )
|
|
# assert r.status_code == 200
|
|
# r = requests.get(
|
|
# SCODOC_URL + "/ScoDoc/api/etudiant/ine/<int:ine>",
|
|
# headers=HEADERS, verify=CHECK_CERTIFICATE
|
|
# )
|
|
# assert r.status_code == 200
|
|
|
|
|
|
# etudiant_formsemestres
|
|
def test_etudiant_formsemestres():
|
|
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
|