pass unit test_formations

This commit is contained in:
Emmanuel Viennet 2021-08-10 09:10:36 +02:00
parent 02df06c29a
commit 642283c7d8
10 changed files with 56 additions and 34 deletions

View File

@ -246,12 +246,10 @@ def DBUpdateArgs(cnx, table, vals, where=None, commit=False, convert_empty_to_nu
cnx.commit() cnx.commit()
def DBDelete(cnx, table, colid, val, commit=False): def DBDelete(cnx, table, oid, commit=False):
cursor = cnx.cursor(cursor_factory=ScoDocCursor) cursor = cnx.cursor(cursor_factory=ScoDocCursor)
try: try:
cursor.execute( cursor.execute("delete from " + table + " where id=%(oid)s", {"oid": oid})
"delete from " + table + " where %s=%%(%s)s" % (colid, colid), {colid: val}
)
except: except:
cnx.commit() # get rid of this transaction cnx.commit() # get rid of this transaction
raise # and re-raise exception raise # and re-raise exception
@ -315,7 +313,7 @@ class EditableTable(object):
def delete(self, cnx, oid, commit=True): def delete(self, cnx, oid, commit=True):
"delete tuple" "delete tuple"
DBDelete(cnx, self.table_name, self.id_name, oid, commit=commit) DBDelete(cnx, self.table_name, oid, commit=commit)
def list( def list(
self, self,

View File

@ -76,7 +76,7 @@ class ScoDocCache:
@classmethod @classmethod
def _get_key(cls, oid): def _get_key(cls, oid):
return g.scodoc_dept + "_" + cls.prefix + "_" + oid return g.scodoc_dept + "_" + cls.prefix + "_" + str(oid)
@classmethod @classmethod
def get(cls, oid): def get(cls, oid):
@ -175,7 +175,8 @@ class SemBulletinsPDFCache(ScoDocCache):
"""Clear cached pdf for all given formsemestres""" """Clear cached pdf for all given formsemestres"""
for version in scu.BULLETINS_VERSIONS: for version in scu.BULLETINS_VERSIONS:
oids = [ oids = [
formsemestre_id + "_" + version for formsemestre_id in formsemestre_ids str(formsemestre_id) + "_" + version
for formsemestre_id in formsemestre_ids
] ]
cls.delete_many(oids) cls.delete_many(oids)

View File

@ -71,7 +71,7 @@ _formsemestreEditor = ndb.EditableTable(
"date_fin": ndb.DateISOtoDMY, "date_fin": ndb.DateISOtoDMY,
"gestion_compensation": str, "gestion_compensation": str,
"gestion_semestrielle": str, "gestion_semestrielle": str,
"etat": str, "etat": bool,
"bul_hide_xml": str, "bul_hide_xml": str,
}, },
input_formators={ input_formators={
@ -79,7 +79,7 @@ _formsemestreEditor = ndb.EditableTable(
"date_fin": ndb.DateDMYtoISO, "date_fin": ndb.DateDMYtoISO,
"gestion_compensation": int, "gestion_compensation": int,
"gestion_semestrielle": int, "gestion_semestrielle": int,
"etat": int, "etat": bool,
"bul_hide_xml": int, "bul_hide_xml": int,
}, },
) )

View File

@ -1421,12 +1421,31 @@ def do_formsemestre_delete(context, formsemestre_id):
req = "DELETE FROM sco_prefs WHERE formsemestre_id=%(formsemestre_id)s" req = "DELETE FROM sco_prefs WHERE formsemestre_id=%(formsemestre_id)s"
cursor.execute(req, {"formsemestre_id": formsemestre_id}) cursor.execute(req, {"formsemestre_id": formsemestre_id})
# --- Suppression des groupes et partitions # --- Suppression des groupes et partitions
req = "DELETE FROM group_membership WHERE group_id IN (SELECT gm.group_id FROM group_membership gm, partition p, group_descr gd WHERE gm.group_id = gd.group_id AND gd.partition_id = p.partition_id AND p.formsemestre_id=%(formsemestre_id)s)" req = """DELETE FROM group_membership
WHERE group_id IN
(SELECT gm.group_id FROM group_membership gm, partition p, group_descr gd
WHERE gm.group_id = gd.id AND gd.partition_id = p.id
AND p.formsemestre_id=%(formsemestre_id)s)
"""
cursor.execute(req, {"formsemestre_id": formsemestre_id}) cursor.execute(req, {"formsemestre_id": formsemestre_id})
req = "DELETE FROM group_descr WHERE group_id IN (SELECT gd.group_id FROM group_descr gd, partition p WHERE gd.partition_id = p.partition_id AND p.formsemestre_id=%(formsemestre_id)s)" req = """DELETE FROM group_descr
WHERE id IN
(SELECT gd.id FROM group_descr gd, partition p
WHERE gd.partition_id = p.id
AND p.formsemestre_id=%(formsemestre_id)s)
"""
cursor.execute(req, {"formsemestre_id": formsemestre_id}) cursor.execute(req, {"formsemestre_id": formsemestre_id})
req = "DELETE FROM partition WHERE formsemestre_id=%(formsemestre_id)s" req = "DELETE FROM partition WHERE formsemestre_id=%(formsemestre_id)s"
cursor.execute(req, {"formsemestre_id": formsemestre_id}) cursor.execute(req, {"formsemestre_id": formsemestre_id})
# --- Responsables
req = """DELETE FROM notes_formsemestre_responsables
WHERE formsemestre_id=%(formsemestre_id)s"""
cursor.execute(req, {"formsemestre_id": formsemestre_id})
# --- Etapes
req = """DELETE FROM notes_formsemestre_etapes
WHERE formsemestre_id=%(formsemestre_id)s"""
cursor.execute(req, {"formsemestre_id": formsemestre_id})
# --- Destruction du semestre # --- Destruction du semestre
sco_formsemestre._formsemestreEditor.delete(cnx, formsemestre_id) sco_formsemestre._formsemestreEditor.delete(cnx, formsemestre_id)

View File

@ -185,7 +185,7 @@ def get_partition_groups(context, partition):
"""SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.* """SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.*
FROM group_descr gd, partition p FROM group_descr gd, partition p
WHERE gd.partition_id=%(partition_id)s WHERE gd.partition_id=%(partition_id)s
AND gd.partition_id=p.partition_id AND gd.partition_id=p.id
ORDER BY group_name ORDER BY group_name
""", """,
partition, partition,
@ -200,7 +200,7 @@ def get_default_group(formsemestre_id, fix_if_missing=False):
FROM group_descr gd, partition p FROM group_descr gd, partition p
WHERE p.formsemestre_id=%(formsemestre_id)s WHERE p.formsemestre_id=%(formsemestre_id)s
AND p.partition_name is NULL AND p.partition_name is NULL
AND p.partition_id = gd.partition_id AND p.id = gd.partition_id
""", """,
{"formsemestre_id": formsemestre_id}, {"formsemestre_id": formsemestre_id},
) )
@ -230,10 +230,10 @@ def get_default_group(formsemestre_id, fix_if_missing=False):
def get_sem_groups(context, formsemestre_id): def get_sem_groups(context, formsemestre_id):
"""Returns groups for this sem (in all partitions).""" """Returns groups for this sem (in all partitions)."""
return ndb.SimpleDictFetch( return ndb.SimpleDictFetch(
"""SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.* """SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.*
FROM group_descr gd, partition p FROM group_descr gd, partition p
WHERE p.formsemestre_id=%(formsemestre_id)s WHERE p.formsemestre_id=%(formsemestre_id)s
AND p.partition_id = gd.partition_id AND p.id = gd.partition_id
""", """,
{"formsemestre_id": formsemestre_id}, {"formsemestre_id": formsemestre_id},
) )
@ -244,7 +244,7 @@ def get_group_members(context, group_id, etat=None):
Si etat, filtre selon l'état de l'inscription Si etat, filtre selon l'état de l'inscription
Trié par nom_usuel (ou nom) puis prénom Trié par nom_usuel (ou nom) puis prénom
""" """
req = """SELECT i.id as etudid, i.*, a.*, gm.*, ins.etat req = """SELECT i.id as etudid, i.*, a.*, gm.*, ins.etat
FROM identite i, adresse a, group_membership gm, FROM identite i, adresse a, group_membership gm,
group_descr gd, partition p, notes_formsemestre_inscription ins group_descr gd, partition p, notes_formsemestre_inscription ins
WHERE i.id = gm.etudid WHERE i.id = gm.etudid

