diff --git a/tests/api/test_api_formsemestre.py b/tests/api/test_api_formsemestre.py index 99df59455f..ed6d2791d6 100644 --- a/tests/api/test_api_formsemestre.py +++ b/tests/api/test_api_formsemestre.py @@ -26,6 +26,7 @@ from tests.api.tools_test_api import ( verify_fields, EVAL_FIELDS, SAISIE_NOTES_FIELDS, + FORMSEMESTRE_ETUS_FIELDS, ) from tests.api.tools_test_api import FSEM_FIELDS, UE_FIELDS, MODULE_FIELDS @@ -81,30 +82,135 @@ def test_bulletins(api_headers): # assert r.status_code == 200 -# def test_formsemestre_etudiants(api_headers): -# """ -# Route: /formsemestre//etudiants, /formsemestre//etudiants/demissionnaires, /formsemestre//etudiants/defaillants -# """ -# r = requests.get( -# API_URL + "/formsemestre//etudiants", -# headers=api_headers, -# verify=CHECK_CERTIFICATE, -# ) -# assert r.status_code == 200 -# -# r = requests.get( -# API_URL + "/formsemestre//etudiants/demissionnaires", -# headers=api_headers, -# verify=CHECK_CERTIFICATE, -# ) -# assert r.status_code == 200 -# -# r = requests.get( -# API_URL + "/formsemestre//etudiants/defaillants", -# headers=api_headers, -# verify=CHECK_CERTIFICATE, -# ) -# assert r.status_code == 200 +def test_formsemestre_etudiants(api_headers): + """ + Route: /formsemestre//etudiants, + /formsemestre//etudiants/demissionnaires, + /formsemestre//etudiants/defaillants + """ + r = requests.get( + API_URL + "/formsemestre/1/etudiants", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r.status_code == 200 + formsemestre_etus = r.json() + assert isinstance(formsemestre_etus, list) + assert verify_fields(formsemestre_etus, FORMSEMESTRE_ETUS_FIELDS) is True + for etu in formsemestre_etus: + assert isinstance(etu["id"], int) + assert isinstance(etu["nip"], str) + assert isinstance(etu["ine"], str) + assert isinstance(etu["nom"], str) + assert etu["nom_usuel"] is None or isinstance(etu["nom_usuel"], str) + assert isinstance(etu["prenom"], str) + assert isinstance(etu["civilite"], str) + assert isinstance(etu["groups"], list) + etu_groups = etu["groups"] + for group in etu_groups: + assert isinstance(group["partition_id"], int) + assert isinstance(group["id"], int) + assert isinstance(group["formsemestre_id"], int) + assert group["partition_name"] is None or isinstance( + group["partition_name"], str + ) + assert isinstance(group["numero"], int) + assert isinstance(group["bul_show_rank"], bool) + assert isinstance(group["show_in_lists"], bool) + assert isinstance(group["group_id"], int) + assert group["group_name"] is None or isinstance(group["group_name"], int) + + ### demissionnaires ### + r_demissionnaires = requests.get( + API_URL + "/formsemestre//etudiants/demissionnaires", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r_demissionnaires.status_code == 200 + formsemestre_etus = r_demissionnaires.json() + assert isinstance(formsemestre_etus, list) + assert verify_fields(formsemestre_etus, FORMSEMESTRE_ETUS_FIELDS) is True + for etu in formsemestre_etus: + assert isinstance(etu["id"], int) + assert isinstance(etu["nip"], str) + assert isinstance(etu["ine"], str) + assert isinstance(etu["nom"], str) + assert etu["nom_usuel"] is None or isinstance(etu["nom_usuel"], str) + assert isinstance(etu["prenom"], str) + assert isinstance(etu["civilite"], str) + assert isinstance(etu["groups"], list) + etu_groups = etu["groups"] + for group in etu_groups: + assert isinstance(group["partition_id"], int) + assert isinstance(group["id"], int) + assert isinstance(group["formsemestre_id"], int) + assert group["partition_name"] is None or isinstance( + group["partition_name"], str + ) + assert isinstance(group["numero"], int) + assert isinstance(group["bul_show_rank"], bool) + assert isinstance(group["show_in_lists"], bool) + assert isinstance(group["group_id"], int) + assert group["group_name"] is None or isinstance(group["group_name"], int) + + ### defaillants ### + r_defaillants = requests.get( + API_URL + "/formsemestre//etudiants/defaillants", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r_defaillants.status_code == 200 + + formsemestre_etus = r_defaillants.json() + assert isinstance(formsemestre_etus, list) + assert verify_fields(formsemestre_etus, FORMSEMESTRE_ETUS_FIELDS) is True + for etu in formsemestre_etus: + assert isinstance(etu["id"], int) + assert isinstance(etu["nip"], str) + assert isinstance(etu["ine"], str) + assert isinstance(etu["nom"], str) + assert etu["nom_usuel"] is None or isinstance(etu["nom_usuel"], str) + assert isinstance(etu["prenom"], str) + assert isinstance(etu["civilite"], str) + assert isinstance(etu["groups"], list) + etu_groups = etu["groups"] + for group in etu_groups: + assert isinstance(group["partition_id"], int) + assert isinstance(group["id"], int) + assert isinstance(group["formsemestre_id"], int) + assert group["partition_name"] is None or isinstance( + group["partition_name"], str + ) + assert isinstance(group["numero"], int) + assert isinstance(group["bul_show_rank"], bool) + assert isinstance(group["show_in_lists"], bool) + assert isinstance(group["group_id"], int) + assert group["group_name"] is None or isinstance(group["group_name"], int) + + assert r != r_demissionnaires != r_defaillants is True + + ### ERROR ### + id_formsemestre_inexistant = 265165689619851621685 + r_error = requests.get( + f"{API_URL}/formsemestre/{id_formsemestre_inexistant}/etudiants", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r_error.status_code == 404 + + r_error_demissionnaires = requests.get( + f"{API_URL}/formsemestre/{id_formsemestre_inexistant}/etudiants/demissionnaires", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r_error_demissionnaires.status_code == 404 + + r_error_defaillants = requests.get( + f"{API_URL}/formsemestre/{id_formsemestre_inexistant}/etudiants/defaillants", + headers=api_headers, + verify=CHECK_CERTIFICATE, + ) + assert r_error_defaillants.status_code == 404 def test_formsemestre_programme(api_headers): diff --git a/tests/api/tools_test_api.py b/tests/api/tools_test_api.py index 7d5f03b6a4..41147cf526 100644 --- a/tests/api/tools_test_api.py +++ b/tests/api/tools_test_api.py @@ -534,3 +534,27 @@ ABSENCES_FIELDS = { } ABSENCES_GROUP_ETAT_FIELDS = {"etudid", "list_abs"} + + +FORMSEMESTRE_ETUS_FIELDS = { + "id", + "nip", + "ine", + "nom", + "nom_usuel", + "prenom", + "cvilite", + "groups", +} + +FORMSEMESTRE_ETUS_GROUPS_FIELDS = { + "partition_id", + "id", + "formsemestre_id", + "partition_name", + "numero", + "bul_show_rank", + "show_in_lists", + "group_id", + "group_name", +}