From 03e30b4e65da1cb121f64a821a9b7b9206105e19 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 2 Aug 2022 09:49:08 +0200 Subject: [PATCH] =?UTF-8?q?Test=20unitaire=20API=20partitions=20(=C3=A0=20?= =?UTF-8?q?compl=C3=A9ter)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/api/test_api_partitions.py | 93 +++++++++++++------ .../fakedatabase/create_test_api_database.py | 6 +- 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/tests/api/test_api_partitions.py b/tests/api/test_api_partitions.py index 9277b97f04..14bd2d7bd8 100644 --- a/tests/api/test_api_partitions.py +++ b/tests/api/test_api_partitions.py @@ -19,7 +19,13 @@ Utilisation : 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 ( verify_fields, PARTITIONS_FIELDS, @@ -35,18 +41,10 @@ def test_partition(api_headers): - /partition/ """ partition_id = 1 - r = requests.get( - f"{API_URL}/partition/{partition_id}", - headers=api_headers, - verify=CHECK_CERTIFICATE, - ) - assert r.status_code == 200 - partition = r.json() + partition = GET(f"/partition/{partition_id}", headers=api_headers) assert isinstance(partition, dict) assert verify_fields(partition, PARTITIONS_FIELDS) is True assert partition_id == partition["id"] - - assert isinstance(partition["id"], int) assert isinstance(partition["id"], int) assert isinstance(partition["formsemestre_id"], int) assert partition["partition_name"] is None or isinstance( @@ -57,24 +55,68 @@ def test_partition(api_headers): assert isinstance(partition["show_in_lists"], bool) +def test_formsemestre_partition(api_headers): + """Test + /formsemestre//partitions + /formsemestre//partition/create + /partition//group/create + /partition/ + /partition//etudiants' Routes : - /group//etudiants - /group//etudiants/query?etat= """ group_id = 1 - r = requests.get( - f"{API_URL}/group/{group_id}/etudiants", - headers=api_headers, - verify=CHECK_CERTIFICATE, - ) - assert r.status_code == 200 - assert isinstance(r.json(), list) + etudiants = GET(f"/group/{group_id}/etudiants", headers=api_headers) + assert isinstance(etudiants, list) - for etud in r.json(): + for etud in etudiants: assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS) assert isinstance(etud["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) etat = "I" - r_etat = requests.get( - f"{API_URL}/group/{group_id}/etudiants/query?etat={etat}", - headers=api_headers, - verify=CHECK_CERTIFICATE, + etudiants = GET( + f"/group/{group_id}/etudiants/query?etat={etat}", headers=api_headers ) - assert r_etat.status_code == 200 - - assert isinstance(r_etat.json(), list) - - for etud in r_etat.json(): + assert isinstance(etudiants, list) + for etud in etudiants: assert verify_fields(etud, PARTITION_GROUPS_ETUD_FIELDS) assert isinstance(etud["id"], int) assert isinstance(etud["dept_id"], int) diff --git a/tools/fakedatabase/create_test_api_database.py b/tools/fakedatabase/create_test_api_database.py index 41519e0c84..36c3dca057 100644 --- a/tools/fakedatabase/create_test_api_database.py +++ b/tools/fakedatabase/create_test_api_database.py @@ -75,7 +75,7 @@ def import_formation() -> Formation: 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 user = User(user_name="test", nom="Doe", prenom="John", dept=dept.acronym) user.set_password("test") @@ -91,6 +91,8 @@ def create_users(dept: Departement) -> tuple: # Edition billets perm_billets = Permission.get_by_name("ScoAbsAddBillet") role.add_permission(perm_billets) + perm_groups = Permission.get_by_name("ScoEtudChangeGroups") + role.add_permission(perm_groups) db.session.add(role) user.add_role(role, None) @@ -463,7 +465,7 @@ def add_absences(formsemestre: FormSemestre): def create_etape_apo(formsemestre: FormSemestre): """ - Ajoute étape apoge au formsemestre + Ajoute étapes Apogée au formsemestre """ etape_apo1 = FormSemestreEtape( id=1, formsemestre_id=formsemestre.id, etape_apo="A1"