forked from ScoDoc/ScoDoc
pass unit test_formations
This commit is contained in:
parent
02df06c29a
commit
642283c7d8
@ -246,12 +246,10 @@ def DBUpdateArgs(cnx, table, vals, where=None, commit=False, convert_empty_to_nu
|
||||
cnx.commit()
|
||||
|
||||
|
||||
def DBDelete(cnx, table, colid, val, commit=False):
|
||||
def DBDelete(cnx, table, oid, commit=False):
|
||||
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
|
||||
try:
|
||||
cursor.execute(
|
||||
"delete from " + table + " where %s=%%(%s)s" % (colid, colid), {colid: val}
|
||||
)
|
||||
cursor.execute("delete from " + table + " where id=%(oid)s", {"oid": oid})
|
||||
except:
|
||||
cnx.commit() # get rid of this transaction
|
||||
raise # and re-raise exception
|
||||
@ -315,7 +313,7 @@ class EditableTable(object):
|
||||
|
||||
def delete(self, cnx, oid, commit=True):
|
||||
"delete tuple"
|
||||
DBDelete(cnx, self.table_name, self.id_name, oid, commit=commit)
|
||||
DBDelete(cnx, self.table_name, oid, commit=commit)
|
||||
|
||||
def list(
|
||||
self,
|
||||
|
@ -76,7 +76,7 @@ class ScoDocCache:
|
||||
|
||||
@classmethod
|
||||
def _get_key(cls, oid):
|
||||
return g.scodoc_dept + "_" + cls.prefix + "_" + oid
|
||||
return g.scodoc_dept + "_" + cls.prefix + "_" + str(oid)
|
||||
|
||||
@classmethod
|
||||
def get(cls, oid):
|
||||
@ -175,7 +175,8 @@ class SemBulletinsPDFCache(ScoDocCache):
|
||||
"""Clear cached pdf for all given formsemestres"""
|
||||
for version in scu.BULLETINS_VERSIONS:
|
||||
oids = [
|
||||
formsemestre_id + "_" + version for formsemestre_id in formsemestre_ids
|
||||
str(formsemestre_id) + "_" + version
|
||||
for formsemestre_id in formsemestre_ids
|
||||
]
|
||||
cls.delete_many(oids)
|
||||
|
||||
|
@ -71,7 +71,7 @@ _formsemestreEditor = ndb.EditableTable(
|
||||
"date_fin": ndb.DateISOtoDMY,
|
||||
"gestion_compensation": str,
|
||||
"gestion_semestrielle": str,
|
||||
"etat": str,
|
||||
"etat": bool,
|
||||
"bul_hide_xml": str,
|
||||
},
|
||||
input_formators={
|
||||
@ -79,7 +79,7 @@ _formsemestreEditor = ndb.EditableTable(
|
||||
"date_fin": ndb.DateDMYtoISO,
|
||||
"gestion_compensation": int,
|
||||
"gestion_semestrielle": int,
|
||||
"etat": int,
|
||||
"etat": bool,
|
||||
"bul_hide_xml": int,
|
||||
},
|
||||
)
|
||||
|
@ -1421,12 +1421,31 @@ def do_formsemestre_delete(context, formsemestre_id):
|
||||
req = "DELETE FROM sco_prefs WHERE formsemestre_id=%(formsemestre_id)s"
|
||||
cursor.execute(req, {"formsemestre_id": formsemestre_id})
|
||||
# --- 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})
|
||||
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})
|
||||
req = "DELETE FROM partition WHERE formsemestre_id=%(formsemestre_id)s"
|
||||
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
|
||||
sco_formsemestre._formsemestreEditor.delete(cnx, formsemestre_id)
|
||||
|
||||
|
@ -185,7 +185,7 @@ def get_partition_groups(context, partition):
|
||||
"""SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.*
|
||||
FROM group_descr gd, partition p
|
||||
WHERE gd.partition_id=%(partition_id)s
|
||||
AND gd.partition_id=p.partition_id
|
||||
AND gd.partition_id=p.id
|
||||
ORDER BY group_name
|
||||
""",
|
||||
partition,
|
||||
@ -200,7 +200,7 @@ def get_default_group(formsemestre_id, fix_if_missing=False):
|
||||
FROM group_descr gd, partition p
|
||||
WHERE p.formsemestre_id=%(formsemestre_id)s
|
||||
AND p.partition_name is NULL
|
||||
AND p.partition_id = gd.partition_id
|
||||
AND p.id = gd.partition_id
|
||||
""",
|
||||
{"formsemestre_id": formsemestre_id},
|
||||
)
|
||||
@ -233,7 +233,7 @@ def get_sem_groups(context, formsemestre_id):
|
||||
"""SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.*
|
||||
FROM group_descr gd, partition p
|
||||
WHERE p.formsemestre_id=%(formsemestre_id)s
|
||||
AND p.partition_id = gd.partition_id
|
||||
AND p.id = gd.partition_id
|
||||
""",
|
||||
{"formsemestre_id": formsemestre_id},
|
||||
)
|
||||
|
@ -1094,13 +1094,13 @@ def list_formsemestre_utilisateurs_uecap(context, formsemestre_id):
|
||||
)[0]
|
||||
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
||||
cursor.execute(
|
||||
"""select sem.formsemestre_id
|
||||
from notes_formsemestre sem, notes_formations F
|
||||
where sem.formation_id = F.formation_id
|
||||
"""SELECT sem.id
|
||||
FROM notes_formsemestre sem, notes_formations F
|
||||
WHERE sem.formation_id = F.id
|
||||
and F.formation_code = %(formation_code)s
|
||||
and sem.semestre_id = %(semestre_id)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"],
|
||||
|
@ -176,7 +176,7 @@ def can_change_groups(formsemestre_id):
|
||||
|
||||
context = None # XXX #context
|
||||
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
|
||||
if sem["etat"] != "1":
|
||||
if not sem["etat"]:
|
||||
return False # semestre verrouillé
|
||||
if current_user.has_permission(Permission.ScoEtudChangeGroups):
|
||||
return True # admin, chef dept
|
||||
|
@ -42,6 +42,7 @@ def test_client():
|
||||
admin_role = Role.query.filter_by(name="Admin").first()
|
||||
u.add_role(admin_role, "TEST00")
|
||||
db.session.add(u)
|
||||
db.session.commit()
|
||||
ndb.set_sco_dept("TEST") # set db connection
|
||||
yield client
|
||||
# ndb.close_dept_connection()
|
||||
|
@ -9,14 +9,15 @@ facilement des tests ou de reproduire des bugs.
|
||||
"""
|
||||
|
||||
from functools import wraps
|
||||
import random
|
||||
import sys
|
||||
import string
|
||||
import collections
|
||||
import pprint
|
||||
import random
|
||||
import typing
|
||||
|
||||
|
||||
import scodoc_manager
|
||||
from config import Config
|
||||
from app.auth.models import User
|
||||
from app.scodoc import notesdb as ndb
|
||||
from app.scodoc import sco_codes_parcours
|
||||
from app.scodoc import sco_edit_formation
|
||||
@ -70,6 +71,9 @@ class ScoFake(object):
|
||||
|
||||
def __init__(self, verbose=True):
|
||||
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):
|
||||
if self.verbose:
|
||||
@ -231,8 +235,10 @@ class ScoFake(object):
|
||||
elt_sem_apo=None,
|
||||
elt_annee_apo=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())
|
||||
oids = sco_formsemestre.do_formsemestre_list(
|
||||
context, args={"formsemestre_id": oid}
|
||||
@ -244,10 +250,12 @@ class ScoFake(object):
|
||||
@logging_meth
|
||||
def create_moduleimpl(
|
||||
self,
|
||||
module_id=None,
|
||||
formsemestre_id=None,
|
||||
responsable_id=None,
|
||||
module_id: int = None,
|
||||
formsemestre_id: int = 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())
|
||||
oids = sco_moduleimpl.do_moduleimpl_list(
|
||||
context, moduleimpl_id=oid
|
||||
@ -299,7 +307,7 @@ class ScoFake(object):
|
||||
etud=None,
|
||||
note=None,
|
||||
comment=None,
|
||||
uid="bach",
|
||||
uid: typing.Optional[int] = None,
|
||||
):
|
||||
return sco_saisie_notes._notes_add(
|
||||
context,
|
||||
|
@ -138,19 +138,16 @@ def test_formations(test_client):
|
||||
mi = G.create_moduleimpl(
|
||||
module_id=mod["module_id"],
|
||||
formsemestre_id=sem1["formsemestre_id"],
|
||||
responsable_id="bach",
|
||||
)
|
||||
|
||||
mi2 = G.create_moduleimpl(
|
||||
module_id=mod2["module_id"],
|
||||
formsemestre_id=sem1["formsemestre_id"],
|
||||
responsable_id="bach",
|
||||
)
|
||||
|
||||
mit = G.create_moduleimpl(
|
||||
module_id=modt["module_id"],
|
||||
formsemestre_id=sem2["formsemestre_id"],
|
||||
responsable_id="bach",
|
||||
)
|
||||
|
||||
semt = G.create_formsemestre(
|
||||
@ -163,7 +160,6 @@ def test_formations(test_client):
|
||||
mi3 = G.create_moduleimpl(
|
||||
module_id=mod3["module_id"],
|
||||
formsemestre_id=semt["formsemestre_id"],
|
||||
responsable_id="bach",
|
||||
)
|
||||
|
||||
# --- Afficher la liste des formations
|
||||
@ -379,7 +375,6 @@ def test_import_formation(test_client):
|
||||
mi = G.create_moduleimpl(
|
||||
module_id=mod["module_id"],
|
||||
formsemestre_id=sems[mod["semestre_id"] - 1]["formsemestre_id"],
|
||||
responsable_id="bach",
|
||||
)
|
||||
assert mi["ens"] == []
|
||||
assert mi["module_id"] == mod["module_id"]
|
||||
|
Loading…
Reference in New Issue
Block a user