2022-03-09 16:05:44 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""Initialise une base pour les tests de l'API ScoDoc 9
|
|
|
|
|
|
|
|
Création des départements, formations, semestres, étudiants, groupes...
|
|
|
|
|
2022-07-29 16:19:40 +02:00
|
|
|
Utilisation: voir tests/api/README.md
|
2022-03-09 16:05:44 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
import datetime
|
2022-08-21 09:17:45 +02:00
|
|
|
import os
|
2022-03-09 16:05:44 +01:00
|
|
|
import random
|
2022-08-21 09:17:45 +02:00
|
|
|
import shutil
|
2022-05-04 23:11:20 +02:00
|
|
|
import sys
|
2022-03-09 16:05:44 +01:00
|
|
|
|
2022-08-04 16:54:59 +02:00
|
|
|
from app import db
|
2022-05-04 23:11:20 +02:00
|
|
|
from app.auth.models import Role, User
|
2022-08-04 16:54:59 +02:00
|
|
|
from app.but.import_refcomp import orebut_import_refcomp
|
2022-03-09 16:05:44 +01:00
|
|
|
from app import models
|
2024-10-10 00:41:20 +02:00
|
|
|
from app.formations import formation_io
|
2022-08-04 16:54:59 +02:00
|
|
|
from app.models import departements
|
2022-06-09 11:08:08 +02:00
|
|
|
from app.models import (
|
2022-08-04 16:54:59 +02:00
|
|
|
Absence,
|
2023-04-17 15:39:32 +02:00
|
|
|
Assiduite,
|
2022-06-09 11:08:08 +02:00
|
|
|
Departement,
|
2023-08-22 17:02:00 +02:00
|
|
|
Evaluation,
|
2022-06-09 11:08:08 +02:00
|
|
|
Formation,
|
|
|
|
FormSemestre,
|
2022-08-04 16:54:59 +02:00
|
|
|
FormSemestreEtape,
|
2022-06-09 11:08:08 +02:00
|
|
|
Identite,
|
2023-04-17 15:39:32 +02:00
|
|
|
Justificatif,
|
2022-06-09 11:08:08 +02:00
|
|
|
ModuleImpl,
|
|
|
|
NotesNotes,
|
2022-06-17 15:50:06 +02:00
|
|
|
)
|
2022-03-09 18:03:18 +01:00
|
|
|
from app.scodoc import (
|
2022-05-04 23:11:20 +02:00
|
|
|
sco_cache,
|
2022-03-09 18:03:18 +01:00
|
|
|
sco_formsemestre_inscriptions,
|
|
|
|
sco_groups,
|
|
|
|
)
|
2022-05-04 23:11:20 +02:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
2023-04-17 15:39:32 +02:00
|
|
|
from app.scodoc.sco_utils import localize_datetime
|
2022-03-09 16:05:44 +01:00
|
|
|
from tools.fakeportal.gen_nomprenoms import nomprenom
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
random.seed(12345678) # tests reproductibles
|
|
|
|
|
2022-03-09 16:05:44 +01:00
|
|
|
# La formation à utiliser:
|
2023-04-06 16:10:32 +02:00
|
|
|
FORMATION_XML_FILENAME = "tests/ressources/formations/scodoc_formation_BUT_RT_v1.xml"
|
2022-08-04 16:54:59 +02:00
|
|
|
REFCOMP_FILENAME = (
|
|
|
|
"ressources/referentiels/but2022/competences/but-RT-05012022-081735.xml"
|
|
|
|
)
|
2022-03-09 16:05:44 +01:00
|
|
|
|
2022-08-21 09:17:45 +02:00
|
|
|
# la réserve de logos
|
|
|
|
LOGOS_STOCK = "/opt/scodoc/tests/ressources/test_logos/"
|
|
|
|
LOGOS_DIR = "/opt/scodoc-data/config/logos/"
|
|
|
|
|
2022-03-09 16:05:44 +01:00
|
|
|
|
2022-08-05 17:05:24 +02:00
|
|
|
def create_departements(acronyms: list[str]) -> list[Departement]:
|
|
|
|
"Create depts"
|
|
|
|
return [departements.create_dept(acronym) for acronym in acronyms]
|
2022-03-09 16:05:44 +01:00
|
|
|
|
|
|
|
|
2022-08-04 16:54:59 +02:00
|
|
|
def import_formation(dept_id: int) -> Formation:
|
2022-03-09 16:05:44 +01:00
|
|
|
"""Import formation from XML.
|
2022-08-04 16:54:59 +02:00
|
|
|
Associate ref. comp.
|
2022-03-09 16:05:44 +01:00
|
|
|
Returns formation_id
|
|
|
|
"""
|
2022-08-04 16:54:59 +02:00
|
|
|
with open(FORMATION_XML_FILENAME, encoding="utf-8") as f:
|
2022-03-09 16:05:44 +01:00
|
|
|
doc = f.read()
|
2022-08-04 16:54:59 +02:00
|
|
|
# --- Création de la formation (import programme)
|
2024-10-10 00:41:20 +02:00
|
|
|
f = formation_io.formation_import_xml(doc)
|
2023-07-11 06:57:38 +02:00
|
|
|
formation = db.session.get(Formation, f[0])
|
2022-08-04 16:54:59 +02:00
|
|
|
# --- Association ref. comp.
|
|
|
|
with open(REFCOMP_FILENAME, encoding="utf-8") as f:
|
|
|
|
xml_data = f.read()
|
|
|
|
ref_comp = orebut_import_refcomp(
|
|
|
|
xml_data, dept_id=dept_id, orig_filename=REFCOMP_FILENAME
|
|
|
|
)
|
|
|
|
formation.referentiel_competence_id = ref_comp.id
|
|
|
|
db.session.add(formation)
|
2024-02-21 15:57:38 +01:00
|
|
|
# --- Association niveaux de compétences aux UE de S1:
|
|
|
|
niveaux = ref_comp.get_niveaux_by_parcours(1)[1]["TC"]
|
|
|
|
ues = formation.ues.filter_by(semestre_idx=1).all()
|
|
|
|
assert len(niveaux) == len(ues) # le ref comp et les formation doivent correspondre
|
|
|
|
for ue, niveau in zip(ues, niveaux):
|
|
|
|
ue.niveau_competence = niveau
|
|
|
|
db.session.add(ue)
|
2022-08-04 16:54:59 +02:00
|
|
|
db.session.commit()
|
|
|
|
return formation
|
2022-03-09 16:05:44 +01:00
|
|
|
|
|
|
|
|
2022-08-05 17:05:24 +02:00
|
|
|
def create_users(depts: list[Departement]) -> tuple:
|
|
|
|
"""Crée les roles et utilisateurs nécessaires aux tests"""
|
|
|
|
dept = depts[0]
|
|
|
|
# Le rôle standard LecteurAPI existe déjà: lui donne les permissions
|
2023-09-29 21:17:31 +02:00
|
|
|
# ScoView, AbsAddBillet, EtudChangeGroups
|
2022-08-05 17:05:24 +02:00
|
|
|
role_lecteur = Role.query.filter_by(name="LecteurAPI").first()
|
|
|
|
if role_lecteur is None:
|
2022-05-04 23:11:20 +02:00
|
|
|
print("Erreur: rôle LecteurAPI non existant")
|
|
|
|
sys.exit(1)
|
2022-07-27 16:03:14 +02:00
|
|
|
perm_sco_view = Permission.get_by_name("ScoView")
|
2022-08-05 17:05:24 +02:00
|
|
|
role_lecteur.add_permission(perm_sco_view)
|
2023-09-29 21:17:31 +02:00
|
|
|
perm_sco_users = Permission.get_by_name("UsersView")
|
2022-08-08 10:06:42 +02:00
|
|
|
role_lecteur.add_permission(perm_sco_users)
|
2022-08-01 21:42:19 +02:00
|
|
|
# Edition billets
|
2023-09-29 21:17:31 +02:00
|
|
|
perm_billets = Permission.get_by_name("AbsAddBillet")
|
2022-08-05 17:05:24 +02:00
|
|
|
role_lecteur.add_permission(perm_billets)
|
2023-09-29 21:17:31 +02:00
|
|
|
perm_groups = Permission.get_by_name("EtudChangeGroups")
|
2022-08-05 17:05:24 +02:00
|
|
|
role_lecteur.add_permission(perm_groups)
|
|
|
|
db.session.add(role_lecteur)
|
2022-05-04 23:11:20 +02:00
|
|
|
|
2022-08-05 17:05:24 +02:00
|
|
|
# Un role pour juste voir les utilisateurs
|
2022-08-08 10:06:42 +02:00
|
|
|
role_users_viewer = Role(
|
2023-09-29 21:17:31 +02:00
|
|
|
name="UsersViewer", permissions=Permission.UsersView | Permission.ScoView
|
2022-08-08 10:06:42 +02:00
|
|
|
)
|
2022-08-05 17:05:24 +02:00
|
|
|
db.session.add(role_users_viewer)
|
2022-08-08 10:06:42 +02:00
|
|
|
# Role View sur l'API, pour demander un jeton
|
|
|
|
role_view = Role(name="Viewer", permissions=Permission.ScoView)
|
|
|
|
db.session.add(role_view)
|
2022-08-05 17:05:24 +02:00
|
|
|
|
|
|
|
# Un utilisateur "test" (passwd test) pouvant lire l'API
|
|
|
|
user_test = User(user_name="test", nom="Doe", prenom="John", dept=dept.acronym)
|
|
|
|
user_test.set_password("test")
|
|
|
|
db.session.add(user_test)
|
|
|
|
user_test.add_role(role_lecteur, None)
|
2022-05-04 23:11:20 +02:00
|
|
|
|
|
|
|
# Un utilisateur "other" n'ayant aucune permission sur l'API
|
|
|
|
other = User(user_name="other", nom="Sans", prenom="Permission", dept=dept.acronym)
|
|
|
|
other.set_password("other")
|
|
|
|
db.session.add(other)
|
|
|
|
|
2022-08-05 06:55:05 +02:00
|
|
|
# Un utilisateur "admin_api"
|
|
|
|
admin_api = User(user_name="admin_api", nom="Admin", prenom="API")
|
|
|
|
admin_api.set_password("admin_api")
|
|
|
|
db.session.add(admin_api)
|
2022-08-05 17:05:24 +02:00
|
|
|
role_super_admin = Role.query.filter_by(name="SuperAdmin").first()
|
|
|
|
if role_super_admin is None:
|
2022-08-05 06:55:05 +02:00
|
|
|
print("Erreur: rôle SuperAdmin non existant")
|
|
|
|
sys.exit(1)
|
2022-08-05 17:05:24 +02:00
|
|
|
admin_api.add_role(role_super_admin, None)
|
|
|
|
|
|
|
|
# Des utilisateurs voyant certains utilisateurs...
|
|
|
|
users = []
|
|
|
|
for dept in depts:
|
|
|
|
u = User(
|
|
|
|
user_name=f"u_{dept.acronym}",
|
|
|
|
nom=f"U {dept.acronym}",
|
|
|
|
prenom="lambda",
|
|
|
|
dept=dept.acronym,
|
|
|
|
)
|
|
|
|
u.set_password("test")
|
|
|
|
users.append(u)
|
|
|
|
db.session.add(u)
|
|
|
|
# Roles pour tester les fonctions sur les utilisateurs
|
|
|
|
for i, u in enumerate(users):
|
|
|
|
for dept in depts[: i + 1]:
|
|
|
|
u.add_role(role_users_viewer, dept.acronym)
|
2022-08-08 10:06:42 +02:00
|
|
|
u.add_role(role_view, None) # necessaire pour avoir le jeton
|
2022-08-05 06:55:05 +02:00
|
|
|
|
2022-03-09 16:05:44 +01:00
|
|
|
db.session.commit()
|
2022-08-05 17:05:24 +02:00
|
|
|
return user_test, other
|
2022-03-09 16:05:44 +01:00
|
|
|
|
|
|
|
|
2022-05-07 08:23:30 +02:00
|
|
|
def create_fake_etud(dept: Departement) -> Identite:
|
|
|
|
"""Créé un faux étudiant et l'insère dans la base."""
|
2022-03-09 16:05:44 +01:00
|
|
|
civilite = random.choice(("M", "F", "X"))
|
|
|
|
nom, prenom = nomprenom(civilite)
|
2022-12-07 23:04:11 +01:00
|
|
|
etud: Identite = Identite.create_etud(
|
2022-05-07 08:23:30 +02:00
|
|
|
civilite=civilite, nom=nom, prenom=prenom, dept_id=dept.id
|
|
|
|
)
|
2022-03-09 16:05:44 +01:00
|
|
|
db.session.add(etud)
|
|
|
|
db.session.commit()
|
2022-05-07 08:23:30 +02:00
|
|
|
# créé un étudiant sur deux avec un NIP et INE alphanumérique
|
|
|
|
etud.code_nip = f"{etud.id}" if (etud.id % 2) else f"NIP{etud.id}"
|
|
|
|
etud.code_ine = f"INE{etud.id}" if (etud.id % 2) else f"{etud.id}"
|
2022-10-31 10:12:04 +01:00
|
|
|
etud.date_naissance = datetime.date(2005, 2, 1) + datetime.timedelta(days=etud.id)
|
2022-12-19 02:31:42 +01:00
|
|
|
etud.adresse = [models.Adresse(email=f"{etud.prenom}.{etud.nom}@example.com")]
|
2022-04-15 15:57:44 +02:00
|
|
|
db.session.add(etud)
|
|
|
|
db.session.commit()
|
2022-03-09 16:05:44 +01:00
|
|
|
return etud
|
|
|
|
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def create_etuds(dept: Departement, nb=16) -> list:
|
2022-03-09 16:05:44 +01:00
|
|
|
"create nb etuds"
|
2022-03-09 18:03:18 +01:00
|
|
|
return [create_fake_etud(dept) for _ in range(nb)]
|
2022-03-09 16:05:44 +01:00
|
|
|
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def create_formsemestre(
|
|
|
|
formation: Formation, responsable: User, semestre_idx=1
|
|
|
|
) -> FormSemestre:
|
|
|
|
"""Create formsemestre and moduleimpls
|
|
|
|
responsable: resp. du formsemestre
|
|
|
|
"""
|
|
|
|
formsemestre = FormSemestre(
|
2022-03-09 16:05:44 +01:00
|
|
|
dept_id=formation.dept_id,
|
|
|
|
semestre_id=semestre_idx,
|
|
|
|
titre="Semestre test",
|
|
|
|
date_debut=datetime.datetime(2021, 9, 1),
|
2022-04-14 14:56:36 +02:00
|
|
|
date_fin=datetime.datetime(2022, 8, 31),
|
2022-03-09 16:05:44 +01:00
|
|
|
modalite="FI",
|
|
|
|
formation=formation,
|
|
|
|
)
|
|
|
|
db.session.add(formsemestre)
|
|
|
|
db.session.commit()
|
|
|
|
# Crée un modulimpl par module de ce semestre:
|
|
|
|
for module in formation.modules.filter_by(semestre_id=semestre_idx):
|
|
|
|
modimpl = models.ModuleImpl(
|
2022-05-04 23:11:20 +02:00
|
|
|
module_id=module.id,
|
|
|
|
formsemestre_id=formsemestre.id,
|
|
|
|
responsable_id=responsable.id,
|
2022-03-09 16:05:44 +01:00
|
|
|
)
|
|
|
|
db.session.add(modimpl)
|
|
|
|
db.session.commit()
|
2024-07-27 13:30:02 +02:00
|
|
|
# Partition par défaut (requise):
|
2022-03-09 18:03:18 +01:00
|
|
|
partition_id = sco_groups.partition_create(
|
|
|
|
formsemestre.id, default=True, redirect=False
|
|
|
|
)
|
2024-07-27 13:30:02 +02:00
|
|
|
sco_groups.create_group(partition_id, default=True)
|
|
|
|
# Ajoute partition normale, TD avec groupes A et B:
|
|
|
|
partition_id = sco_groups.partition_create(
|
|
|
|
formsemestre.id, partition_name="TD", redirect=False
|
|
|
|
)
|
|
|
|
sco_groups.create_group(partition_id, group_name="A")
|
|
|
|
sco_groups.create_group(partition_id, group_name="B")
|
2022-03-09 16:05:44 +01:00
|
|
|
return formsemestre
|
|
|
|
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def inscrit_etudiants(etuds: list, formsemestre: FormSemestre):
|
2022-08-07 19:56:25 +02:00
|
|
|
"""Inscrit les étudiants au semestre et à tous ses modules.
|
|
|
|
1/5 DEF, 1/5 DEF
|
|
|
|
"""
|
|
|
|
for i, etud in enumerate(etuds):
|
|
|
|
if (i + 1) % 5 == 0:
|
|
|
|
etat = "D"
|
|
|
|
elif (i + 2) % 5 == 0:
|
|
|
|
etat = "DEF"
|
2022-06-24 16:03:35 +02:00
|
|
|
else:
|
2022-08-07 19:56:25 +02:00
|
|
|
etat = "I"
|
|
|
|
sco_formsemestre_inscriptions.do_formsemestre_inscription_with_modules(
|
|
|
|
formsemestre.id,
|
|
|
|
etud.id,
|
|
|
|
group_ids=[],
|
|
|
|
etat=etat,
|
|
|
|
method="init db test",
|
|
|
|
)
|
2022-03-09 16:05:44 +01:00
|
|
|
|
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
def create_evaluations(formsemestre: FormSemestre):
|
2023-08-22 17:02:00 +02:00
|
|
|
"Création d'une evaluation dans chaque modimpl du semestre"
|
|
|
|
for moduleimpl in formsemestre.modimpls:
|
2022-05-04 23:11:20 +02:00
|
|
|
args = {
|
2023-08-25 17:58:57 +02:00
|
|
|
"jour": datetime.date(2022, 3, 1)
|
|
|
|
+ datetime.timedelta(days=moduleimpl.id), # TODO à changer
|
2022-05-04 23:11:20 +02:00
|
|
|
"heure_debut": "8h00",
|
|
|
|
"heure_fin": "9h00",
|
2023-08-22 17:02:00 +02:00
|
|
|
"description": f"Evaluation-{moduleimpl.module.code}",
|
2022-05-04 23:11:20 +02:00
|
|
|
"note_max": 20,
|
|
|
|
"coefficient": 1.0,
|
|
|
|
"visibulletin": True,
|
|
|
|
"publish_incomplete": True,
|
|
|
|
"evaluation_type": None,
|
|
|
|
"numero": None,
|
|
|
|
}
|
2023-08-22 17:02:00 +02:00
|
|
|
evaluation = Evaluation.create(moduleimpl=moduleimpl, **args)
|
|
|
|
db.session.add(evaluation)
|
|
|
|
db.session.commit()
|
2022-05-04 23:11:20 +02:00
|
|
|
|
|
|
|
|
2022-06-09 11:08:08 +02:00
|
|
|
def saisie_notes_evaluations(formsemestre: FormSemestre, user: User):
|
2022-06-02 16:18:47 +02:00
|
|
|
"""
|
|
|
|
Saisie les notes des evaluations d'un semestre
|
|
|
|
"""
|
2022-06-09 11:08:08 +02:00
|
|
|
etuds = formsemestre.etuds
|
|
|
|
list_etuds = []
|
|
|
|
for etu in etuds:
|
|
|
|
list_etuds.append(etu)
|
2022-06-02 16:18:47 +02:00
|
|
|
|
2022-06-09 11:08:08 +02:00
|
|
|
date_debut = formsemestre.date_debut
|
|
|
|
date_fin = formsemestre.date_fin
|
|
|
|
|
2023-04-03 17:46:31 +02:00
|
|
|
list_ues = formsemestre.get_ues()
|
2022-06-09 11:08:08 +02:00
|
|
|
|
|
|
|
def saisir_notes(evaluation_id: int, condition: int):
|
2022-06-02 16:18:47 +02:00
|
|
|
"""
|
2022-06-03 16:20:59 +02:00
|
|
|
Permet de saisir les notes de manière aléatoire suivant une condition
|
|
|
|
Définition des valeurs de condition :
|
|
|
|
0 : all_notes_saisies
|
|
|
|
1 : all_notes_manquantes
|
|
|
|
2 : some_notes_manquantes
|
2022-06-02 16:18:47 +02:00
|
|
|
"""
|
2022-07-29 16:19:40 +02:00
|
|
|
if condition == 2:
|
|
|
|
return # nothing to do
|
|
|
|
if condition == 0:
|
|
|
|
list_a_saisir = list_etuds
|
|
|
|
else:
|
|
|
|
percent = 80 / 100
|
|
|
|
len_etuds = len(list_etuds)
|
|
|
|
list_a_saisir = random.sample(list_etuds, k=int(percent * len_etuds))
|
|
|
|
|
|
|
|
for etud in list_a_saisir:
|
|
|
|
note = NotesNotes(
|
|
|
|
etudid=etud.id,
|
|
|
|
evaluation_id=evaluation_id,
|
|
|
|
value=random.uniform(0, 20),
|
|
|
|
comment="",
|
|
|
|
date=date_debut + random.random() * (date_fin - date_debut),
|
|
|
|
uid=user.id,
|
|
|
|
)
|
|
|
|
db.session.add(note)
|
|
|
|
db.session.commit()
|
2022-06-02 16:18:47 +02:00
|
|
|
|
|
|
|
for ue in list_ues:
|
|
|
|
mods = ue.modules
|
|
|
|
for mod in mods:
|
|
|
|
moduleimpl = ModuleImpl.query.get_or_404(mod.id)
|
|
|
|
for evaluation in moduleimpl.evaluations:
|
2022-06-03 16:20:59 +02:00
|
|
|
condition_saisie_notes = random.randint(0, 2)
|
2022-06-09 11:08:08 +02:00
|
|
|
saisir_notes(evaluation.id, condition_saisie_notes)
|
2022-06-02 16:18:47 +02:00
|
|
|
|
|
|
|
|
2022-06-20 16:10:39 +02:00
|
|
|
def add_absences(formsemestre: FormSemestre):
|
|
|
|
"""
|
|
|
|
Ajoute des absences en base
|
|
|
|
"""
|
|
|
|
date_debut = formsemestre.date_debut
|
|
|
|
date_fin = formsemestre.date_fin
|
2022-06-20 16:09:22 +02:00
|
|
|
|
2022-06-20 16:10:39 +02:00
|
|
|
etuds = formsemestre.etuds
|
|
|
|
for etu in etuds:
|
|
|
|
aleatoire = random.randint(0, 1)
|
|
|
|
if aleatoire == 1:
|
|
|
|
nb_absences = random.randint(1, 5)
|
|
|
|
for absence in range(0, nb_absences):
|
|
|
|
etudid = etu.id
|
|
|
|
jour = date_debut + random.random() * (date_fin - date_debut)
|
|
|
|
estabs = True
|
|
|
|
estjust = True if random.randint(0, 1) == 1 else False
|
|
|
|
matin = True if random.randint(0, 1) == 1 else False
|
|
|
|
description = ""
|
2022-07-29 16:19:40 +02:00
|
|
|
absence = Absence(
|
|
|
|
etudid=etudid,
|
|
|
|
jour=jour,
|
|
|
|
estabs=estabs,
|
|
|
|
estjust=estjust,
|
|
|
|
matin=matin,
|
|
|
|
description=description,
|
|
|
|
)
|
|
|
|
db.session.add(absence)
|
|
|
|
db.session.commit()
|
2022-06-20 16:09:22 +02:00
|
|
|
|
2022-06-17 15:50:06 +02:00
|
|
|
|
2022-06-24 16:04:40 +02:00
|
|
|
def create_etape_apo(formsemestre: FormSemestre):
|
|
|
|
"""
|
2022-08-02 09:49:08 +02:00
|
|
|
Ajoute étapes Apogée au formsemestre
|
2022-06-24 16:04:40 +02:00
|
|
|
"""
|
2022-06-27 16:11:48 +02:00
|
|
|
etape_apo1 = FormSemestreEtape(
|
|
|
|
id=1, formsemestre_id=formsemestre.id, etape_apo="A1"
|
|
|
|
)
|
|
|
|
db.session.add(etape_apo1)
|
|
|
|
|
|
|
|
etape_apo2 = FormSemestreEtape(
|
|
|
|
id=2, formsemestre_id=formsemestre.id, etape_apo="A2"
|
|
|
|
)
|
|
|
|
db.session.add(etape_apo2)
|
|
|
|
|
|
|
|
etape_apo3 = FormSemestreEtape(
|
|
|
|
id=3, formsemestre_id=formsemestre.id, etape_apo="A3"
|
|
|
|
)
|
|
|
|
db.session.add(etape_apo3)
|
|
|
|
|
|
|
|
list_etapes = [etape_apo1, etape_apo2, etape_apo3]
|
|
|
|
formsemestre.etapes = list_etapes
|
|
|
|
db.session.commit()
|
2022-06-24 16:04:40 +02:00
|
|
|
|
|
|
|
|
2022-08-21 09:17:45 +02:00
|
|
|
def create_logos():
|
|
|
|
if not os.path.exists(LOGOS_DIR + "logos_1"):
|
|
|
|
os.mkdir(LOGOS_DIR + "logos_1")
|
|
|
|
shutil.copy(
|
|
|
|
LOGOS_STOCK + "logo_A.jpg",
|
|
|
|
LOGOS_DIR + "logos_1/logo_A.jpg",
|
|
|
|
)
|
|
|
|
shutil.copy(
|
|
|
|
LOGOS_STOCK + "logo_D.png",
|
|
|
|
LOGOS_DIR + "logos_1/logo_D.png",
|
|
|
|
)
|
|
|
|
shutil.copy(
|
|
|
|
LOGOS_STOCK + "logo_A.jpg",
|
|
|
|
LOGOS_DIR + "logo_B.jpg",
|
|
|
|
)
|
|
|
|
shutil.copy(
|
|
|
|
LOGOS_STOCK + "logo_D.png",
|
|
|
|
LOGOS_DIR + "logo_C.png",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-04-17 15:39:32 +02:00
|
|
|
def ajouter_assiduites_justificatifs(formsemestre: FormSemestre):
|
|
|
|
"""
|
|
|
|
Ajoute des assiduités semi-aléatoires à chaque étudiant du semestre
|
|
|
|
"""
|
|
|
|
MODS = [moduleimpl for moduleimpl in formsemestre.modimpls]
|
|
|
|
MODS.append(None)
|
|
|
|
|
|
|
|
for etud in formsemestre.etuds:
|
2024-06-26 11:20:28 +02:00
|
|
|
# Se base sur la date des évaluations
|
2024-01-05 13:42:55 +01:00
|
|
|
base_date = datetime.datetime(
|
2024-06-26 11:20:28 +02:00
|
|
|
2022, 3, [1, 8, 15, 22, 29][random.randint(0, 4)], 8, 0, 0
|
2024-01-05 13:42:55 +01:00
|
|
|
)
|
2023-04-17 15:39:32 +02:00
|
|
|
base_date = localize_datetime(base_date)
|
|
|
|
|
2024-06-26 11:20:28 +02:00
|
|
|
for i in range(random.randint(1, 4)):
|
2023-04-17 15:39:32 +02:00
|
|
|
etat = random.randint(0, 2)
|
|
|
|
moduleimpl = random.choice(MODS)
|
|
|
|
deb_date = base_date + datetime.timedelta(days=i)
|
|
|
|
fin_date = deb_date + datetime.timedelta(hours=i)
|
|
|
|
|
|
|
|
code = Assiduite.create_assiduite(
|
|
|
|
etud, deb_date, fin_date, etat, moduleimpl
|
|
|
|
)
|
|
|
|
|
|
|
|
assert isinstance(
|
|
|
|
code, Assiduite
|
|
|
|
), "Erreur dans la génération des assiduités"
|
|
|
|
|
|
|
|
db.session.add(code)
|
|
|
|
|
|
|
|
for i in range(random.randint(0, 2)):
|
|
|
|
etat = random.randint(0, 3)
|
|
|
|
deb_date = base_date + datetime.timedelta(days=i)
|
|
|
|
fin_date = deb_date + datetime.timedelta(hours=8)
|
|
|
|
raison = random.choice(["raison", None])
|
|
|
|
|
|
|
|
code = Justificatif.create_justificatif(
|
2023-12-22 15:18:20 +01:00
|
|
|
etud,
|
|
|
|
deb_date,
|
|
|
|
fin_date,
|
2023-04-17 15:39:32 +02:00
|
|
|
etat=etat,
|
|
|
|
raison=raison,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert isinstance(
|
|
|
|
code, Justificatif
|
|
|
|
), "Erreur dans la génération des justificatifs"
|
|
|
|
|
|
|
|
db.session.add(code)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2022-03-09 16:05:44 +01:00
|
|
|
def init_test_database():
|
2022-05-04 23:11:20 +02:00
|
|
|
"""Appelé par la commande `flask init-test-database`
|
2022-04-14 14:56:36 +02:00
|
|
|
|
2022-05-04 23:11:20 +02:00
|
|
|
Création d'un département et de son contenu pour les tests
|
|
|
|
"""
|
2022-08-05 17:05:24 +02:00
|
|
|
import app as mapp
|
|
|
|
|
|
|
|
depts = create_departements(["TAPI", "AA", "BB", "CC", "DD"])
|
|
|
|
dept = depts[0]
|
|
|
|
mapp.set_sco_dept(dept.acronym)
|
|
|
|
user_lecteur, user_autre = create_users(depts)
|
2022-05-04 23:11:20 +02:00
|
|
|
with sco_cache.DeferredSemCacheManager():
|
2022-08-07 19:56:25 +02:00
|
|
|
etuds = create_etuds(dept, nb=20)
|
2022-08-04 16:54:59 +02:00
|
|
|
formation = import_formation(dept.id)
|
2022-05-04 23:11:20 +02:00
|
|
|
formsemestre = create_formsemestre(formation, user_lecteur)
|
|
|
|
create_evaluations(formsemestre)
|
2022-08-07 19:56:25 +02:00
|
|
|
inscrit_etudiants(etuds[:16], formsemestre)
|
2022-06-09 11:08:08 +02:00
|
|
|
saisie_notes_evaluations(formsemestre, user_lecteur)
|
2022-06-20 16:09:22 +02:00
|
|
|
add_absences(formsemestre)
|
2022-06-24 16:03:35 +02:00
|
|
|
create_etape_apo(formsemestre)
|
2023-04-17 15:39:32 +02:00
|
|
|
ajouter_assiduites_justificatifs(formsemestre)
|
2022-08-21 09:17:45 +02:00
|
|
|
create_logos()
|
2022-03-09 16:05:44 +01:00
|
|
|
# à compléter
|
|
|
|
# - groupes
|
|
|
|
# - absences
|
|
|
|
# - notes
|
|
|
|
# - décisions de jury
|
|
|
|
# ...
|