forked from ScoDoc/ScoDoc
Fix: import formation + tests unitaires formations
This commit is contained in:
parent
917070b169
commit
3df34737a7
@ -75,6 +75,8 @@ class Formation(db.Model):
|
||||
e["commentaire"] = e["commentaire"] or ""
|
||||
if with_departement and self.departement:
|
||||
e["departement"] = self.departement.to_dict()
|
||||
else:
|
||||
e.pop("departement", None)
|
||||
e["formation_id"] = self.id # ScoDoc7 backward compat
|
||||
if with_refcomp_attrs and self.referentiel_competence:
|
||||
e["refcomp_version_orebut"] = self.referentiel_competence.version_orebut
|
||||
|
@ -302,10 +302,10 @@ def do_formation_create(args: dict) -> Formation:
|
||||
titre=args["titre"].strip(),
|
||||
titre_officiel=args["titre_officiel"].strip(),
|
||||
version=args.get("version"),
|
||||
commentaire=scu.strip_str(args["commentaire"]),
|
||||
commentaire=scu.strip_str(args.get("commentaire", "")) or None,
|
||||
formation_code=args.get("formation_code", "").strip() or None,
|
||||
type_parcours=args.get("type_parcours"),
|
||||
code_specialite=args.get("code_specialite").strip() or None,
|
||||
code_specialite=args.get("code_specialite", "").strip() or None,
|
||||
referentiel_competence_id=args.get("referentiel_competence_id"),
|
||||
)
|
||||
db.session.add(formation)
|
||||
|
@ -187,7 +187,10 @@ def do_formsemestre_createwithmodules(edit=False, formsemestre: FormSemestre = N
|
||||
is_apc = formation.is_apc()
|
||||
if not edit:
|
||||
initvalues = {"titre": _default_sem_title(formation)}
|
||||
try:
|
||||
semestre_id = int(vals["semestre_id"])
|
||||
except ValueError as exc:
|
||||
raise ScoValueError("valeur invalide pour l'indice de semestre") from exc
|
||||
module_ids_set = set()
|
||||
else:
|
||||
# setup form init values
|
||||
|
@ -16,7 +16,7 @@ import typing
|
||||
|
||||
from app import db, log
|
||||
from app.auth.models import User
|
||||
from app.models import Formation, FormationModalite, Matiere
|
||||
from app.models import Departement, Formation, FormationModalite, Matiere
|
||||
from app.scodoc import notesdb as ndb
|
||||
from app.scodoc import codes_cursus
|
||||
from app.scodoc import sco_edit_matiere
|
||||
@ -32,7 +32,8 @@ from app.scodoc import sco_saisie_notes
|
||||
from app.scodoc import sco_synchro_etuds
|
||||
from app.scodoc import sco_utils as scu
|
||||
from app.scodoc.sco_exceptions import ScoValueError
|
||||
from config import Config
|
||||
from config import Config, TestConfig
|
||||
|
||||
|
||||
from tests.unit.setup import NOTES_T
|
||||
|
||||
@ -80,6 +81,8 @@ class ScoFake(object):
|
||||
self.default_user = User.query.filter_by(user_name="bach").first()
|
||||
if not self.default_user:
|
||||
raise ScoValueError('User test "bach" not found !')
|
||||
self.dept = Departement.query.filter_by(acronym=TestConfig.DEPT_TEST).first()
|
||||
assert self.dept
|
||||
|
||||
def log(self, msg):
|
||||
if self.verbose:
|
||||
@ -150,7 +153,7 @@ class ScoFake(object):
|
||||
acronyme="test",
|
||||
titre="Formation test",
|
||||
titre_officiel="Le titre officiel de la formation test",
|
||||
type_parcours=codes_cursus.CursusDUT.TYPE_CURSUS,
|
||||
type_parcours: int = codes_cursus.CursusDUT.TYPE_CURSUS,
|
||||
formation_code=None,
|
||||
code_specialite=None,
|
||||
) -> int:
|
||||
@ -161,9 +164,10 @@ class ScoFake(object):
|
||||
acronyme=scu.strip_str(acronyme),
|
||||
titre=scu.strip_str(titre),
|
||||
titre_officiel=scu.strip_str(titre_officiel),
|
||||
type_parcours=scu.strip_str(type_parcours),
|
||||
type_parcours=type_parcours,
|
||||
formation_code=scu.strip_str(formation_code),
|
||||
code_specialite=scu.strip_str(code_specialite),
|
||||
dept_id=self.dept.id,
|
||||
)
|
||||
db.session.add(formation)
|
||||
db.session.commit()
|
||||
|
@ -45,7 +45,6 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask
|
||||
import pytest
|
||||
|
||||
from app.models import Formation, ModuleImpl
|
||||
@ -72,7 +71,35 @@ def test_formations(test_client):
|
||||
formation_id = G.create_formation(
|
||||
acronyme="F1", titre="Formation 1", titre_officiel="Titre officiel 1"
|
||||
)
|
||||
f = Formation.query.get(formation_id).to_dict()
|
||||
# --- Objet Formation
|
||||
formation = Formation.query.get(formation_id)
|
||||
assert isinstance(formation, Formation)
|
||||
assert formation.acronyme == "F1"
|
||||
assert formation.titre == "Formation 1"
|
||||
assert formation.titre_officiel == "Titre officiel 1"
|
||||
assert formation.dept_id
|
||||
f_dict = formation.to_dict()
|
||||
assert isinstance(f_dict, dict)
|
||||
fields = {
|
||||
"acronyme",
|
||||
"titre_officiel",
|
||||
"commentaire",
|
||||
"departement",
|
||||
"formation_id",
|
||||
"type_parcours",
|
||||
"code_specialite",
|
||||
"referentiel_competence_id",
|
||||
"id",
|
||||
"version",
|
||||
"formation_code",
|
||||
"dept_id",
|
||||
"titre",
|
||||
}
|
||||
assert set(f_dict.keys()) == fields
|
||||
f_dict = formation.to_dict(with_departement=False)
|
||||
assert set(f_dict.keys()) == fields - {"departement"}
|
||||
|
||||
# Création des UEs, matières, modules
|
||||
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(
|
||||
@ -154,24 +181,7 @@ def test_formations(test_client):
|
||||
formsemestre_id=formsemestre_idt,
|
||||
)
|
||||
|
||||
# --- Récupérer la liste des formations
|
||||
|
||||
formation = Formation.query.get(formation_id)
|
||||
assert isinstance(formation, Formation)
|
||||
assert formation.acronyme == f["acronyme"]
|
||||
assert formation.titre_officiel == f["titre_officiel"]
|
||||
assert formation.id == formation_id
|
||||
assert formation.titre == f["titre"]
|
||||
|
||||
f_dict = formation.to_dict()
|
||||
assert isinstance(f_dict, dict)
|
||||
del f_dict["departement"]
|
||||
# pour le test:
|
||||
f_dict["referentiel_competence_id"] = f_dict["referentiel_competence_id"] or ""
|
||||
assert f_dict == f
|
||||
|
||||
# --- Export de formation_id
|
||||
|
||||
# --- Export de formation vers JSON
|
||||
exp = sco_formations.formation_export(
|
||||
formation_id=formation_id, format="json", export_ids=True
|
||||
).get_data(as_text=True)
|
||||
@ -181,12 +191,11 @@ def test_formations(test_client):
|
||||
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 load_exp["formation_code"] == formation.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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user