1
0
forked from ScoDoc/ScoDoc

correction bug génération date random pour tests unitaires

This commit is contained in:
leonard_montalbano 2022-06-09 11:08:08 +02:00
parent d3e7ababd8
commit 25422b7f81
2 changed files with 52 additions and 48 deletions

View File

@ -47,6 +47,14 @@ class NotesNotes(db.Model):
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
uid = db.Column(db.Integer, db.ForeignKey("user.id"))
def __init__(self, etudid, evaluation_id, value, comment, date, uid):
self.etudid = etudid
self.evaluation_id = evaluation_id
self.value = value
self.comment = comment
self.date = date
self.uid = uid
def to_dict(self):
return {
"id": self.id,

View File

@ -10,7 +10,7 @@
FLASK_DEBUG=1
2) En tant qu'utilisateur scodoc, lancer:
tools/create_database.sh SCODOC_TEST_API
tools/create_database.sh SCODOC_TEST_API_EVAL
flask db upgrade
flask sco-db-init --erase
flask init-test-database
@ -24,11 +24,19 @@
"""
import datetime
import random
import time
import sys
from app.auth.models import Role, User
from app import models
from app.models import Departement, Formation, FormSemestre, Identite, ModuleImpl
from app.models import (
Departement,
Formation,
FormSemestre,
Identite,
ModuleImpl,
NotesNotes,
)
from app import db
from app.scodoc import (
sco_cache,
@ -189,35 +197,21 @@ def create_evaluations(formsemestre: FormSemestre):
evaluation_id = sco_evaluation_db.do_evaluation_create(**args)
def saisie_note_evaluations(formsemestre: FormSemestre, user: User):
def saisie_notes_evaluations(formsemestre: FormSemestre, user: User):
"""
Saisie les notes des evaluations d'un semestre
"""
# Récupération des id des étudiants du semestre
list_etudids = [etud.id for etud in formsemestre.etuds]
etuds = formsemestre.etuds
list_etuds = []
for etu in etuds:
list_etuds.append(etu)
def add_random_notes(evaluation_id, new_list_notes_eval=None, not_all=False):
"""
Permet d'ajouter des notes aléatoires à une évaluation
"""
if not_all:
percent = 80 / 100
len_list_etudids = len(list_etudids)
new_list_etudids = random.sample(
list_etudids, k=int(percent * len_list_etudids)
)
# new_list_etudids = [note.etudid for note in new_list_notes_eval]
list_tuple_notes = [
(etudid, random.uniform(0.0, 20.0)) for etudid in new_list_etudids
]
notes_add(user, evaluation_id, list_tuple_notes)
else:
list_tuple_notes = [
(etudid, random.uniform(0.0, 20.0)) for etudid in list_etudids
]
notes_add(user, evaluation_id, list_tuple_notes)
date_debut = formsemestre.date_debut
date_fin = formsemestre.date_fin
def saisir_notes(evaluation_id: int, condition: int, list_notes_eval):
list_ues = formsemestre.query_ues()
def saisir_notes(evaluation_id: int, condition: int):
"""
Permet de saisir les notes de manière aléatoire suivant une condition
Définition des valeurs de condition :
@ -226,39 +220,41 @@ def saisie_note_evaluations(formsemestre: FormSemestre, user: User):
2 : some_notes_manquantes
"""
if condition == 0 or condition == 2:
date_debut = formsemestre.date_debut
date_fin = formsemestre.date_fin
if condition == 0:
add_random_notes(evaluation_id)
for note in list_notes_eval:
note.date = date_debut + random.random() * (date_fin - date_debut)
for etu in list_etuds:
note = NotesNotes(
etu.id,
evaluation_id,
random.uniform(0, 20),
"",
date_debut + random.random() * (date_fin - date_debut),
user.id,
)
db.session.add(note)
db.session.commit()
else:
percent = 80 / 100
len_list_notes_eval = len(list_notes_eval)
new_list_notes_eval = random.sample(
list_notes_eval, k=int(percent * len_list_notes_eval)
len_etuds = len(list_etuds)
new_list_etuds = random.sample(list_etuds, k=int(percent * len_etuds))
for etu in new_list_etuds:
note = NotesNotes(
etu.id,
evaluation_id,
random.uniform(0, 20),
"",
date_debut + random.random() * (date_fin - date_debut),
user.id,
)
add_random_notes(evaluation_id, new_list_notes_eval, True)
for note in new_list_notes_eval:
note.date = date_debut + random.random() * (date_fin - date_debut)
db.session.add(note)
db.session.commit()
list_ues = formsemestre.query_ues()
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:
# Récupération de toutes les notes de l'évaluation
notes_eval = models.NotesNotes.query.filter_by(
evaluation_id=evaluation.id
).all()
condition_saisie_notes = random.randint(0, 2)
saisir_notes(evaluation.id, condition_saisie_notes, notes_eval)
saisir_notes(evaluation.id, condition_saisie_notes)
def init_test_database():
@ -274,7 +270,7 @@ def init_test_database():
formsemestre = create_formsemestre(formation, user_lecteur)
create_evaluations(formsemestre)
inscrit_etudiants(etuds, formsemestre)
saisie_note_evaluations(formsemestre, user_lecteur)
saisie_notes_evaluations(formsemestre, user_lecteur)
# à compléter
# - groupes
# - absences