View File

@ -1094,13 +1094,13 @@ def list_formsemestre_utilisateurs_uecap(context, formsemestre_id):
)[0] )[0]
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
cursor.execute( cursor.execute(
"""select sem.formsemestre_id """SELECT sem.id
from notes_formsemestre sem, notes_formations F FROM notes_formsemestre sem, notes_formations F
where sem.formation_id = F.formation_id WHERE sem.formation_id = F.id
and F.formation_code = %(formation_code)s and F.formation_code = %(formation_code)s
and sem.semestre_id = %(semestre_id)s and sem.semestre_id = %(semestre_id)s
and sem.date_debut >= %(date_debut)s and sem.date_debut >= %(date_debut)s
and sem.formsemestre_id != %(formsemestre_id)s; and sem.id != %(formsemestre_id)s;
""", """,
{ {
"formation_code": F["formation_code"], "formation_code": F["formation_code"],

View File

@ -176,7 +176,7 @@ def can_change_groups(formsemestre_id):
context = None # XXX #context context = None # XXX #context
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
if sem["etat"] != "1": if not sem["etat"]:
return False # semestre verrouillé return False # semestre verrouillé
if current_user.has_permission(Permission.ScoEtudChangeGroups): if current_user.has_permission(Permission.ScoEtudChangeGroups):
return True # admin, chef dept return True # admin, chef dept

View File

@ -42,6 +42,7 @@ def test_client():
admin_role = Role.query.filter_by(name="Admin").first() admin_role = Role.query.filter_by(name="Admin").first()
u.add_role(admin_role, "TEST00") u.add_role(admin_role, "TEST00")
db.session.add(u) db.session.add(u)
db.session.commit()
ndb.set_sco_dept("TEST") # set db connection ndb.set_sco_dept("TEST") # set db connection
yield client yield client
# ndb.close_dept_connection() # ndb.close_dept_connection()

View File

@ -9,14 +9,15 @@ facilement des tests ou de reproduire des bugs.
""" """
from functools import wraps from functools import wraps
import random
import sys import sys
import string import string
import collections import typing
import pprint
import random
import scodoc_manager import scodoc_manager
from config import Config from config import Config
from app.auth.models import User
from app.scodoc import notesdb as ndb from app.scodoc import notesdb as ndb
from app.scodoc import sco_codes_parcours from app.scodoc import sco_codes_parcours
from app.scodoc import sco_edit_formation from app.scodoc import sco_edit_formation
@ -70,6 +71,9 @@ class ScoFake(object):
def __init__(self, verbose=True): def __init__(self, verbose=True):
self.verbose = verbose self.verbose = verbose
self.default_user = User.query.filter_by(user_name="bach").first()
if not self.default_user:
raise ScoValueError('User test "bach" not found !')
def log(self, msg): def log(self, msg):
if self.verbose: if self.verbose:
@ -231,8 +235,10 @@ class ScoFake(object):
elt_sem_apo=None, elt_sem_apo=None,
elt_annee_apo=None, elt_annee_apo=None,
etapes=None, etapes=None,
responsables=("bach",), responsables=None, # sequence of resp. ids
): ):
if responsables is None:
responsables = (self.default_user.id,)
oid = sco_formsemestre.do_formsemestre_create(locals()) oid = sco_formsemestre.do_formsemestre_create(locals())
oids = sco_formsemestre.do_formsemestre_list( oids = sco_formsemestre.do_formsemestre_list(
context, args={"formsemestre_id": oid} context, args={"formsemestre_id": oid}
@ -244,10 +250,12 @@ class ScoFake(object):
@logging_meth @logging_meth
def create_moduleimpl( def create_moduleimpl(
self, self,
module_id=None, module_id: int = None,
formsemestre_id=None, formsemestre_id: int = None,
responsable_id=None, responsable_id: typing.Optional[int] = None,
): ):
if not responsable_id:
responsable_id = self.default_user.id
oid = sco_moduleimpl.do_moduleimpl_create(context, locals()) oid = sco_moduleimpl.do_moduleimpl_create(context, locals())
oids = sco_moduleimpl.do_moduleimpl_list( oids = sco_moduleimpl.do_moduleimpl_list(
context, moduleimpl_id=oid context, moduleimpl_id=oid
@ -299,7 +307,7 @@ class ScoFake(object):
etud=None, etud=None,
note=None, note=None,
comment=None, comment=None,
uid="bach", uid: typing.Optional[int] = None,
): ):
return sco_saisie_notes._notes_add( return sco_saisie_notes._notes_add(
context, context,

View File

@ -138,19 +138,16 @@ def test_formations(test_client):
mi = G.create_moduleimpl( mi = G.create_moduleimpl(
module_id=mod["module_id"], module_id=mod["module_id"],
formsemestre_id=sem1["formsemestre_id"], formsemestre_id=sem1["formsemestre_id"],
responsable_id="bach",
) )
mi2 = G.create_moduleimpl( mi2 = G.create_moduleimpl(
module_id=mod2["module_id"], module_id=mod2["module_id"],
formsemestre_id=sem1["formsemestre_id"], formsemestre_id=sem1["formsemestre_id"],
responsable_id="bach",
) )
mit = G.create_moduleimpl( mit = G.create_moduleimpl(
module_id=modt["module_id"], module_id=modt["module_id"],
formsemestre_id=sem2["formsemestre_id"], formsemestre_id=sem2["formsemestre_id"],
responsable_id="bach",
) )
semt = G.create_formsemestre( semt = G.create_formsemestre(
@ -163,7 +160,6 @@ def test_formations(test_client):
mi3 = G.create_moduleimpl( mi3 = G.create_moduleimpl(
module_id=mod3["module_id"], module_id=mod3["module_id"],
formsemestre_id=semt["formsemestre_id"], formsemestre_id=semt["formsemestre_id"],
responsable_id="bach",
) )
# --- Afficher la liste des formations # --- Afficher la liste des formations
@ -379,7 +375,6 @@ def test_import_formation(test_client):
mi = G.create_moduleimpl( mi = G.create_moduleimpl(
module_id=mod["module_id"], module_id=mod["module_id"],
formsemestre_id=sems[mod["semestre_id"] - 1]["formsemestre_id"], formsemestre_id=sems[mod["semestre_id"] - 1]["formsemestre_id"],
responsable_id="bach",
) )
assert mi["ens"] == [] assert mi["ens"] == []
assert mi["module_id"] == mod["module_id"] assert mi["module_id"] == mod["module_id"]