forked from ScoDoc/ScoDoc
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:
|
except:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
raise
|
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():
|
def clear_scodoc_cache():
|
||||||
|
@ -166,33 +166,18 @@ def _un_semestre(
|
|||||||
a_user = User.query.first()
|
a_user = User.query.first()
|
||||||
formsemestre.responsables = [a_user]
|
formsemestre.responsables = [a_user]
|
||||||
db.session.add(formsemestre)
|
db.session.add(formsemestre)
|
||||||
# Ajoute pour chaque UE une ressource avec un coef vers cette UE
|
# Ajoute tous les modules du semestre sans parcours OU avec l'un des parcours indiqués
|
||||||
added_ressources = set()
|
sem_parcours_ids = {p.id for p in parcours}
|
||||||
for parcour in parcours + [None]:
|
modules = [
|
||||||
for ue in formation.query_ues_parcour(parcour):
|
m
|
||||||
ressource = (
|
for m in formsemestre.formation.modules.filter_by(semestre_id=semestre_id)
|
||||||
Module.query.filter_by(
|
if (not m.parcours) or ({p.id for p in m.parcours} & sem_parcours_ids)
|
||||||
formation=formation,
|
]
|
||||||
semestre_id=1,
|
for module in modules:
|
||||||
module_type=scu.ModuleType.RESSOURCE,
|
modimpl = ModuleImpl(module=module, responsable_id=a_user.id)
|
||||||
)
|
|
||||||
.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)
|
db.session.add(modimpl)
|
||||||
formsemestre.modimpls.append(modimpl)
|
formsemestre.modimpls.append(modimpl)
|
||||||
added_ressources.add(ressource.id)
|
|
||||||
|
|
||||||
# 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
|
# Crée une évaluation dans chaque module
|
||||||
create_evaluations(formsemestre)
|
create_evaluations(formsemestre)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user