diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index e51806b9..579aff12 100644 --- a/app/scodoc/sco_cache.py +++ b/app/scodoc/sco_cache.py @@ -104,7 +104,11 @@ class ScoDocCache: class EvaluationCache(ScoDocCache): - "Cache for evaluations" + """Cache for evaluations. + Clé: evaluation_id + Valeur: { 'etudid' : note } + """ + prefix = "EVAL" @classmethod diff --git a/app/scodoc/sco_evaluations.py b/app/scodoc/sco_evaluations.py index 4a30f8f1..eba208b8 100644 --- a/app/scodoc/sco_evaluations.py +++ b/app/scodoc/sco_evaluations.py @@ -568,7 +568,7 @@ def do_evaluation_etat( } -def do_evaluation_list_in_sem(context, formsemestre_id): +def do_evaluation_list_in_sem(context, formsemestre_id, with_etat=True): """Liste les evaluations de tous les modules de ce semestre. Donne pour chaque eval son état (voir do_evaluation_etat) { evaluation_id,nb_inscrits, nb_notes, nb_abs, nb_neutre, moy, median, last_modif ... } @@ -624,7 +624,8 @@ def do_evaluation_list_in_sem(context, formsemestre_id): # etat de chaque evaluation: for r in res: r["jour"] = r["jour"] or datetime.date(1900, 1, 1) # pour les comparaisons - r["etat"] = do_evaluation_etat(context, r["evaluation_id"]) + if with_etat: + r["etat"] = do_evaluation_etat(context, r["evaluation_id"]) return res diff --git a/tests/unit/test_caches.py b/tests/unit/test_caches.py index 2b06f148..43db1f1e 100644 --- a/tests/unit/test_caches.py +++ b/tests/unit/test_caches.py @@ -13,6 +13,7 @@ from flask import current_app from app import db from app.scodoc import sco_cache +from app.scodoc import sco_evaluations from app.scodoc import sco_formsemestre DEPT = "RT" # ce département (BD) doit exister @@ -29,3 +30,27 @@ def test_notes_table(test_client): assert sco_cache.NotesTableCache.get(formsemestre_id, compute=False) sco_cache.invalidate_formsemestre(formsemestre_id) assert not sco_cache.NotesTableCache.get(formsemestre_id, compute=False) + + +def test_cache_evaluations(test_client): + """""" + # cherche un semestre ayant des evaluations + sems = sco_formsemestre.do_formsemestre_list(None) + assert len(sems) + sem_evals = [] + for sem in sems: + sem_evals = sco_evaluations.do_evaluation_list_in_sem( + None, sem["formsemestre_id"], with_etat=False + ) + if sem_evals: + break + if not sem_evals: + raise Exception("no evaluations") + # + evaluation_id = sem_evals[0]["evaluation_id"] + sco_evaluations.do_evaluation_get_all_notes(None, evaluation_id) + # should have been be cached: + assert sco_cache.EvaluationCache.get(evaluation_id) + sco_cache.invalidate_formsemestre(sem["formsemestre_id"]) + # should have been erased from cache: + assert not sco_cache.EvaluationCache.get(evaluation_id)