forked from ScoDoc/ScoDoc
Test basic: modules, sems, notes
This commit is contained in:
parent
0864917a5f
commit
274d39a3ec
@ -63,7 +63,14 @@ su -c ./create_database.sh "$POSTGRES_SUPERUSER"
|
||||
|
||||
# ----------------------- Create tables
|
||||
# POSTGRES_USER == regular unix user (www-data)
|
||||
if [ "$interactive" = 1 ]
|
||||
then
|
||||
su -c ./initialize_database.sh "$POSTGRES_USER"
|
||||
else
|
||||
su -c ./initialize_database.sh "$POSTGRES_USER" > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# ----------------------- Enregistre fichier config
|
||||
echo "dbname=${db_name}" > "$cfg_pathname"
|
||||
|
@ -6,6 +6,7 @@ A utiliser avec debug.py (côté serveur).
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
from functools import wraps
|
||||
import sys
|
||||
import string
|
||||
import pprint
|
||||
@ -16,13 +17,16 @@ random.seed(12345) # tests reproductibles
|
||||
from debug import REQUEST
|
||||
|
||||
import sco_utils
|
||||
from notes_log import log
|
||||
from sco_exceptions import ScoValueError
|
||||
import scolars
|
||||
import sco_formsemestre
|
||||
import sco_formsemestre_inscriptions
|
||||
import sco_synchro_etuds
|
||||
import sco_edit_formation
|
||||
import sco_edit_ue
|
||||
import sco_codes_parcours
|
||||
from notes_log import log
|
||||
import sco_saisie_notes
|
||||
|
||||
DEMODIR = sco_utils.SCO_SRCDIR + "/scotests/demo/"
|
||||
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))
|
||||
|
||||
|
||||
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:
|
||||
def __init__(self, context, verbose=True):
|
||||
self.context = context
|
||||
@ -57,6 +71,7 @@ class ScoFake:
|
||||
prenom = random.choice(PRENOMS_H)
|
||||
return sexe, random.choice(NOMS).upper(), prenom.upper()
|
||||
|
||||
@logging_meth
|
||||
def create_etud(
|
||||
self,
|
||||
cnx=None,
|
||||
@ -94,14 +109,13 @@ class ScoFake:
|
||||
if not prenom:
|
||||
prenom = r_prenom
|
||||
etud = scolars.create_etud(self.context, cnx, args=locals(), REQUEST=REQUEST)
|
||||
pprint.pprint(etud)
|
||||
self.log("create_etud( %s %s %s ) -> %s" % (sexe, prenom, nom, etud["etudid"]))
|
||||
inscription = "2020"
|
||||
inscription = "2020" # pylint: disable=unused-variable
|
||||
sco_synchro_etuds.do_import_etud_admission(
|
||||
self.context, cnx, etud["etudid"], locals()
|
||||
)
|
||||
return etud
|
||||
|
||||
@logging_meth
|
||||
def create_formation(
|
||||
self,
|
||||
acronyme="test",
|
||||
@ -114,29 +128,161 @@ class ScoFake:
|
||||
"""Crée une formation"""
|
||||
if acronyme == "":
|
||||
acronyme = "TEST" + str(random.randint(100000, 999999))
|
||||
formation_id = self.context.do_formation_create(locals(), REQUEST=REQUEST)
|
||||
Flist = self.context.formation_list(args={"formation_id": formation_id})
|
||||
if not Flist:
|
||||
raise ScoValueError("formation inexistante !")
|
||||
self.log(
|
||||
"create_formation( %s %s ) -> %s"
|
||||
% (acronyme, titre, Flist[0]["formation_id"])
|
||||
)
|
||||
return Flist[0]
|
||||
oid = self.context.do_formation_create(locals(), REQUEST=REQUEST)
|
||||
oids = self.context.formation_list(args={"formation_id": oid})
|
||||
if not oids:
|
||||
raise ScoValueError("formation not created !")
|
||||
return oids[0]
|
||||
|
||||
def create_ue(self):
|
||||
pass
|
||||
@logging_meth
|
||||
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):
|
||||
pass
|
||||
@logging_meth
|
||||
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(
|
||||
self.context,
|
||||
sem["formsemestre_id"],
|
||||
etud["etudid"],
|
||||
etat="I",
|
||||
etape=etud["etape"],
|
||||
etape=etud.get("etape", None),
|
||||
REQUEST=REQUEST,
|
||||
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,
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ if [ "$recreate_dept" = 1 ]
|
||||
then
|
||||
(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"
|
||||
systemctl start scodoc
|
||||
# systemctl start scodoc
|
||||
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""');"
|
||||
|
@ -9,9 +9,58 @@ Utiliser comme:
|
||||
scotests/scointeractive.sh -r TEST00 scotests/test_basic.py
|
||||
|
||||
"""
|
||||
import random
|
||||
|
||||
import scotests.sco_fake_gen as sco_fake_gen
|
||||
import sco_utils
|
||||
|
||||
G = sco_fake_gen.ScoFake(context.Notes) # pylint: disable=undefined-variable
|
||||
G.verbose = False
|
||||
|
||||
etud = G.create_etud(code_nip=None)
|
||||
F = G.create_formation(acronyme="")
|
||||
# --- Création d'étudiants
|
||||
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))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user