forked from ScoDoc/ScoDoc
Test unitaire API partitions (à compléter)
This commit is contained in:
parent
1f4cb5700e
commit
03e30b4e65
@ -19,7 +19,13 @@ Utilisation :
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from tests.api.setup_test_api import API_URL, CHECK_CERTIFICATE, api_headers
|
from tests.api.setup_test_api import (
|
||||||
|
API_URL,
|
||||||
|
CHECK_CERTIFICATE,
|
||||||
|
GET,
|
||||||
|
POST_JSON,
|
||||||
|
api_headers,
|
||||||
|
)
|
||||||
from tests.api.tools_test_api import (
|
from tests.api.tools_test_api import (
|
||||||
verify_fields,
|
verify_fields,
|
||||||
PARTITIONS_FIELDS,
|
PARTITIONS_FIELDS,
|
||||||
@ -35,18 +41,10 @@ def test_partition(api_headers):
|
|||||||
- /partition/<int:partition_id>
|
- /partition/<int:partition_id>
|
||||||
"""
|
"""
|
||||||
partition_id = 1
|
partition_id = 1
|
||||||
r = requests.get(
|
partition = GET(f"/partition/{partition_id}", headers=api_headers)
|
||||||
f"{API_URL}/partition/{partition_id}",
|
|
||||||
headers=api_headers,
|
|
||||||
verify=CHECK_CERTIFICATE,
|
|
||||||
)
|
|
||||||
assert r.status_code == 200
|
|
||||||
partition = r.json()
|
|
||||||
assert isinstance(partition, dict)
|
assert isinstance(partition, dict)
|
||||||
assert verify_fields(partition, PARTITIONS_FIELDS) is True
|
assert verify_fields(partition, PARTITIONS_FIELDS) is True
|
||||||
assert partition_id == partition["id"]
|
assert partition_id == partition["id"]
|
||||||
|
|
||||||
assert isinstance(partition["id"], int)
|
|
||||||
assert isinstance(partition["id"], int)
|
assert isinstance(partition["id"], int)
|
||||||
assert isinstance(partition["formsemestre_id"], int)
|
assert isinstance(partition["formsemestre_id"], int)
|
||||||
assert partition["partition_name"] is None or isinstance(
|
assert partition["partition_name"] is None or isinstance(
|
||||||
@ -57,24 +55,68 @@ def test_partition(api_headers):
|
|||||||
assert isinstance(partition["show_in_lists"], bool)
|
assert isinstance(partition["show_in_lists"], bool)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
formsemestre_id = 1
|
||||||
|
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions", headers=api_headers)
|
||||||
|
# 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,
|
||||||
|
headers=api_headers,
|
||||||
|
)
|
||||||
|
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,
|
||||||
|
headers=api_headers,
|
||||||
|
)
|
||||||
|
assert isinstance(group_r, dict)
|
||||||
|
assert group_r["group_name"] == group_d["group_name"]
|
||||||
|
# --- Liste groupes de la partition
|
||||||
|
partition = GET(f"/partition/{partition_r['id']}", headers=api_headers)
|
||||||
|
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"]
|
||||||
|
|
||||||
|
# Delete partition
|
||||||
|
repl = POST_JSON(f"/partition/{partition_r['id']}/delete", headers=api_headers)
|
||||||
|
assert repl["OK"] is True
|
||||||
|
|
||||||
|
|
||||||
def test_etud_in_group(api_headers):
|
def test_etud_in_group(api_headers):
|
||||||
"""
|
"""
|
||||||
Test 'etud_in_group'
|
Test '/group/<int:group_id>/etudiants'
|
||||||
|
|
||||||
Routes :
|
Routes :
|
||||||
- /group/<int:group_id>/etudiants
|
- /group/<int:group_id>/etudiants
|
||||||
- /group/<int:group_id>/etudiants/query?etat=<string:etat>
|
- /group/<int:group_id>/etudiants/query?etat=<string:etat>
|
||||||
"""
|
"""
|
||||||
group_id = 1
|
group_id = 1
|
||||||
r = requests.get(
|
etudiants = GET(f"/group/{group_id}/etudiants", headers=api_headers)
|
||||||
f"{API_URL}/group/{group_id}/etudiants",
|
assert isinstance(etudiants, list)
|
||||||
headers=api_headers,
|
|
||||||
verify=CHECK_CERTIFICATE,
|
|
||||||
)
|
|
||||||
assert r.status_code == 200
|
|
||||||
assert isinstance(r.json(), list)
|
|
||||||
|
|
||||||
for etud in r.json():
|
for etud in etudiants:
|
||||||
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
||||||
assert isinstance(etud["id"], int)
|
assert isinstance(etud["id"], int)
|
||||||
assert isinstance(etud["dept_id"], int)
|
assert isinstance(etud["dept_id"], int)
|
||||||
@ -86,16 +128,11 @@ def test_etud_in_group(api_headers):
|
|||||||
assert isinstance(etud["code_ine"], str)
|
assert isinstance(etud["code_ine"], str)
|
||||||
|
|
||||||
etat = "I"
|
etat = "I"
|
||||||
r_etat = requests.get(
|
etudiants = GET(
|
||||||
f"{API_URL}/group/{group_id}/etudiants/query?etat={etat}",
|
f"/group/{group_id}/etudiants/query?etat={etat}", headers=api_headers
|
||||||
headers=api_headers,
|
|
||||||
verify=CHECK_CERTIFICATE,
|
|
||||||
)
|
)
|
||||||
assert r_etat.status_code == 200
|
assert isinstance(etudiants, list)
|
||||||
|
for etud in etudiants:
|
||||||
assert isinstance(r_etat.json(), list)
|
|
||||||
|
|
||||||
for etud in r_etat.json():
|
|
||||||
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS)
|
||||||
assert isinstance(etud["id"], int)
|
assert isinstance(etud["id"], int)
|
||||||
assert isinstance(etud["dept_id"], int)
|
assert isinstance(etud["dept_id"], int)
|
||||||
|
@ -75,7 +75,7 @@ def import_formation() -> Formation:
|
|||||||
|
|
||||||
|
|
||||||
def create_users(dept: Departement) -> tuple:
|
def create_users(dept: Departement) -> tuple:
|
||||||
"""créé les utilisateurs nécessaires aux tests"""
|
"""Crée les utilisateurs nécessaires aux tests"""
|
||||||
# Un utilisateur "test" (passwd test) pouvant lire l'API
|
# Un utilisateur "test" (passwd test) pouvant lire l'API
|
||||||
user = User(user_name="test", nom="Doe", prenom="John", dept=dept.acronym)
|
user = User(user_name="test", nom="Doe", prenom="John", dept=dept.acronym)
|
||||||
user.set_password("test")
|
user.set_password("test")
|
||||||
@ -91,6 +91,8 @@ def create_users(dept: Departement) -> tuple:
|
|||||||
# Edition billets
|
# Edition billets
|
||||||
perm_billets = Permission.get_by_name("ScoAbsAddBillet")
|
perm_billets = Permission.get_by_name("ScoAbsAddBillet")
|
||||||
role.add_permission(perm_billets)
|
role.add_permission(perm_billets)
|
||||||
|
perm_groups = Permission.get_by_name("ScoEtudChangeGroups")
|
||||||
|
role.add_permission(perm_groups)
|
||||||
db.session.add(role)
|
db.session.add(role)
|
||||||
|
|
||||||
user.add_role(role, None)
|
user.add_role(role, None)
|
||||||
@ -463,7 +465,7 @@ def add_absences(formsemestre: FormSemestre):
|
|||||||
|
|
||||||
def create_etape_apo(formsemestre: FormSemestre):
|
def create_etape_apo(formsemestre: FormSemestre):
|
||||||
"""
|
"""
|
||||||
Ajoute étape apoge au formsemestre
|
Ajoute étapes Apogée au formsemestre
|
||||||
"""
|
"""
|
||||||
etape_apo1 = FormSemestreEtape(
|
etape_apo1 = FormSemestreEtape(
|
||||||
id=1, formsemestre_id=formsemestre.id, etape_apo="A1"
|
id=1, formsemestre_id=formsemestre.id, etape_apo="A1"
|
||||||
|
Loading…
Reference in New Issue
Block a user