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
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2021-07-31 18:01:10 +02:00
|
|
|
from flask import current_app, g
|
2021-07-20 17:27:54 +02:00
|
|
|
|
|
|
|
from app import db
|
|
|
|
from app.scodoc import sco_cache
|
2021-07-21 14:58:49 +02:00
|
|
|
from app.scodoc import sco_evaluations
|
2021-07-20 17:27:54 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
2021-07-31 18:01:10 +02:00
|
|
|
from app.scodoc import notesdb as ndb
|
2021-07-20 17:27:54 +02:00
|
|
|
|
|
|
|
DEPT = "RT" # ce département (BD) doit exister
|
2021-07-30 09:36:30 +02:00
|
|
|
context = None # #context
|
2021-07-20 17:27:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_notes_table(test_client):
|
2021-07-31 23:05:53 +02:00
|
|
|
"""Test construction et cache de NotesTable.
|
|
|
|
Attention: utilise une base (departement) existante.
|
|
|
|
"""
|
2021-07-31 18:01:10 +02:00
|
|
|
ndb.set_sco_dept(DEPT)
|
|
|
|
assert g.scodoc_dept == DEPT
|
2021-07-30 09:36:30 +02:00
|
|
|
sems = sco_formsemestre.do_formsemestre_list(context)
|
2021-07-20 17:27:54 +02:00
|
|
|
assert len(sems)
|
|
|
|
sem = sems[0]
|
|
|
|
formsemestre_id = sem["formsemestre_id"]
|
|
|
|
nt = sco_cache.NotesTableCache.get(formsemestre_id)
|
|
|
|
assert nt
|
|
|
|
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)
|
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"]
|
|
|
|
nt = sco_cache.NotesTableCache.get(formsemestre_id)
|
|
|
|
assert sco_cache.NotesTableCache.get(formsemestre_id, compute=False)
|
2021-07-21 14:58:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cache_evaluations(test_client):
|
|
|
|
""""""
|
|
|
|
# cherche un semestre ayant des evaluations
|
2021-07-31 18:01:10 +02:00
|
|
|
ndb.set_sco_dept(DEPT)
|
2021-07-21 14:58:49 +02:00
|
|
|
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(
|
2021-07-29 10:19:00 +02:00
|
|
|
sem["formsemestre_id"], with_etat=False
|
2021-07-21 14:58:49 +02:00
|
|
|
)
|
|
|
|
if sem_evals:
|
|
|
|
break
|
|
|
|
if not sem_evals:
|
|
|
|
raise Exception("no evaluations")
|
|
|
|
#
|
|
|
|
evaluation_id = sem_evals[0]["evaluation_id"]
|
2021-07-29 16:31:15 +02:00
|
|
|
eval_notes = sco_evaluations.do_evaluation_get_all_notes(evaluation_id)
|
|
|
|
# should have been be cached, except if empty
|
|
|
|
if eval_notes:
|
|
|
|
assert sco_cache.EvaluationCache.get(evaluation_id)
|
2021-07-21 14:58:49 +02:00
|
|
|
sco_cache.invalidate_formsemestre(sem["formsemestre_id"])
|
|
|
|
# should have been erased from cache:
|
|
|
|
assert not sco_cache.EvaluationCache.get(evaluation_id)
|