From 4c7c6e1be04e107de2832fa007e90c1013f97bc3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 21 Feb 2023 15:28:42 +0100 Subject: [PATCH] Nouveau test unitaire sur les formsemestres --- .../yaml}/cursus_but_gb.yaml | 0 .../yaml}/cursus_but_geii_lyon.yaml | 0 .../yaml}/cursus_but_gmp_iutlm.yaml | 0 .../ressources/yaml/simple_formsemestres.yaml | 93 +++++++++++++++++++ tests/unit/test_formsemestre.py | 36 +++++++ tests/unit/yaml_setup.py | 11 ++- 6 files changed, 137 insertions(+), 3 deletions(-) rename tests/{unit => ressources/yaml}/cursus_but_gb.yaml (100%) rename tests/{unit => ressources/yaml}/cursus_but_geii_lyon.yaml (100%) rename tests/{unit => ressources/yaml}/cursus_but_gmp_iutlm.yaml (100%) create mode 100644 tests/ressources/yaml/simple_formsemestres.yaml create mode 100644 tests/unit/test_formsemestre.py diff --git a/tests/unit/cursus_but_gb.yaml b/tests/ressources/yaml/cursus_but_gb.yaml similarity index 100% rename from tests/unit/cursus_but_gb.yaml rename to tests/ressources/yaml/cursus_but_gb.yaml diff --git a/tests/unit/cursus_but_geii_lyon.yaml b/tests/ressources/yaml/cursus_but_geii_lyon.yaml similarity index 100% rename from tests/unit/cursus_but_geii_lyon.yaml rename to tests/ressources/yaml/cursus_but_geii_lyon.yaml diff --git a/tests/unit/cursus_but_gmp_iutlm.yaml b/tests/ressources/yaml/cursus_but_gmp_iutlm.yaml similarity index 100% rename from tests/unit/cursus_but_gmp_iutlm.yaml rename to tests/ressources/yaml/cursus_but_gmp_iutlm.yaml diff --git a/tests/ressources/yaml/simple_formsemestres.yaml b/tests/ressources/yaml/simple_formsemestres.yaml new file mode 100644 index 000000000..158e1ab38 --- /dev/null +++ b/tests/ressources/yaml/simple_formsemestres.yaml @@ -0,0 +1,93 @@ +# Définion de deux formsemestres dans la même formation, sans résultats +# pour tests unitaires formsemestre. + +Formation: + filename: scodoc_formation_BUT_GEII_lyon_v1.xml + # Association des UE aux compétences: + ues: + # S1 : Tronc commun GEII + 'UE11': + annee: BUT1 + competence: Concevoir + 'UE12': + annee: BUT1 + competence: Vérifier + + # S2 : Tronc commun GEII + 'UE21': + annee: BUT1 + competence: Concevoir + 'UE22': + annee: BUT1 + competence: Vérifier + + # S3 : Tronc commun GEII + 'UE31': + annee: BUT2 + competence: Concevoir + 'UE32': + annee: BUT2 + competence: Vérifier + 'UE33': + annee: BUT2 + competence: Maintenir + # S3 : Parcours EME + 'UE34EME': + annee: BUT2 + competence: Installer + parcours: EME + # S3 : Parcours ESE + 'UE34ESE': + annee: BUT2 + competence: Implanter + parcours: ESE + # S3 : Parcours AII + 'UE34AII': + annee: BUT2 + competence: Intégrer + parcours: AII + + # S4 : Tronc commun GEII + 'UE41': + annee: BUT2 + competence: Concevoir + 'UE42': + annee: BUT2 + competence: Vérifier + 'UE43': + annee: BUT2 + competence: Maintenir + # S4 : Parcours EME + 'UE44EME': + annee: BUT2 + competence: Installer + parcours: EME + # S4 : Parcours ESE + 'UE44ESE': + annee: BUT2 + competence: Implanter + parcours: ESE + # S4 : Parcours AII + 'UE44AII': + annee: BUT2 + competence: Intégrer + parcours: AII + + modules_parcours: + # cette section permet d'associer des modules à des parcours + # les codes modules peuvent être des regexp + EME: [ .*EME.* ] + ESE: [ .*ESE.* ] + AII: [ .*AII.* ] + +FormSemestres: + # S1 et S2 : + S1: + idx: 1 + date_debut: 2021-09-01 + date_fin: 2022-01-15 + S1b: + idx: 1 + date_debut: 2021-09-02 + date_fin: 2022-01-17 + diff --git a/tests/unit/test_formsemestre.py b/tests/unit/test_formsemestre.py new file mode 100644 index 000000000..3cb516afe --- /dev/null +++ b/tests/unit/test_formsemestre.py @@ -0,0 +1,36 @@ +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +""" Test création/accès/clonage formsemestre +""" +import pytest +from tests.unit import yaml_setup + +import app +from app.models import Formation +from app.scodoc import sco_formsemestre_edit +from config import TestConfig + +DEPT = TestConfig.DEPT_TEST + + +def test_formsemestres_associate_new_version(test_client): + """Test association à une nouvelle version du programme""" + app.set_sco_dept(DEPT) + # Construit la base de test GB une seule fois + # puis lance les tests de jury + yaml_setup.setup_from_yaml("tests/ressources/yaml/simple_formsemestres.yaml") + formation = Formation.query.filter_by(acronyme="BUT GEII", version=1).first() + formsemestres = formation.formsemestres.all() + # On a deux S1: + assert len(formsemestres) == 2 + assert {s.semestre_id for s in formsemestres} == {1} + # Les rattache à une nouvelle version de la formation: + formsemestre_ids = [s.id for s in formsemestres] + sco_formsemestre_edit.do_formsemestres_associate_new_version(formsemestre_ids) + new_formation: Formation = Formation.query.filter_by( + acronyme="BUT GEII", version=2 + ).first() + assert new_formation + assert formsemestres[0].formation_id == new_formation.id + assert formsemestres[1].formation_id == new_formation.id diff --git a/tests/unit/yaml_setup.py b/tests/unit/yaml_setup.py index 4d4c9257a..0f8544ff9 100644 --- a/tests/unit/yaml_setup.py +++ b/tests/unit/yaml_setup.py @@ -234,7 +234,10 @@ def setup_formsemestres(formation: Formation, doc: str): def inscrit_les_etudiants(formation: Formation, doc: dict): """Inscrit les étudiants dans chacun de leurs formsemestres""" - for nom, infos in doc["Etudiants"].items(): + etudiants = doc.get("Etudiants") + if not etudiants: + return + for nom, infos in etudiants.items(): etud = Identite.create_etud( dept_id=g.scodoc_dept_id, nom=nom, @@ -283,6 +286,8 @@ def setup_from_yaml(filename: str) -> dict: ) yaml_setup_but.associe_ues_et_parcours(formation, doc["Formation"]) setup_formsemestres(formation, doc) - inscrit_les_etudiants(formation, doc) - note_les_modules(doc) + etudiants = doc.get("Etudiants") + if etudiants: + inscrit_les_etudiants(formation, doc) + note_les_modules(doc) return doc