diff --git a/tests/api/make_samples.py b/tests/api/make_samples.py index e262052c..fd61346f 100644 --- a/tests/api/make_samples.py +++ b/tests/api/make_samples.py @@ -40,7 +40,6 @@ Le tout mis en forme au format markdown et rangé dans le répertoire DATA_DIR ( TODO: ajouter un argument au script permettant de ne générer qu'un seul fichier (exemple: `python make_samples.py nom_exemple`) """ -import numpy as np import os import shutil import sys diff --git a/tests/conftest.py b/tests/conftest.py index eb1a494f..f9e72a66 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -13,6 +13,8 @@ from app.auth.models import get_super_admin from app.scodoc import sco_bulletins_standard from app.scodoc import notesdb as ndb +RESOURCES_DIR = "/opt/scodoc/tests/ressources" + @pytest.fixture() def test_client(): diff --git a/tests/unit/formation-exemple-1.xml b/tests/ressources/formations/formation-exemple-1.xml similarity index 100% rename from tests/unit/formation-exemple-1.xml rename to tests/ressources/formations/formation-exemple-1.xml diff --git a/tests/unit/config_test_logos.py b/tests/unit/config_test_logos.py index f4daf25b..13bd0085 100644 --- a/tests/unit/config_test_logos.py +++ b/tests/unit/config_test_logos.py @@ -3,6 +3,7 @@ """Test Logos Mise en place de l'environnement de test pour logos """ +import os from pathlib import Path from shutil import copytree, rmtree, copy @@ -13,9 +14,9 @@ from app import db, Departement from app.auth.models import User, Role from config import TestConfig from scodoc import app -from tests.conftest import test_client +from tests.conftest import test_client, RESOURCES_DIR -RESOURCES_DIR = "/opt/scodoc/tests/ressources/test_logos" +LOGO_RESOURCES_DIR = os.path.join(RESOURCES_DIR, "test_logos") @pytest.fixture @@ -56,15 +57,15 @@ def create_logos(create_dept): dept2_id = dept2.id FILE_LIST = ["logo_A.jpg", "logo_C.jpg", "logo_D.png", "logo_E.jpg", "logo_F.jpeg"] for filename in FILE_LIST: - from_path = Path(RESOURCES_DIR).joinpath(filename) + from_path = Path(LOGO_RESOURCES_DIR).joinpath(filename) to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(filename) copy(from_path.absolute(), to_path.absolute()) copytree( - f"{RESOURCES_DIR}/logos_1", + f"{LOGO_RESOURCES_DIR}/logos_1", f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1_id}", ) copytree( - f"{RESOURCES_DIR}/logos_2", + f"{LOGO_RESOURCES_DIR}/logos_2", f"{scu.SCODOC_LOGOS_DIR}/logos_{dept2_id}", ) yield dept1, dept2, dept3 diff --git a/tests/unit/sco_fake_gen.py b/tests/unit/sco_fake_gen.py index 7e03f152..62bf5991 100644 --- a/tests/unit/sco_fake_gen.py +++ b/tests/unit/sco_fake_gen.py @@ -17,7 +17,7 @@ import typing from config import Config from app.auth.models import User -from app.models import FormationModalite +from app.models import FormationModalite, Matiere from app.scodoc import notesdb as ndb from app.scodoc import sco_codes_parcours from app.scodoc import sco_edit_formation @@ -210,8 +210,6 @@ class ScoFake(object): heures_td=None, heures_tp=None, coefficient=None, - ue_id=None, - formation_id=None, matiere_id=None, semestre_id=1, numero=None, @@ -220,10 +218,13 @@ class ScoFake(object): code_apogee=None, module_type=scu.ModuleType.STANDARD, ) -> int: + matiere = Matiere.query.get(matiere_id) + ue_id = matiere.ue.id + formation_id = matiere.ue.formation.id oid = sco_edit_module.do_module_create(locals()) oids = sco_edit_module.module_list(args={"module_id": oid}) if not oids: - raise ScoValueError("module not created ! (oid=%s)" % oid) + raise ScoValueError(f"module not created ! (oid={oid})") return oid @logging_meth @@ -361,8 +362,6 @@ class ScoFake(object): code="TSM%s" % len(mod_ids), coefficient=1.0, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) mod_ids.append(mod) return formation_id, ue_ids, mod_ids diff --git a/tests/unit/setup.py b/tests/unit/setup.py index de7f2643..90432242 100644 --- a/tests/unit/setup.py +++ b/tests/unit/setup.py @@ -46,8 +46,6 @@ def build_formation_test( code=f"TSM{i}", coefficient=1.0, titre=f"module test {i}", - ue_id=_ue1, - formation_id=formation_id, semestre_id=2, module_type=scu.ModuleType.RESSOURCE if parcours.APC_SAE @@ -69,8 +67,6 @@ def build_formation_test( code="BAD", coefficient=1.0, titre="module sport", - ue_id=ue_sport, - formation_id=formation_id, semestre_id=2, ) module_ids.append(mod_sport) diff --git a/tests/unit/test_abs_counts.py b/tests/unit/test_abs_counts.py index 3b8f94b7..5b0a5f04 100644 --- a/tests/unit/test_abs_counts.py +++ b/tests/unit/test_abs_counts.py @@ -32,8 +32,6 @@ def test_abs_counts(test_client): code="TSM1", coefficient=1.0, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) # --- Mise place d'un semestre diff --git a/tests/unit/test_abs_demijournee.py b/tests/unit/test_abs_demijournee.py index 5b1e95b3..e148b943 100644 --- a/tests/unit/test_abs_demijournee.py +++ b/tests/unit/test_abs_demijournee.py @@ -36,8 +36,6 @@ def test_abs_demijournee(test_client): code="TSM1", coefficient=1.0, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) # --- Mise place d'un semestre @@ -142,8 +140,6 @@ def test_abs_basic(test_client): code="TSM1", coefficient=1.0, titre="module test", - ue_id=ue_id, # faiblesse de l'API - formation_id=formation_id, # faiblesse de l'API ) # --- Mise place d'un semestre diff --git a/tests/unit/test_but_modules.py b/tests/unit/test_but_modules.py index da393aec..b09ad783 100644 --- a/tests/unit/test_but_modules.py +++ b/tests/unit/test_but_modules.py @@ -42,7 +42,7 @@ def test_evaluation_poids(test_client): semestre_id=1, date_debut="01/01/2021", date_fin="30/06/2021", - ) # formsemestre_id=716 + ) moduleimpl_id = G.create_moduleimpl( module_id=module_ids[0], formsemestre_id=formsemestre_id, diff --git a/tests/unit/test_formations.py b/tests/unit/test_formations.py index 679ddc13..c91a4cf8 100644 --- a/tests/unit/test_formations.py +++ b/tests/unit/test_formations.py @@ -1,382 +1,381 @@ -# -*- mode: python -*- -# -*- coding: utf-8 -*- - -""" Test creation/edition/import/export formations -""" - -# test écrit par Fares Amer, mai 2021 et porté sur ScoDoc 8 en juillet 2021 - -# Créer 2 formations, une test et une normale. Créer 2 semestres dans la formation normale et un -# dans la formation test, créer 2 semestres dans la formation normale (un test et un normal), -# 2 ue (un test et un normal), 2 modules (un test et un normal) et 2 matieres (test et normal). -# Et dans la formations test, un semestre, un module, un ue et une matiere. -# Afficher la liste de tout ca puis supprimer les ue, mod, mat et sem test ainsi -# que la formation test. Afficher la liste des UE, formations et modules restante. -# -# Vérification : -# -# - Les listes initiales comprennent bien tout les éléments créés avec les bon noms etc -# - La supression s'est bien effectué au niveau de scodoc web et en python -# - Vérifier que les fonctions listes font bien la mise à jour après supression -# -# Fonction de l'API utilisé : -# -# - create_formation -# - create_ue -# - create_matiere -# - create_module -# - create_formsemestre -# - create_moduleimpl -# - formation_list -# - formation_export -# - formsemestre_list -# - moduleimpl_list -# - do_module_impl_with_module_list -# - do_formsemestre_delete -# - module_list -# - do_module_delete -# - matiere_list -# - do_matiere_delete -# - ue_list -# - do_ue_delete -# - do_formation_delete - -import json - -import flask -from flask import g -import pytest -from app.models.moduleimpls import ModuleImpl -from tests.unit import sco_fake_gen - -from app.scodoc import sco_edit_formation, sco_formsemestre -from app.scodoc import sco_edit_matiere -from app.scodoc import sco_edit_module -from app.scodoc import sco_edit_ue -from app.scodoc import sco_exceptions -from app.scodoc import sco_formations -from app.scodoc import sco_formsemestre_edit -from app.scodoc import sco_moduleimpl -from app.views import notes - - -def test_formations(test_client): - """Test création/édition/import/export formations""" - G = sco_fake_gen.ScoFake(verbose=False) - - # --- Création de formations - - formation_id = G.create_formation( - acronyme="F1", titre="Formation 1", titre_officiel="Titre officiel 1" - ) - f = sco_formations.formation_list(formation_id)[0] - ue_id = G.create_ue(formation_id=formation_id, acronyme="TST1", titre="ue test") - matiere_id = G.create_matiere(ue_id=ue_id, titre="matière test") - module_id = G.create_module( - matiere_id=matiere_id, - code="TSM1", - coefficient=1.0, - titre="module test", - ue_id=ue_id, # faiblesse de l'API - formation_id=formation_id, # faiblesse de l'API - ) - - ue_id2 = G.create_ue(formation_id=formation_id, acronyme="TST2", titre="ue test2") - matiere_id2 = G.create_matiere(ue_id=ue_id2, titre="matière test2") - module_id2 = G.create_module( - matiere_id=matiere_id2, - code="TSM2", - coefficient=1.0, - titre="module test", - ue_id=ue_id2, - formation_id=formation_id, - ) - - uet_id = G.create_ue(formation_id=formation_id, acronyme="TSTt", titre="ue testt") - matiere_id3 = G.create_matiere(ue_id=uet_id, titre="matière testt") - module_id_t = G.create_module( - matiere_id=matiere_id3, - code="TSMt", - coefficient=1.0, - titre="module test", - ue_id=uet_id, - formation_id=formation_id, - ) - - formation_id2 = G.create_formation(acronyme="", titre="Formation test") - formation2 = sco_formations.formation_list(formation_id2)[0] - ue3 = G.create_ue(formation_id=formation_id2, acronyme="TST3", titre="ue test3") - matiere_id4 = G.create_matiere(ue_id=ue3, titre="matière test3") - module_id3 = G.create_module( - matiere_id=matiere_id4, - code="TSM3", - coefficient=1.0, - titre="module test3", - ue_id=ue3, - formation_id=formation_id2, - ) - - # --- Création et implémentation des semestres - - formsemestre_id1 = G.create_formsemestre( - formation_id=formation_id, - semestre_id=1, - date_debut="01/01/2021", - date_fin="30/06/2021", - ) - - formsemestre_id2 = G.create_formsemestre( - formation_id=formation_id, - semestre_id=2, - date_debut="01/09/2020", - date_fin="31/12/2020", - ) - - moduleimpl_id = G.create_moduleimpl( - module_id=module_id, - formsemestre_id=formsemestre_id1, - ) - - _ = G.create_moduleimpl( - module_id=module_id2, - formsemestre_id=formsemestre_id1, - ) - - _ = G.create_moduleimpl( - module_id=module_id_t, - formsemestre_id=formsemestre_id2, - ) - - formsemestre_idt = G.create_formsemestre( - formation_id=formation_id2, - semestre_id=3, - date_debut="01/01/2021", - date_fin="30/06/2021", - ) - - mi3 = G.create_moduleimpl( - module_id=module_id3, - formsemestre_id=formsemestre_idt, - ) - - # --- Afficher la liste des formations - - lif = notes.formation_list(format="json", formation_id=formation_id) - # lif est une Response car on a appelé une vue (1er appel) - assert isinstance(lif, flask.Response) - load_lif = json.loads(lif.get_data().decode("utf-8")) - assert len(load_lif) == 1 - assert load_lif[0]["acronyme"] == f["acronyme"] - assert load_lif[0]["titre_officiel"] == f["titre_officiel"] - assert load_lif[0]["formation_id"] == formation_id - assert load_lif[0]["titre"] == f["titre"] - - lif2 = notes.formation_list(format="json").get_data(as_text=True) - # lif2 est un chaine - assert isinstance(lif2, str) - load_lif2 = json.loads(lif2) - assert len(load_lif2) == 2 - assert load_lif2[0] == load_lif[0] - assert load_lif2[1]["titre"] == formation2["titre"] - - # --- Export de formation_id - - exp = sco_formations.formation_export( - formation_id=formation_id, format="json" - ).get_data(as_text=True) - assert isinstance(exp, str) - load_exp = json.loads(exp) - - assert load_exp["acronyme"] == "F1" - assert load_exp["titre_officiel"] == "Titre officiel 1" - assert load_exp["titre"] == "Formation 1" - assert load_exp["formation_code"] == f["formation_code"] - assert len(load_exp["ue"]) == 3 - assert load_exp["ue"][0]["acronyme"] == "TST1" - assert load_exp["ue"][0]["titre"] == "ue test" - assert load_exp["formation_id"] == formation_id - assert load_exp["formation_code"] == f["formation_code"] - - # --- Liste des semestres - - li_sem1 = notes.formsemestre_list( - formsemestre_id=formsemestre_id1, format="json" - ).get_data(as_text=True) - assert isinstance(li_sem1, str) - load_li_sem1 = json.loads(li_sem1) # uniquement le semestre 1 dans la liste - - assert len(load_li_sem1) == 1 - sem1 = sco_formsemestre.get_formsemestre(formsemestre_id1) - assert load_li_sem1[0]["date_fin"] == sem1["date_fin"] - assert load_li_sem1[0]["semestre_id"] == sem1["semestre_id"] - assert load_li_sem1[0]["formation_id"] == sem1["formation_id"] - - li_semf = notes.formsemestre_list( - formation_id=formation_id, - format="json", - ).get_data(as_text=True) - assert isinstance(li_semf, str) - load_li_semf = json.loads(li_semf) - - assert load_li_sem1[0] in load_li_semf - assert len(load_li_semf) == 2 - sem2 = sco_formsemestre.get_formsemestre(formsemestre_id2) - assert load_li_semf[1]["semestre_id"] == sem2["semestre_id"] - - li_sem = notes.formsemestre_list(format="json").get_data(as_text=True) - load_li_sem = json.loads(li_sem) - - assert len(load_li_sem) == 3 - assert load_li_semf[0] and load_li_semf[1] in load_li_sem - - # --- Liste des modules - - lim_sem1 = sco_moduleimpl.moduleimpl_list(formsemestre_id=sem1["formsemestre_id"]) - - assert len(lim_sem1) == 2 - assert module_id in ( - lim_sem1[0]["module_id"], - lim_sem1[1]["module_id"], - ) - assert module_id2 in ( - lim_sem1[0]["module_id"], - lim_sem1[1]["module_id"], - ) - - lim_modid = sco_moduleimpl.moduleimpl_list(module_id=module_id) - - assert len(lim_modid) == 1 - - lim_modimpl_id = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id) - # print(lim_modimpl_id) - - # ---- Test de moduleimpl_withmodule_list - - assert lim_modid == lim_modimpl_id # doit etre le meme resultat - - liimp_sem1 = sco_moduleimpl.moduleimpl_withmodule_list( - formsemestre_id=sem1["formsemestre_id"] - ) - - assert len(liimp_sem1) == 2 - assert module_id in ( - liimp_sem1[0]["module_id"], - liimp_sem1[1]["module_id"], - ) - assert module_id2 in ( - liimp_sem1[0]["module_id"], - liimp_sem1[1]["module_id"], - ) - liimp_sem2 = sco_moduleimpl.moduleimpl_withmodule_list( - formsemestre_id=sem2["formsemestre_id"] - ) - assert module_id_t == liimp_sem2[0]["module_id"] - liimp_modid = sco_moduleimpl.moduleimpl_withmodule_list(module_id=module_id) - assert len(liimp_modid) == 1 - - liimp_modimplid = sco_moduleimpl.moduleimpl_withmodule_list( - moduleimpl_id=moduleimpl_id - ) - - assert liimp_modid == liimp_modimplid - - # --- Suppression du module, matiere et ue test du semestre 2 - - # on doit d'abord supprimer le semestre: - - sco_formsemestre_edit.do_formsemestre_delete( - formsemestre_id=sem2["formsemestre_id"] - ) - - li_module = sco_edit_module.module_list() - assert len(li_module) == 4 - # Suppression impossible car utilisé dans le semestre formsemestre_idt: - module3 = ModuleImpl.query.get(mi3).module - with pytest.raises(sco_exceptions.ScoNonEmptyFormationObject): - sco_edit_module.module_delete(module_id=module3.id) - - sco_formsemestre_edit.do_formsemestre_delete(formsemestre_idt) - - li_module2_before = sco_edit_module.module_list() - - sco_edit_module.do_module_delete(module3.id) - sco_edit_module.do_module_delete(module_id_t) - - # deuxieme methode de supression d'un module - li_module2_after = sco_edit_module.module_list() - - assert ( - len(li_module2_after) == len(li_module2_before) - 2 - ) # verification de la suppression - - lim_sem2 = sco_moduleimpl.moduleimpl_list(formsemestre_id=sem2["formsemestre_id"]) - - assert len(lim_sem2) == 0 # deuxieme vérification si le module s'est bien sup - - li_mat = sco_edit_matiere.matiere_list() - assert len(li_mat) == 4 - sco_edit_matiere.do_matiere_delete(oid=matiere_id3) # on supprime la matiere - li_mat2 = sco_edit_matiere.matiere_list() - assert len(li_mat2) == 3 # verification de la suppression de la matiere - - li_ue = sco_edit_ue.ue_list() - assert len(li_ue) == 4 - sco_edit_ue.ue_delete(ue_id=uet_id, dialog_confirmed=True) - li_ue2 = sco_edit_ue.ue_list() - assert len(li_ue2) == 3 # verification de la suppression de l'UE - - # --- Suppression d'une formation - - sco_edit_formation.do_formation_delete(formation_id=formation_id2) - lif3 = notes.formation_list(format="json").get_data(as_text=True) - assert isinstance(lif3, str) - load_lif3 = json.loads(lif3) - assert len(load_lif3) == 1 - - -def test_import_formation(test_client): - """Test import/export formations""" - G = sco_fake_gen.ScoFake(verbose=False) - # Lecture fichier XML local: - with open("tests/unit/formation-exemple-1.xml") as f: - doc = f.read() - - # --- Création de la formation - f = sco_formations.formation_import_xml(doc) - assert len(f) == 3 # 3-uple - formation_id = f[0] - # --- Vérification des UE - ues = sco_edit_ue.ue_list({"formation_id": formation_id}) - assert len(ues) == 10 - assert all(not ue["is_external"] for ue in ues) # aucune UE externe dans le XML - # --- Mise en place de 4 semestres - formsemestre_ids = [ - G.create_formsemestre( - formation_id=formation_id, - semestre_id=x[0], - date_debut=x[1], - date_fin=x[2], - ) - for x in ( - (1, "05/09/2019", "05/01/2020"), - (2, "06/01/2020", "30/06/2020"), - (3, "01/09/2020", "05/01/2021"), - (4, "06/01/2021", "30/06/2021"), - ) - ] - # et les modules - modules = sco_edit_module.module_list({"formation_id": formation_id}) - for mod in modules: - moduleimpl_id = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_ids[mod["semestre_id"] - 1], - ) - mi = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id)[0] - assert mi["ens"] == [] - assert mi["module_id"] == mod["module_id"] - - # --- Export formation en XML - doc1 = sco_formations.formation_export(formation_id, format="xml").get_data( - as_text=True - ) - assert isinstance(doc1, str) +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +""" Test creation/edition/import/export formations +""" + +# test écrit par Fares Amer, mai 2021 et porté sur ScoDoc 8 en juillet 2021 + +# Créer 2 formations, une test et une normale. Créer 2 semestres dans la +# formation normale et un dans la formation test, créer 2 semestres dans la +# formation normale (un test et un normal), 2 ue (un test et un normal), 2 +# modules (un test et un normal) et 2 matieres (test et normal). Et dans la +# formations test, un semestre, un module, un ue et une matiere. Afficher la +# liste de tout ca puis supprimer les ue, mod, mat et sem test ainsi que la +# formation test. Afficher la liste des UE, formations et modules restante. +# +# Vérification : +# +# - Les listes initiales comprennent bien tout les éléments créés avec les bons +# noms etc +# - La supression s'est bien effectué au niveau de scodoc web et en python +# - Vérifier que les fonctions listes font bien la mise à jour après suppression +# +# Fonction de l'API utilisé : +# +# - create_formation +# - create_ue +# - create_matiere +# - create_module +# - create_formsemestre +# - create_moduleimpl +# - formation_list +# - formation_export +# - formsemestre_list +# - moduleimpl_list +# - do_module_impl_with_module_list +# - do_formsemestre_delete +# - module_list +# - do_module_delete +# - matiere_list +# - do_matiere_delete +# - ue_list +# - do_ue_delete +# - do_formation_delete + +import json +import os + +import flask +import pytest + +from app.models.moduleimpls import ModuleImpl +from app.scodoc import sco_edit_formation, sco_formsemestre +from app.scodoc import sco_edit_matiere +from app.scodoc import sco_edit_module +from app.scodoc import sco_edit_ue +from app.scodoc import sco_exceptions +from app.scodoc import sco_formations +from app.scodoc import sco_formsemestre_edit +from app.scodoc import sco_moduleimpl +from app.views import notes + +from tests.conftest import RESOURCES_DIR +from tests.unit import sco_fake_gen + + +def test_formations(test_client): + """Test création/édition/import/export formations""" + G = sco_fake_gen.ScoFake(verbose=False) + + # --- Création de formations + + formation_id = G.create_formation( + acronyme="F1", titre="Formation 1", titre_officiel="Titre officiel 1" + ) + f = sco_formations.formation_list(formation_id)[0] + ue_id = G.create_ue(formation_id=formation_id, acronyme="TST1", titre="ue test") + matiere_id = G.create_matiere(ue_id=ue_id, titre="matière test") + module_id = G.create_module( + matiere_id=matiere_id, + code="TSM1", + coefficient=1.0, + titre="module test", + ) + + ue_id2 = G.create_ue(formation_id=formation_id, acronyme="TST2", titre="ue test2") + matiere_id2 = G.create_matiere(ue_id=ue_id2, titre="matière test2") + module_id2 = G.create_module( + matiere_id=matiere_id2, + code="TSM2", + coefficient=1.0, + titre="module test", + ) + + uet_id = G.create_ue(formation_id=formation_id, acronyme="TSTt", titre="ue testt") + matiere_id3 = G.create_matiere(ue_id=uet_id, titre="matière testt") + module_id_t = G.create_module( + matiere_id=matiere_id3, + code="TSMt", + coefficient=1.0, + titre="module test", + ) + + formation_id2 = G.create_formation(acronyme="", titre="Formation test") + formation2 = sco_formations.formation_list(formation_id2)[0] + ue3 = G.create_ue(formation_id=formation_id2, acronyme="TST3", titre="ue test3") + matiere_id4 = G.create_matiere(ue_id=ue3, titre="matière test3") + module_id3 = G.create_module( + matiere_id=matiere_id4, + code="TSM3", + coefficient=1.0, + titre="module test3", + ) + + # --- Création et implémentation des semestres + + formsemestre_id1 = G.create_formsemestre( + formation_id=formation_id, + semestre_id=1, + date_debut="01/01/2021", + date_fin="30/06/2021", + ) + + formsemestre_id2 = G.create_formsemestre( + formation_id=formation_id, + semestre_id=2, + date_debut="01/09/2020", + date_fin="31/12/2020", + ) + + moduleimpl_id = G.create_moduleimpl( + module_id=module_id, + formsemestre_id=formsemestre_id1, + ) + + _ = G.create_moduleimpl( + module_id=module_id2, + formsemestre_id=formsemestre_id1, + ) + + _ = G.create_moduleimpl( + module_id=module_id_t, + formsemestre_id=formsemestre_id2, + ) + + formsemestre_idt = G.create_formsemestre( + formation_id=formation_id2, + semestre_id=3, + date_debut="01/01/2021", + date_fin="30/06/2021", + ) + + mi3 = G.create_moduleimpl( + module_id=module_id3, + formsemestre_id=formsemestre_idt, + ) + + # --- Afficher la liste des formations + + lif = notes.formation_list(format="json", formation_id=formation_id) + # lif est une Response car on a appelé une vue (1er appel) + assert isinstance(lif, flask.Response) + load_lif = json.loads(lif.get_data().decode("utf-8")) + assert len(load_lif) == 1 + assert load_lif[0]["acronyme"] == f["acronyme"] + assert load_lif[0]["titre_officiel"] == f["titre_officiel"] + assert load_lif[0]["formation_id"] == formation_id + assert load_lif[0]["titre"] == f["titre"] + + lif2 = notes.formation_list(format="json").get_data(as_text=True) + # lif2 est un chaine + assert isinstance(lif2, str) + load_lif2 = json.loads(lif2) + assert len(load_lif2) == 2 + assert load_lif2[0] == load_lif[0] + assert load_lif2[1]["titre"] == formation2["titre"] + + # --- Export de formation_id + + exp = sco_formations.formation_export( + formation_id=formation_id, format="json" + ).get_data(as_text=True) + assert isinstance(exp, str) + load_exp = json.loads(exp) + + assert load_exp["acronyme"] == "F1" + assert load_exp["titre_officiel"] == "Titre officiel 1" + assert load_exp["titre"] == "Formation 1" + assert load_exp["formation_code"] == f["formation_code"] + assert len(load_exp["ue"]) == 3 + assert load_exp["ue"][0]["acronyme"] == "TST1" + assert load_exp["ue"][0]["titre"] == "ue test" + assert load_exp["formation_id"] == formation_id + assert load_exp["formation_code"] == f["formation_code"] + + # --- Liste des semestres + + li_sem1 = notes.formsemestre_list( + formsemestre_id=formsemestre_id1, format="json" + ).get_data(as_text=True) + assert isinstance(li_sem1, str) + load_li_sem1 = json.loads(li_sem1) # uniquement le semestre 1 dans la liste + + assert len(load_li_sem1) == 1 + sem1 = sco_formsemestre.get_formsemestre(formsemestre_id1) + assert load_li_sem1[0]["date_fin"] == sem1["date_fin"] + assert load_li_sem1[0]["semestre_id"] == sem1["semestre_id"] + assert load_li_sem1[0]["formation_id"] == sem1["formation_id"] + + li_semf = notes.formsemestre_list( + formation_id=formation_id, + format="json", + ).get_data(as_text=True) + assert isinstance(li_semf, str) + load_li_semf = json.loads(li_semf) + + assert load_li_sem1[0] in load_li_semf + assert len(load_li_semf) == 2 + sem2 = sco_formsemestre.get_formsemestre(formsemestre_id2) + assert load_li_semf[1]["semestre_id"] == sem2["semestre_id"] + + li_sem = notes.formsemestre_list(format="json").get_data(as_text=True) + load_li_sem = json.loads(li_sem) + + assert len(load_li_sem) == 3 + assert load_li_semf[0] and load_li_semf[1] in load_li_sem + + # --- Liste des modules + + lim_sem1 = sco_moduleimpl.moduleimpl_list(formsemestre_id=sem1["formsemestre_id"]) + + assert len(lim_sem1) == 2 + assert module_id in ( + lim_sem1[0]["module_id"], + lim_sem1[1]["module_id"], + ) + assert module_id2 in ( + lim_sem1[0]["module_id"], + lim_sem1[1]["module_id"], + ) + + lim_modid = sco_moduleimpl.moduleimpl_list(module_id=module_id) + + assert len(lim_modid) == 1 + + lim_modimpl_id = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id) + # print(lim_modimpl_id) + + # ---- Test de moduleimpl_withmodule_list + + assert lim_modid == lim_modimpl_id # doit etre le meme resultat + + liimp_sem1 = sco_moduleimpl.moduleimpl_withmodule_list( + formsemestre_id=sem1["formsemestre_id"] + ) + + assert len(liimp_sem1) == 2 + assert module_id in ( + liimp_sem1[0]["module_id"], + liimp_sem1[1]["module_id"], + ) + assert module_id2 in ( + liimp_sem1[0]["module_id"], + liimp_sem1[1]["module_id"], + ) + liimp_sem2 = sco_moduleimpl.moduleimpl_withmodule_list( + formsemestre_id=sem2["formsemestre_id"] + ) + assert module_id_t == liimp_sem2[0]["module_id"] + liimp_modid = sco_moduleimpl.moduleimpl_withmodule_list(module_id=module_id) + assert len(liimp_modid) == 1 + + liimp_modimplid = sco_moduleimpl.moduleimpl_withmodule_list( + moduleimpl_id=moduleimpl_id + ) + + assert liimp_modid == liimp_modimplid + + # --- Suppression du module, matiere et ue test du semestre 2 + + # on doit d'abord supprimer le semestre: + + sco_formsemestre_edit.do_formsemestre_delete( + formsemestre_id=sem2["formsemestre_id"] + ) + + li_module = sco_edit_module.module_list() + assert len(li_module) == 4 + # Suppression impossible car utilisé dans le semestre formsemestre_idt: + module3 = ModuleImpl.query.get(mi3).module + with pytest.raises(sco_exceptions.ScoNonEmptyFormationObject): + sco_edit_module.module_delete(module_id=module3.id) + + sco_formsemestre_edit.do_formsemestre_delete(formsemestre_idt) + + li_module2_before = sco_edit_module.module_list() + + sco_edit_module.do_module_delete(module3.id) + sco_edit_module.do_module_delete(module_id_t) + + # deuxieme methode de supression d'un module + li_module2_after = sco_edit_module.module_list() + + assert ( + len(li_module2_after) == len(li_module2_before) - 2 + ) # verification de la suppression + + lim_sem2 = sco_moduleimpl.moduleimpl_list(formsemestre_id=sem2["formsemestre_id"]) + + assert len(lim_sem2) == 0 # deuxieme vérification si le module s'est bien sup + + li_mat = sco_edit_matiere.matiere_list() + assert len(li_mat) == 4 + sco_edit_matiere.do_matiere_delete(oid=matiere_id3) # on supprime la matiere + li_mat2 = sco_edit_matiere.matiere_list() + assert len(li_mat2) == 3 # verification de la suppression de la matiere + + li_ue = sco_edit_ue.ue_list() + assert len(li_ue) == 4 + sco_edit_ue.ue_delete(ue_id=uet_id, dialog_confirmed=True) + li_ue2 = sco_edit_ue.ue_list() + assert len(li_ue2) == 3 # verification de la suppression de l'UE + + # --- Suppression d'une formation + + sco_edit_formation.do_formation_delete(formation_id=formation_id2) + lif3 = notes.formation_list(format="json").get_data(as_text=True) + assert isinstance(lif3, str) + load_lif3 = json.loads(lif3) + assert len(load_lif3) == 1 + + +def test_import_formation(test_client, filename="formation-exemple-1.xml"): + """Test import/export formations""" + G = sco_fake_gen.ScoFake(verbose=False) + # Lecture fichier XML local: + with open( + os.path.join(RESOURCES_DIR, "formations", filename), + encoding="utf-8", + ) as f: + doc = f.read() + + # --- Création de la formation + f = sco_formations.formation_import_xml(doc) + assert len(f) == 3 # 3-uple + formation_id = f[0] + # --- Vérification des UE + ues = sco_edit_ue.ue_list({"formation_id": formation_id}) + assert len(ues) == 10 + assert all(not ue["is_external"] for ue in ues) # aucune UE externe dans le XML + # --- Mise en place de 4 semestres + formsemestre_ids = [ + G.create_formsemestre( + formation_id=formation_id, + semestre_id=x[0], + date_debut=x[1], + date_fin=x[2], + ) + for x in ( + (1, "05/09/2019", "05/01/2020"), + (2, "06/01/2020", "30/06/2020"), + (3, "01/09/2020", "05/01/2021"), + (4, "06/01/2021", "30/06/2021"), + ) + ] + # et les modules + modules = sco_edit_module.module_list({"formation_id": formation_id}) + for mod in modules: + moduleimpl_id = G.create_moduleimpl( + module_id=mod["module_id"], + formsemestre_id=formsemestre_ids[mod["semestre_id"] - 1], + ) + mi = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id)[0] + assert mi["ens"] == [] + assert mi["module_id"] == mod["module_id"] + + # --- Export formation en XML + doc1 = sco_formations.formation_export(formation_id, format="xml").get_data( + as_text=True + ) + assert isinstance(doc1, str) diff --git a/tests/unit/test_logos.py b/tests/unit/test_logos.py index 2ea9fb06..e5975512 100644 --- a/tests/unit/test_logos.py +++ b/tests/unit/test_logos.py @@ -8,7 +8,6 @@ Utiliser comme: from pathlib import Path from shutil import copy -import pytest as pytest from _pytest.python_api import approx import app @@ -20,7 +19,7 @@ from app.scodoc.sco_logos import ( write_logo, delete_logo, ) -from tests.unit.config_test_logos import create_dept, create_logos, RESOURCES_DIR +from tests.unit.config_test_logos import create_dept, create_logos, LOGO_RESOURCES_DIR def test_select_global_only(create_logos): @@ -90,7 +89,7 @@ def test_get_png_without_data(create_logos): def test_delete_unique_global_jpg_logo(create_logos): dept1, dept2, dept3 = create_logos - from_path = Path(RESOURCES_DIR).joinpath("logo_A.jpg") + from_path = Path(LOGO_RESOURCES_DIR).joinpath("logo_A.jpg") to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath("logo_W.jpg") copy(from_path.absolute(), to_path.absolute()) assert to_path.exists() @@ -100,7 +99,7 @@ def test_delete_unique_global_jpg_logo(create_logos): def test_delete_unique_local_jpg_logo(create_logos): dept1, dept2, dept3 = create_logos - from_path = Path(RESOURCES_DIR).joinpath("logo_A.jpg") + from_path = Path(LOGO_RESOURCES_DIR).joinpath("logo_A.jpg") to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_W.jpg") copy(from_path.absolute(), to_path.absolute()) assert to_path.exists() @@ -110,9 +109,9 @@ def test_delete_unique_local_jpg_logo(create_logos): def test_delete_multiple_local_jpg_logo(create_logos): dept1, dept2, dept3 = create_logos - from_path_A = Path(RESOURCES_DIR).joinpath("logo_A.jpg") + from_path_A = Path(LOGO_RESOURCES_DIR).joinpath("logo_A.jpg") to_path_A = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_V.jpg") - from_path_B = Path(RESOURCES_DIR).joinpath("logo_D.png") + from_path_B = Path(LOGO_RESOURCES_DIR).joinpath("logo_D.png") to_path_B = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_V.png") copy(from_path_A.absolute(), to_path_A.absolute()) copy(from_path_B.absolute(), to_path_B.absolute()) @@ -125,7 +124,7 @@ def test_delete_multiple_local_jpg_logo(create_logos): def test_create_global_jpg_logo(create_logos): dept1, dept2, dept3 = create_logos - path = Path(f"{RESOURCES_DIR}/logo_C.jpg") + path = Path(f"{LOGO_RESOURCES_DIR}/logo_C.jpg") stream = path.open("rb") logo_path = Path(scu.SCODOC_LOGOS_DIR).joinpath("logo_X.jpg") assert not logo_path.exists() @@ -136,7 +135,7 @@ def test_create_global_jpg_logo(create_logos): def test_create_locale_jpg_logo(create_logos): dept1, dept2, dept3 = create_logos - path = Path(f"{RESOURCES_DIR}/logo_C.jpg") + path = Path(f"{LOGO_RESOURCES_DIR}/logo_C.jpg") stream = path.open("rb") logo_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_Y.jpg") assert not logo_path.exists() @@ -149,7 +148,7 @@ def test_create_jpg_instead_of_png_logo(create_logos): dept1, dept2, dept3 = create_logos # action logo = Logo("D") # create global logo (replace logo_D.png) - path = Path(f"{RESOURCES_DIR}/logo_C.jpg") + path = Path(f"{LOGO_RESOURCES_DIR}/logo_C.jpg") stream = path.open("rb") logo.create(stream) # test @@ -163,7 +162,7 @@ def test_create_jpg_instead_of_png_logo(create_logos): assert logo is not None assert logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logo_D.jpg" # created.absolute() # restore initial state - original = Path(f"{RESOURCES_DIR}/logo_D.png") + original = Path(f"{LOGO_RESOURCES_DIR}/logo_D.png") copy(original, removed) created.unlink(missing_ok=True) diff --git a/tests/unit/test_notes_modules.py b/tests/unit/test_notes_modules.py index c04a6c77..55e123a7 100644 --- a/tests/unit/test_notes_modules.py +++ b/tests/unit/test_notes_modules.py @@ -69,8 +69,6 @@ def test_notes_modules(test_client): code="TSM1", coefficient=coef_mod_1, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) # --- Mise place d'un semestre @@ -261,8 +259,6 @@ def test_notes_modules(test_client): code="TSM2", coefficient=coef_mod_2, titre="module test 2", - ue_id=ue_id, - formation_id=formation_id, ) moduleimpl_id2 = G.create_moduleimpl( module_id=module_id2, @@ -356,8 +352,6 @@ def test_notes_modules_att_dem(test_client): code="TSM1", coefficient=coef_mod_1, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) # # -------------------------------- diff --git a/tests/unit/test_notes_rattrapage.py b/tests/unit/test_notes_rattrapage.py index e804b5e6..da23fa85 100644 --- a/tests/unit/test_notes_rattrapage.py +++ b/tests/unit/test_notes_rattrapage.py @@ -37,8 +37,6 @@ def test_notes_rattrapage(test_client): code="TSM1", coefficient=1.0, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) # --- Mise place d'un semestre diff --git a/tests/unit/test_sco_basic.py b/tests/unit/test_sco_basic.py index f3d46758..c1e57fa4 100644 --- a/tests/unit/test_sco_basic.py +++ b/tests/unit/test_sco_basic.py @@ -64,8 +64,6 @@ def run_sco_basic(verbose=False) -> FormSemestre: code="TSM1", coefficient=1.0, titre="module test", - ue_id=ue_id, - formation_id=formation_id, ) # --- Mise place d'un semestre