2022-03-09 16:52:07 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2022-08-05 17:05:24 +02:00
|
|
|
"""Test API : groupes et partitions
|
2022-03-09 16:52:07 +01:00
|
|
|
|
|
|
|
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_partitions.py
|
|
|
|
"""
|
|
|
|
|
2022-08-02 09:49:08 +02:00
|
|
|
from tests.api.setup_test_api import (
|
|
|
|
API_URL,
|
|
|
|
CHECK_CERTIFICATE,
|
|
|
|
GET,
|
|
|
|
POST_JSON,
|
|
|
|
api_headers,
|
|
|
|
)
|
2022-06-23 16:20:59 +02:00
|
|
|
from tests.api.tools_test_api import (
|
|
|
|
verify_fields,
|
|
|
|
PARTITIONS_FIELDS,
|
2022-07-29 16:19:40 +02:00
|
|
|
PARTITION_GROUPS_ETUD_FIELDS,
|
2022-06-23 16:20:59 +02:00
|
|
|
)
|
2022-05-03 16:15:04 +02:00
|
|
|
|
2022-03-09 16:52:07 +01:00
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def test_partition(api_headers):
|
|
|
|
"""
|
2022-05-06 16:05:34 +02:00
|
|
|
Test 'partition'
|
|
|
|
|
|
|
|
Route :
|
2022-07-29 16:19:40 +02:00
|
|
|
- /partition/<int:partition_id>
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2022-06-23 16:20:59 +02:00
|
|
|
partition_id = 1
|
2022-08-02 09:49:08 +02:00
|
|
|
partition = GET(f"/partition/{partition_id}", headers=api_headers)
|
2022-06-23 16:20:59 +02:00
|
|
|
assert isinstance(partition, dict)
|
|
|
|
assert verify_fields(partition, PARTITIONS_FIELDS) is True
|
2022-07-29 16:19:40 +02:00
|
|
|
assert partition_id == partition["id"]
|
2022-06-23 16:20:59 +02:00
|
|
|
assert isinstance(partition["id"], int)
|
|
|
|
assert isinstance(partition["formsemestre_id"], int)
|
|
|
|
assert partition["partition_name"] is None or isinstance(
|
|
|
|
partition["partition_name"], str
|
|
|
|
)
|
|
|
|
assert isinstance(partition["numero"], int)
|
|
|
|
assert isinstance(partition["bul_show_rank"], bool)
|
|
|
|
assert isinstance(partition["show_in_lists"], bool)
|
2022-04-13 12:39:10 +02:00
|
|
|
|
2022-05-03 16:15:04 +02:00
|
|
|
|
2022-08-02 09:49:08 +02:00
|
|
|
def test_formsemestre_partition(api_headers):
|
|
|
|
"""Test
|
|
|
|
/formsemestre/<int:formsemestre_id>/partitions
|
|
|
|
/formsemestre/<int:formsemestre_id>/partition/create
|
|
|
|
/partition/<int:partition_id>/group/create
|
|
|
|
/partition/<int:partition_id>
|
|
|
|
/partition/<int:partition_id/delete
|
2022-08-02 16:21:41 +02:00
|
|
|
/group/<int:group_id>/set_etudiant/<int:etudid>
|
2022-08-02 09:49:08 +02:00
|
|
|
"""
|
2022-08-02 16:21:41 +02:00
|
|
|
headers = api_headers
|
2022-08-02 09:49:08 +02:00
|
|
|
formsemestre_id = 1
|
2022-08-02 16:21:41 +02:00
|
|
|
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions", headers=headers)
|
2022-08-02 09:49:08 +02:00
|
|
|
# au départ, pas de partitions
|
|
|
|
assert partitions == {}
|
|
|
|
# --- Création partition
|
|
|
|
partition_d = {
|
|
|
|
"partition_name": "T&Dé",
|
|
|
|
"bul_show_rank": True,
|
|
|
|
"show_in_lists": True,
|
|
|
|
}
|
|
|
|
partition_r = POST_JSON(
|
|
|
|
f"/formsemestre/{formsemestre_id}/partition/create",
|
|
|
|
partition_d,
|
2022-08-02 16:21:41 +02:00
|
|
|
headers=headers,
|
2022-08-02 09:49:08 +02:00
|
|
|
)
|
|
|
|
assert isinstance(partition_r, dict)
|
|
|
|
assert partition_r["partition_name"] == partition_d["partition_name"]
|
|
|
|
assert partition_r["groups"] == {}
|
|
|
|
# --- Création Groupe
|
|
|
|
group_d = {"group_name": "Aé-&"}
|
|
|
|
group_r = POST_JSON(
|
|
|
|
f"/partition/{partition_r['id']}/group/create",
|
|
|
|
group_d,
|
2022-08-02 16:21:41 +02:00
|
|
|
headers=headers,
|
2022-08-02 09:49:08 +02:00
|
|
|
)
|
|
|
|
assert isinstance(group_r, dict)
|
|
|
|
assert group_r["group_name"] == group_d["group_name"]
|
|
|
|
# --- Liste groupes de la partition
|
2022-08-02 16:21:41 +02:00
|
|
|
partition = GET(f"/partition/{partition_r['id']}", headers=headers)
|
2022-08-02 09:49:08 +02:00
|
|
|
assert isinstance(partition, dict)
|
|
|
|
assert partition["id"] == partition_r["id"]
|
|
|
|
assert isinstance(partition["groups"], dict)
|
|
|
|
assert len(partition["groups"]) == 1
|
|
|
|
group = partition["groups"][str(group_r["id"])] # nb: str car clés json en string
|
|
|
|
assert group["group_name"] == group_d["group_name"]
|
|
|
|
|
2022-08-02 16:21:41 +02:00
|
|
|
# Place un étudiant dans le groupe
|
|
|
|
etud = GET(f"/formsemestre/{formsemestre_id}/etudiants", headers=headers)[0]
|
|
|
|
repl = POST_JSON(f"/group/{group['id']}/set_etudiant/{etud['id']}", headers=headers)
|
|
|
|
assert isinstance(repl, dict)
|
|
|
|
assert repl["group_id"] == group["id"]
|
|
|
|
assert repl["etudid"] == etud["id"]
|
|
|
|
#
|
|
|
|
etuds = GET(f"/group/{group['id']}/etudiants", headers=headers)
|
|
|
|
assert len(etuds) == 1
|
|
|
|
assert etuds[0]["id"] == etud["id"]
|
|
|
|
# Retire l'étudiant du groupe
|
|
|
|
repl = POST_JSON(
|
|
|
|
f"/group/{group['id']}/remove_etudiant/{etud['id']}", headers=headers
|
|
|
|
)
|
|
|
|
assert len(GET(f"/group/{group['id']}/etudiants", headers=headers)) == 0
|
|
|
|
|
|
|
|
# Le retire à nouveau ! (bug #465)
|
|
|
|
repl = POST_JSON(
|
|
|
|
f"/group/{group['id']}/remove_etudiant/{etud['id']}", headers=headers
|
|
|
|
)
|
|
|
|
assert repl["group_id"] == group["id"]
|
2022-08-02 09:49:08 +02:00
|
|
|
# Delete partition
|
2022-08-02 16:21:41 +02:00
|
|
|
repl = POST_JSON(f"/partition/{partition_r['id']}/delete", headers=headers)
|
2022-08-02 09:49:08 +02:00
|
|
|
assert repl["OK"] is True
|
|
|
|
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def test_etud_in_group(api_headers):
|
|
|
|
"""
|
2022-08-02 09:49:08 +02:00
|
|
|
Test '/group/<int:group_id>/etudiants'
|
2022-05-06 16:05:34 +02:00
|
|
|
|
|
|
|
Routes :
|
2022-07-29 16:19:40 +02:00
|
|
|
- /group/<int:group_id>/etudiants
|
|
|
|
- /group/<int:group_id>/etudiants/query?etat=<string:etat>
|
2022-05-04 23:11:20 +02:00
|
|
|
"""
|
2022-06-23 16:20:59 +02:00
|
|
|
group_id = 1
|
2022-08-10 07:24:54 +02:00
|
|
|
etuds = GET(f"/group/{group_id}/etudiants", headers=api_headers)
|
|
|
|
assert isinstance(etuds, list)
|
2022-06-23 16:20:59 +02:00
|
|
|
|
2022-08-10 07:24:54 +02:00
|
|
|
for etud in etuds:
|
2022-07-29 16:19:40 +02:00
|
|
|
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
|
|
|
assert isinstance(etud["id"], int)
|
|
|
|
assert isinstance(etud["dept_id"], int)
|
|
|
|
assert isinstance(etud["nom"], str)
|
|
|
|
assert isinstance(etud["prenom"], str)
|
|
|
|
assert etud["nom_usuel"] is None or isinstance(etud["nom_usuel"], str)
|
|
|
|
assert isinstance(etud["civilite"], str)
|
|
|
|
assert isinstance(etud["code_nip"], str)
|
|
|
|
assert isinstance(etud["code_ine"], str)
|
2022-06-23 16:20:59 +02:00
|
|
|
|
2022-08-10 07:24:54 +02:00
|
|
|
# query sans filtre:
|
|
|
|
etuds_query = GET(f"/group/{group_id}/etudiants/query", headers=api_headers)
|
|
|
|
assert etuds_query == etuds
|
|
|
|
|
2022-06-23 16:20:59 +02:00
|
|
|
etat = "I"
|
2022-08-10 07:24:54 +02:00
|
|
|
etuds = GET(f"/group/{group_id}/etudiants/query?etat={etat}", headers=api_headers)
|
|
|
|
assert isinstance(etuds, list)
|
|
|
|
for etud in etuds:
|
2022-07-29 16:19:40 +02:00
|
|
|
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
|
|
|
assert isinstance(etud["id"], int)
|
|
|
|
assert isinstance(etud["dept_id"], int)
|
|
|
|
assert isinstance(etud["nom"], str)
|
|
|
|
assert isinstance(etud["prenom"], str)
|
|
|
|
assert etud["nom_usuel"] is None or isinstance(etud["nom_usuel"], str)
|
|
|
|
assert isinstance(etud["civilite"], str)
|
2022-05-03 16:15:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
# # set_groups
|
2022-05-04 23:11:20 +02:00
|
|
|
# def test_set_groups(api_headers):
|
|
|
|
# """
|
2022-05-06 16:05:34 +02:00
|
|
|
# Test 'set_groups'
|
|
|
|
#
|
|
|
|
# Routes :
|
|
|
|
# - /partitions/set_groups/partition/<int:partition_id>/groups/<string:groups_id>/delete/<string:groups_to_delete>"
|
|
|
|
# "/create/<string:groups_to_create>
|
2022-05-04 23:11:20 +02:00
|
|
|
# """
|
2022-05-03 16:15:04 +02:00
|
|
|
# r = requests.get(
|
|
|
|
# SCODOC_URL
|
|
|
|
# + "/partitions/set_groups/partition/<int:partition_id>/groups/<string:groups_id>"
|
|
|
|
# "/delete/<string:groups_to_delete>/create/<string:groups_to_create>",
|
2022-05-04 23:11:20 +02:00
|
|
|
# headers=api_headers,
|
2022-05-03 16:15:04 +02:00
|
|
|
# verify=CHECK_CERTIFICATE,
|
|
|
|
# )
|
|
|
|
# assert r.status_code == 200
|