From 5d521b9cfa50fb39dd8533e5371e1436eb3d36d1 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 21 Jul 2021 15:58:49 +0300 Subject: [PATCH] added a unit test: evaluation cache --- app/scodoc/sco_cache.py | 6 +++++- app/scodoc/sco_evaluations.py | 5 +++-- tests/unit/test_caches.py | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/scodoc/sco_cache.py b/app/scodoc/sco_cache.py index e51806b98c..579aff1297 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 4a30f8f18e..eba208b8ae 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 2b06f14862..43db1f1e55 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)