2021-07-20 17:27:54 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
|
|
|
|
"""Unit tests for caches
|
|
|
|
|
|
|
|
|
|
|
|
Ce test suppose une base département existante.
|
|
|
|
|
|
|
|
Usage: pytest tests/unit/test_caches.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2022-11-29 00:07:34 +01:00
|
|
|
from flask import g
|
2021-07-20 17:27:54 +02:00
|
|
|
|
2021-08-13 00:34:58 +02:00
|
|
|
import app
|
2021-07-20 17:27:54 +02:00
|
|
|
from app import db
|
2022-02-13 23:53:11 +01:00
|
|
|
from app.comp import res_sem
|
2022-03-27 22:25:00 +02:00
|
|
|
from app.comp.res_compat import NotesTableCompat
|
2023-08-25 17:58:57 +02:00
|
|
|
from app.models import Evaluation, FormSemestre, ModuleImpl
|
2021-07-20 17:27:54 +02:00
|
|
|
from app.scodoc import sco_cache
|
2021-07-21 14:58:49 +02:00
|
|
|
from app.scodoc import sco_evaluations
|
2021-11-12 22:17:46 +01:00
|
|
|
from app.scodoc import sco_evaluation_db
|
2021-07-20 17:27:54 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
2021-08-10 12:57:38 +02:00
|
|
|
from config import TestConfig
|
2021-08-10 13:20:35 +02:00
|
|
|
from tests.unit.test_sco_basic import run_sco_basic
|
2021-08-10 12:57:38 +02:00
|
|
|
|
|
|
|
DEPT = TestConfig.DEPT_TEST
|
2021-07-20 17:27:54 +02:00
|
|
|
|
|
|
|
|
2022-02-13 23:53:11 +01:00
|
|
|
def test_notes_table(test_client): # XXX A REVOIR POUR TESTER RES TODO
|
2021-08-10 12:57:38 +02:00
|
|
|
"""Test construction et cache de NotesTable."""
|
2021-08-13 00:34:58 +02:00
|
|
|
app.set_sco_dept(DEPT)
|
2021-07-31 18:01:10 +02:00
|
|
|
assert g.scodoc_dept == DEPT
|
2021-08-10 12:57:38 +02:00
|
|
|
# prépare le département avec quelques semestres:
|
2021-08-10 13:20:35 +02:00
|
|
|
run_sco_basic()
|
2021-08-10 12:57:38 +02:00
|
|
|
#
|
2021-08-19 10:28:35 +02:00
|
|
|
sems = sco_formsemestre.do_formsemestre_list()
|
2021-07-20 17:27:54 +02:00
|
|
|
assert len(sems)
|
|
|
|
sem = sems[0]
|
|
|
|
formsemestre_id = sem["formsemestre_id"]
|
2024-10-29 19:18:36 +01:00
|
|
|
formsemestre: FormSemestre = FormSemestre.get_or_404(formsemestre_id)
|
2022-02-13 23:53:11 +01:00
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
2021-07-20 17:27:54 +02:00
|
|
|
assert nt
|
2022-11-12 17:28:05 +01:00
|
|
|
assert sco_cache.ResultatsSemestreCache.get(formsemestre_id)
|
2021-07-20 17:27:54 +02:00
|
|
|
sco_cache.invalidate_formsemestre(formsemestre_id)
|
2022-11-12 17:28:05 +01:00
|
|
|
assert not sco_cache.ResultatsSemestreCache.get(formsemestre_id)
|
2021-07-25 11:18:39 +02:00
|
|
|
# cache les 10 premiers
|
|
|
|
for sem in sems[:10]:
|
2021-07-25 09:51:09 +02:00
|
|
|
formsemestre_id = sem["formsemestre_id"]
|
2022-11-12 17:28:05 +01:00
|
|
|
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
assert sco_cache.ResultatsSemestreCache.get(formsemestre_id)
|
2024-01-15 17:49:28 +01:00
|
|
|
# Efface les semestres
|
|
|
|
sco_cache.ResultatsSemestreCache.delete_pattern("*")
|
|
|
|
for sem in sems[:10]:
|
|
|
|
assert sco_cache.ResultatsSemestreCache.get(formsemestre_id) is None
|
2021-07-21 14:58:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_evaluations(test_client):
|
|
|
|
""""""
|
|
|
|
# cherche un semestre ayant des evaluations
|
2021-08-13 00:34:58 +02:00
|
|
|
app.set_sco_dept(DEPT)
|
2021-08-10 13:20:35 +02:00
|
|
|
# prépare le département avec quelques semestres:
|
|
|
|
run_sco_basic()
|
|
|
|
#
|
2023-08-25 17:58:57 +02:00
|
|
|
formsemestres = FormSemestre.query
|
|
|
|
assert formsemestres.count()
|
|
|
|
evaluation = None
|
|
|
|
for formsemestre in formsemestres:
|
|
|
|
evaluation: Evaluation = (
|
|
|
|
Evaluation.query.join(ModuleImpl)
|
|
|
|
.filter_by(formsemestre_id=formsemestre.id)
|
|
|
|
.first()
|
2021-07-21 14:58:49 +02:00
|
|
|
)
|
2023-08-25 17:58:57 +02:00
|
|
|
if evaluation is not None:
|
2021-07-21 14:58:49 +02:00
|
|
|
break
|
2023-08-25 17:58:57 +02:00
|
|
|
if evaluation is None:
|
2021-07-21 14:58:49 +02:00
|
|
|
raise Exception("no evaluations")
|
|
|
|
#
|
2023-08-25 17:58:57 +02:00
|
|
|
eval_notes = sco_evaluation_db.do_evaluation_get_all_notes(evaluation.id)
|
2021-07-29 16:31:15 +02:00
|
|
|
# should have been be cached, except if empty
|
|
|
|
if eval_notes:
|
2023-08-25 17:58:57 +02:00
|
|
|
assert sco_cache.EvaluationCache.get(evaluation.id)
|
|
|
|
sco_cache.invalidate_formsemestre(evaluation.moduleimpl.formsemestre.id)
|
2021-07-21 14:58:49 +02:00
|
|
|
# should have been erased from cache:
|
2023-08-25 17:58:57 +02:00
|
|
|
assert not sco_cache.EvaluationCache.get(evaluation.id)
|