Tests unitaires yaml: reset sequences to get same ids
This commit is contained in:
parent
c6e35dd4cd
commit
f1fd4d98d7
@ -465,6 +465,26 @@ def truncate_database():
|
||||
except:
|
||||
db.session.rollback()
|
||||
raise
|
||||
# Remet les compteurs (séquences sql) à zéro
|
||||
db.session.execute(
|
||||
"""
|
||||
CREATE OR REPLACE FUNCTION reset_sequences(username IN VARCHAR) RETURNS void AS $$
|
||||
DECLARE
|
||||
statements CURSOR FOR
|
||||
SELECT sequence_name
|
||||
FROM information_schema.sequences
|
||||
ORDER BY sequence_name ;
|
||||
BEGIN
|
||||
FOR stmt IN statements LOOP
|
||||
EXECUTE 'ALTER SEQUENCE ' || quote_ident(stmt.sequence_name) || ' RESTART;';
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
SELECT reset_sequences('scodoc');
|
||||
"""
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def clear_scodoc_cache():
|
||||
|
@ -166,33 +166,18 @@ def _un_semestre(
|
||||
a_user = User.query.first()
|
||||
formsemestre.responsables = [a_user]
|
||||
db.session.add(formsemestre)
|
||||
# Ajoute pour chaque UE une ressource avec un coef vers cette UE
|
||||
added_ressources = set()
|
||||
for parcour in parcours + [None]:
|
||||
for ue in formation.query_ues_parcour(parcour):
|
||||
ressource = (
|
||||
Module.query.filter_by(
|
||||
formation=formation,
|
||||
semestre_id=1,
|
||||
module_type=scu.ModuleType.RESSOURCE,
|
||||
)
|
||||
.join(ModuleUECoef)
|
||||
.filter_by(ue=ue)
|
||||
.first()
|
||||
)
|
||||
if ressource is not None:
|
||||
if ressource.id not in added_ressources:
|
||||
modimpl = ModuleImpl(module=ressource, responsable_id=a_user.id)
|
||||
db.session.add(modimpl)
|
||||
formsemestre.modimpls.append(modimpl)
|
||||
added_ressources.add(ressource.id)
|
||||
# Ajoute tous les modules du semestre sans parcours OU avec l'un des parcours indiqués
|
||||
sem_parcours_ids = {p.id for p in parcours}
|
||||
modules = [
|
||||
m
|
||||
for m in formsemestre.formation.modules.filter_by(semestre_id=semestre_id)
|
||||
if (not m.parcours) or ({p.id for p in m.parcours} & sem_parcours_ids)
|
||||
]
|
||||
for module in modules:
|
||||
modimpl = ModuleImpl(module=module, responsable_id=a_user.id)
|
||||
db.session.add(modimpl)
|
||||
formsemestre.modimpls.append(modimpl)
|
||||
|
||||
# Ajoute la première SAE
|
||||
sae = formation.modules.filter_by(
|
||||
semestre_id=1, module_type=scu.ModuleType.SAE
|
||||
).first()
|
||||
modimpl = ModuleImpl(module=sae, responsable_id=a_user.id)
|
||||
formsemestre.modimpls.append(modimpl)
|
||||
# Crée une évaluation dans chaque module
|
||||
create_evaluations(formsemestre)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user