Test basic: modules, sems, notes

This commit is contained in:
viennet 2020-12-27 13:45:24 +01:00
parent 0864917a5f
commit 274d39a3ec
4 changed files with 225 additions and 23 deletions

View File

@ -63,7 +63,14 @@ su -c ./create_database.sh "$POSTGRES_SUPERUSER"
# ----------------------- Create tables # ----------------------- Create tables
# POSTGRES_USER == regular unix user (www-data) # POSTGRES_USER == regular unix user (www-data)
if [ "$interactive" = 1 ]
then
su -c ./initialize_database.sh "$POSTGRES_USER" su -c ./initialize_database.sh "$POSTGRES_USER"
else
su -c ./initialize_database.sh "$POSTGRES_USER" > /dev/null 2>&1
fi
# ----------------------- Enregistre fichier config # ----------------------- Enregistre fichier config
echo "dbname=${db_name}" > "$cfg_pathname" echo "dbname=${db_name}" > "$cfg_pathname"

View File

@ -6,6 +6,7 @@ A utiliser avec debug.py (côté serveur).
""" """
from __future__ import print_function from __future__ import print_function
from functools import wraps
import sys import sys
import string import string
import pprint import pprint
@ -16,13 +17,16 @@ random.seed(12345) # tests reproductibles
from debug import REQUEST from debug import REQUEST
import sco_utils import sco_utils
from notes_log import log
from sco_exceptions import ScoValueError from sco_exceptions import ScoValueError
import scolars import scolars
import sco_formsemestre
import sco_formsemestre_inscriptions import sco_formsemestre_inscriptions
import sco_synchro_etuds import sco_synchro_etuds
import sco_edit_formation import sco_edit_formation
import sco_edit_ue
import sco_codes_parcours import sco_codes_parcours
from notes_log import log import sco_saisie_notes
DEMODIR = sco_utils.SCO_SRCDIR + "/scotests/demo/" DEMODIR = sco_utils.SCO_SRCDIR + "/scotests/demo/"
NOMS = [x.strip() for x in open(DEMODIR + "/noms.txt").readlines()] NOMS = [x.strip() for x in open(DEMODIR + "/noms.txt").readlines()]
@ -35,6 +39,16 @@ def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return "".join(random.choice(chars) for _ in range(size)) return "".join(random.choice(chars) for _ in range(size))
def logging_meth(func):
@wraps(func)
def wrapper_logging_meth(self, *args, **kwargs):
r = func(self, *args, **kwargs)
self.log("%s(%s) -> \n%s" % (func.__name__, kwargs, pprint.pformat(r)))
return r
return wrapper_logging_meth
class ScoFake: class ScoFake:
def __init__(self, context, verbose=True): def __init__(self, context, verbose=True):
self.context = context self.context = context
@ -57,6 +71,7 @@ class ScoFake:
prenom = random.choice(PRENOMS_H) prenom = random.choice(PRENOMS_H)
return sexe, random.choice(NOMS).upper(), prenom.upper() return sexe, random.choice(NOMS).upper(), prenom.upper()
@logging_meth
def create_etud( def create_etud(
self, self,
cnx=None, cnx=None,
@ -94,14 +109,13 @@ class ScoFake:
if not prenom: if not prenom:
prenom = r_prenom prenom = r_prenom
etud = scolars.create_etud(self.context, cnx, args=locals(), REQUEST=REQUEST) etud = scolars.create_etud(self.context, cnx, args=locals(), REQUEST=REQUEST)
pprint.pprint(etud) inscription = "2020" # pylint: disable=unused-variable
self.log("create_etud( %s %s %s ) -> %s" % (sexe, prenom, nom, etud["etudid"]))
inscription = "2020"
sco_synchro_etuds.do_import_etud_admission( sco_synchro_etuds.do_import_etud_admission(
self.context, cnx, etud["etudid"], locals() self.context, cnx, etud["etudid"], locals()
) )
return etud return etud
@logging_meth
def create_formation( def create_formation(
self, self,
acronyme="test", acronyme="test",
@ -114,29 +128,161 @@ class ScoFake:
"""Crée une formation""" """Crée une formation"""
if acronyme == "": if acronyme == "":
acronyme = "TEST" + str(random.randint(100000, 999999)) acronyme = "TEST" + str(random.randint(100000, 999999))
formation_id = self.context.do_formation_create(locals(), REQUEST=REQUEST) oid = self.context.do_formation_create(locals(), REQUEST=REQUEST)
Flist = self.context.formation_list(args={"formation_id": formation_id}) oids = self.context.formation_list(args={"formation_id": oid})
if not Flist: if not oids:
raise ScoValueError("formation inexistante !") raise ScoValueError("formation not created !")
self.log( return oids[0]
"create_formation( %s %s ) -> %s"
% (acronyme, titre, Flist[0]["formation_id"])
)
return Flist[0]
def create_ue(self): @logging_meth
pass def create_ue(
self,
formation_id=None,
acronyme=None,
numero=None,
titre="",
type=None,
ue_code=None,
ects=None,
is_external=None,
code_apogee=None,
coefficient=None,
):
"""Crée une UE"""
if numero is None:
numero = sco_edit_ue.next_ue_numero(self.context, formation_id, 0)
oid = self.context.do_ue_create(locals(), REQUEST)
oids = self.context.do_ue_list(args={"ue_id": oid})
if not oids:
raise ScoValueError("ue not created !")
return oids[0]
def create_fake_sem(self): @logging_meth
pass def create_matiere(self, ue_id=None, titre=None, numero=None):
oid = self.context.do_matiere_create(locals(), REQUEST)
oids = self.context.do_matiere_list(args={"matiere_id": oid})
if not oids:
raise ScoValueError("matiere not created !")
return oids[0]
def test_inscrit_etudiant(self, sem, etud): @logging_meth
def create_module(
self,
titre=None,
code=None,
heures_cours=None,
heures_td=None,
heures_tp=None,
coefficient=None,
ue_id=None,
formation_id=None,
matiere_id=None,
semestre_id=1,
numero=None,
abbrev=None,
ects=None,
code_apogee=None,
module_type=None,
):
oid = self.context.do_module_create(locals(), REQUEST)
oids = self.context.do_module_list(args={"module_id": oid})
if not oids:
raise ScoValueError("module not created ! (oid=%s)" % oid)
return oids[0]
@logging_meth
def create_formsemestre(
self,
formation_id=None,
semestre_id=None,
titre=None,
date_debut=None,
date_fin=None,
etat=None,
gestion_compensation=None,
bul_hide_xml=None,
gestion_semestrielle=None,
bul_bgcolor=None,
modalite=None,
resp_can_edit=None,
resp_can_change_ens=None,
ens_can_edit_eval=None,
elt_sem_apo=None,
elt_annee_apo=None,
etapes=None,
responsables=None,
):
oid = self.context.do_formsemestre_create(locals(), REQUEST)
# oids = self.context.do_formsemestre_list(args={"formsemestre_id": oid})
oids = sco_formsemestre.do_formsemestre_list(
self.context, args={"formsemestre_id": oid}
) # API inconsistency
if not oids:
raise ScoValueError("formsemestre not created !")
return oids[0]
@logging_meth
def create_moduleimpl(
self,
module_id=None,
formsemestre_id=None,
responsable_id=None,
):
oid = self.context.do_moduleimpl_create(locals())
oids = self.context.do_moduleimpl_list(moduleimpl_id=oid) # API inconsistency
if not oids:
raise ScoValueError("moduleimpl not created !")
return oids[0]
@logging_meth
def inscrit_etudiant(self, sem, etud):
sco_formsemestre_inscriptions.do_formsemestre_inscription_with_modules( sco_formsemestre_inscriptions.do_formsemestre_inscription_with_modules(
self.context, self.context,
sem["formsemestre_id"], sem["formsemestre_id"],
etud["etudid"], etud["etudid"],
etat="I", etat="I",
etape=etud["etape"], etape=etud.get("etape", None),
REQUEST=REQUEST, REQUEST=REQUEST,
method="test_inscrit_etudiant", method="test_inscrit_etudiant",
) )
@logging_meth
def create_evaluation(
self,
moduleimpl_id=None,
jour=None,
heure_debut="8h00",
heure_fin="9h00",
description=None,
note_max=20,
coefficient=None,
visibulletin=None,
publish_incomplete=None,
evaluation_type=None,
numero=None,
REQUEST=REQUEST,
):
args = locals()
del args["self"]
oid = self.context.do_evaluation_create(**args)
oids = self.context.do_evaluation_list(args={"evaluation_id": oid})
if not oids:
raise ScoValueError("evaluation not created !")
return oids[0]
@logging_meth
def create_note(
self,
evaluation=None,
etud=None,
note=None,
comment=None,
uid="bach",
):
return sco_saisie_notes._notes_add(
self.context,
uid,
evaluation["evaluation_id"],
[(etud["etudid"], note)],
comment=comment,
)

View File

@ -38,7 +38,7 @@ if [ "$recreate_dept" = 1 ]
then then
(cd config || terminate "no config directory"; ./delete_dept.sh -n "$DEPT") || terminate "error deleting dept $DEPT" (cd config || terminate "no config directory"; ./delete_dept.sh -n "$DEPT") || terminate "error deleting dept $DEPT"
(cd config || terminate "no config directory"; ./create_dept.sh -n "$DEPT") || terminate "error creating dept $DEPT" (cd config || terminate "no config directory"; ./create_dept.sh -n "$DEPT") || terminate "error creating dept $DEPT"
systemctl start scodoc # systemctl start scodoc
fi fi
cmd="from __future__ import print_function;from Zope2 import configure;configure('/opt/scodoc/etc/zope.conf');import Zope2; app=Zope2.app();from debug import *;context = go_dept(app, '""$DEPT""');" cmd="from __future__ import print_function;from Zope2 import configure;configure('/opt/scodoc/etc/zope.conf');import Zope2; app=Zope2.app();from debug import *;context = go_dept(app, '""$DEPT""');"

View File

@ -9,9 +9,58 @@ Utiliser comme:
scotests/scointeractive.sh -r TEST00 scotests/test_basic.py scotests/scointeractive.sh -r TEST00 scotests/test_basic.py
""" """
import random
import scotests.sco_fake_gen as sco_fake_gen import scotests.sco_fake_gen as sco_fake_gen
import sco_utils
G = sco_fake_gen.ScoFake(context.Notes) # pylint: disable=undefined-variable G = sco_fake_gen.ScoFake(context.Notes) # pylint: disable=undefined-variable
G.verbose = False
etud = G.create_etud(code_nip=None) # --- Création d'étudiants
F = G.create_formation(acronyme="") etuds = [G.create_etud(code_nip=None) for _ in range(10)]
# --- Création d'une formation
f = G.create_formation(acronyme="")
ue = G.create_ue(formation_id=f["formation_id"], acronyme="TST1", titre="ue test")
mat = G.create_matiere(ue_id=ue["ue_id"], titre="matière test")
mod = G.create_module(
matiere_id=mat["matiere_id"],
code="TSM1",
coefficient=1.0,
titre="module test",
ue_id=ue["ue_id"], # faiblesse de l'API
formation_id=f["formation_id"], # faiblesse de l'API
)
# --- Mise place d'un semestre
sem = G.create_formsemestre(
formation_id=f["formation_id"],
semestre_id=1,
date_debut="01/01/2020",
date_fin="30/06/2020",
)
mi = G.create_moduleimpl(
module_id=mod["module_id"],
formsemestre_id=sem["formsemestre_id"],
responsable_id="bach",
)
# --- Inscription des étudiants
for etud in etuds:
G.inscrit_etudiant(sem, etud)
# --- Creation évaluation
e = G.create_evaluation(
moduleimpl_id=mi["moduleimpl_id"],
jour="01/01/2020",
description="evaluation test",
coefficient=1.0,
)
# --- Saisie notes
for etud in etuds:
nb_changed, nb_suppress, existing_decisions = G.create_note(
evaluation=e, etud=etud, note=float(random.randint(0, 20))
)