Vide base departement avant tests
This commit is contained in:
parent
540623d3b9
commit
6a42846d2e
@ -668,3 +668,16 @@ CREATE TABLE notes_appreciations (
|
||||
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION truncate_tables(username IN VARCHAR) RETURNS void AS $$
|
||||
DECLARE
|
||||
statements CURSOR FOR
|
||||
SELECT tablename FROM pg_tables
|
||||
WHERE tableowner = username AND schemaname = 'public'
|
||||
AND tablename <> 'notes_semestres'
|
||||
AND tablename <> 'notes_form_modalites';
|
||||
BEGIN
|
||||
FOR stmt IN statements LOOP
|
||||
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
@ -1,286 +0,0 @@
|
||||
""" creation de 10 étudiants, formation, semestre, ue, module, absences le matin, l'apres midi, la journée compléte
|
||||
et justification d'absences, supression d'absences, création d'une liste etat absences, creation d'un groupe afin
|
||||
de tester la fonction EtatAbsencesGroupes
|
||||
|
||||
Fonctions de l'API utilisé :
|
||||
- doSignaleAbsence
|
||||
- doAnnuleAbsence
|
||||
- doJustifAbsence
|
||||
- get_partition_groups
|
||||
- get_partitions_list
|
||||
- sco_abs.get_abs_count(etudid, sem)
|
||||
- ListeAbsEtud
|
||||
- partition_create
|
||||
- createGroup
|
||||
- set_group
|
||||
- EtatAbsenceGr
|
||||
- AddBilletAbsence
|
||||
- listeBilletsEtud
|
||||
|
||||
"""
|
||||
|
||||
|
||||
import random
|
||||
|
||||
# La variable context est définie par le script de lancement
|
||||
# l'affecte ainsi pour évietr les warnins pylint:
|
||||
context = context # pylint: disable=undefined-variable
|
||||
REQUEST = REQUEST # pylint: disable=undefined-variable
|
||||
import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error
|
||||
import sco_abs
|
||||
import sco_abs_views
|
||||
import sco_abs_notification
|
||||
import ZAbsences
|
||||
|
||||
G = sco_fake_gen.ScoFake(context.Notes)
|
||||
G.verbose = False
|
||||
|
||||
# --- Création d'étudiants
|
||||
etuds = [G.create_etud(code_nip=None) for _ in range(10)]
|
||||
|
||||
# --- Création d'une formation
|
||||
f = G.create_formation(acronyme="")
|
||||
ue = G.create_ue(formation_id=f["formation_id"], acronyme="TST1", titre="ue test")
|
||||
mat = G.create_matiere(ue_id=ue["ue_id"], titre="matière test")
|
||||
mod = G.create_module(
|
||||
matiere_id=mat["matiere_id"],
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue["ue_id"], # faiblesse de l'API
|
||||
formation_id=f["formation_id"], # faiblesse de l'API
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
sem = G.create_formsemestre(
|
||||
formation_id=f["formation_id"],
|
||||
semestre_id=1,
|
||||
date_debut="01/01/2021",
|
||||
date_fin="30/06/2021",
|
||||
)
|
||||
|
||||
mi = G.create_moduleimpl(
|
||||
module_id=mod["module_id"],
|
||||
formsemestre_id=sem["formsemestre_id"],
|
||||
responsable_id="bach",
|
||||
)
|
||||
|
||||
# --- Inscription des étudiants
|
||||
for etud in etuds:
|
||||
G.inscrit_etudiant(sem, etud)
|
||||
|
||||
# --- Création d'une évaluation
|
||||
e = G.create_evaluation(
|
||||
moduleimpl_id=mi["moduleimpl_id"],
|
||||
jour="22/01/2021",
|
||||
description="evaluation test",
|
||||
coefficient=1.0,
|
||||
)
|
||||
|
||||
|
||||
# --- Saisie absences
|
||||
etudid = etuds[0]["etudid"]
|
||||
|
||||
_ = sco_abs_views.doSignaleAbsence(
|
||||
context.Absences,
|
||||
"15/01/2021",
|
||||
"15/01/2021",
|
||||
demijournee=1,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
_ = sco_abs_views.doSignaleAbsence(
|
||||
context.Absences,
|
||||
"18/01/2021",
|
||||
"18/01/2021",
|
||||
demijournee=0,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
_ = sco_abs_views.doSignaleAbsence(
|
||||
context.Absences,
|
||||
"19/01/2021",
|
||||
"19/01/2021",
|
||||
demijournee=2,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
_ = sco_abs_views.doSignaleAbsence(
|
||||
context.Absences,
|
||||
"22/01/2021",
|
||||
"22/01/2021",
|
||||
demijournee=1,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
# --- Justification de certaines absences
|
||||
|
||||
_ = sco_abs_views.doJustifAbsence(
|
||||
context.Absences,
|
||||
"15/01/2021",
|
||||
"15/01/2021",
|
||||
demijournee=1,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
_ = sco_abs_views.doJustifAbsence(
|
||||
context.Absences,
|
||||
"18/01/2021",
|
||||
"18/01/2021",
|
||||
demijournee=0,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
_ = sco_abs_views.doJustifAbsence(
|
||||
context.Absences,
|
||||
"19/01/2021",
|
||||
"19/01/2021",
|
||||
demijournee=2,
|
||||
etudid=etudid,
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
# --- Test
|
||||
|
||||
b = sco_abs.is_work_saturday(context.Absences)
|
||||
assert b == 0 # samedi ne sont pas compris
|
||||
nbabs, nbabsjust = sco_abs.get_abs_count(etudid, sem)
|
||||
assert (
|
||||
nbabs == 5
|
||||
) # l'étudiant a été absent le 15 (apres midi) , (16 et 17 we), 18 (matin) et 19 janvier (matin et apres midi), et 22 (matin)
|
||||
assert nbabsjust == 4 # l'étudiant justifie ses abs du 15, 18 et 19
|
||||
|
||||
|
||||
# + vérification à l'aide de ScoDoc WEB : ok!
|
||||
|
||||
# --- Supression d'une absence et d'une justification
|
||||
|
||||
_ = sco_abs_views.doAnnuleAbsence(
|
||||
context.Absences, "19/01/2021", "19/01/2021", 2, etudid=etudid, REQUEST=REQUEST
|
||||
)
|
||||
nbabs, nbabsjust = sco_abs.get_abs_count(etudid, sem)
|
||||
print(nbabs) # lors du print cela affiche 5 or cela devrait afficher 3
|
||||
|
||||
# assert nbabs == 3
|
||||
# + vérification à l'aide de ScoDoc WEB : il y a bien plus que 3 abs, 2 justifiés et 1 non justifié.
|
||||
|
||||
|
||||
# --- supression d'une justification pas encore disponible à l'aide de python.
|
||||
|
||||
|
||||
# --- Création d'une liste d'abs
|
||||
|
||||
liste_abs = sco_abs_views.ListeAbsEtud(
|
||||
context.Absences, etudid, format="json", absjust_only=1, REQUEST=REQUEST
|
||||
)
|
||||
liste_abs2 = sco_abs_views.ListeAbsEtud(
|
||||
context.Absences, etudid, format="json", REQUEST=REQUEST
|
||||
)
|
||||
|
||||
load_liste_abs = json.loads(liste_abs)
|
||||
load_liste_abs2 = json.loads(liste_abs2)
|
||||
|
||||
assert len(load_liste_abs2) == 1
|
||||
assert len(load_liste_abs) == 2
|
||||
assert load_liste_abs2[0]["ampm"] == "1"
|
||||
assert load_liste_abs2[0]["datedmy"] == "22/01/2021"
|
||||
assert load_liste_abs2[0]["exams"] == mod["code"]
|
||||
# absjust_only -> seulement les abs justifiés
|
||||
|
||||
|
||||
# --- Création d'un groupe
|
||||
|
||||
_ = sco_groups.partition_create(
|
||||
context.Scolarite,
|
||||
formsemestre_id=sem["formsemestre_id"],
|
||||
partition_name="Eleve",
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
li1 = sco_groups.get_partitions_list(context.Scolarite, sem["formsemestre_id"])
|
||||
_ = sco_groups.createGroup(context.Scolarite, li1[0]["partition_id"], "Groupe 1")
|
||||
|
||||
# --- Affectation des élèves dans des groupes
|
||||
|
||||
li_grp1 = sco_groups.get_partition_groups(context.Scolarite, li1[0])
|
||||
for etud in etuds:
|
||||
sco_groups.set_group(context.Scolarite, etud["etudid"], li_grp1[0]["group_id"])
|
||||
|
||||
# --- Test de EtatAbsencesGroupes
|
||||
|
||||
grp1_abs = context.Absences.EtatAbsencesGr(
|
||||
group_ids=[li_grp1[0]["group_id"]],
|
||||
debut="01/01/2021",
|
||||
fin="30/06/2021",
|
||||
format="json",
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
load_grp1_abs = json.loads(grp1_abs)
|
||||
|
||||
assert len(load_grp1_abs) == 10
|
||||
|
||||
tab_id = [] # tab des id present dans load_grp1_abs
|
||||
for un_etud in load_grp1_abs:
|
||||
tab_id.append(un_etud["etudid"])
|
||||
|
||||
for (
|
||||
etud
|
||||
) in (
|
||||
etuds
|
||||
): # verification si tous les etudiants sont present dans la liste du groupe d'absence
|
||||
assert etud["etudid"] in tab_id
|
||||
|
||||
|
||||
for un_etud in load_grp1_abs:
|
||||
if un_etud["etudid"] == etudid:
|
||||
assert un_etud["nbabs"] == "3"
|
||||
assert un_etud["nbjustifs_noabs"] == "2"
|
||||
assert un_etud["nbabsjust"] == "2"
|
||||
assert un_etud["nbabsnonjust"] == "1"
|
||||
assert un_etud["nomprenom"] == etuds[0]["nomprenom"]
|
||||
|
||||
# --- Création de billets
|
||||
|
||||
b1 = context.Absences.AddBilletAbsence(
|
||||
begin="2021-01-22 00:00",
|
||||
end="2021-01-22 23:59",
|
||||
etudid=etudid,
|
||||
description="abs du 22",
|
||||
justified=False,
|
||||
code_nip=etuds[0]["code_nip"],
|
||||
code_ine=etuds[0]["code_ine"],
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
b2 = context.Absences.AddBilletAbsence(
|
||||
begin="2021-01-15 00:00",
|
||||
end="2021-01-15 23:59",
|
||||
etudid=etudid,
|
||||
description="abs du 15",
|
||||
code_nip=etuds[0]["code_nip"],
|
||||
code_ine=etuds[0]["code_ine"],
|
||||
REQUEST=REQUEST,
|
||||
)
|
||||
|
||||
|
||||
li_bi = context.Absences.listeBilletsEtud(etudid=etudid, REQUEST=REQUEST, format="json")
|
||||
load_li_bi = json.loads(li_bi)
|
||||
|
||||
assert len(load_li_bi) == 2
|
||||
assert load_li_bi[1]["description"] == "abs du 22"
|
||||
|
||||
"""
|
||||
Commentaire :
|
||||
|
||||
Parametre demijournee ne prend pas en compte les strings ---> pb régler.
|
||||
|
||||
La suppression de justification ne peut pas se faire directement en interractif à l'aide de python.
|
||||
|
||||
La fonction CountAbs ne met pas à jour le nombre après supression des absences. ---> (cf : test_CountAbs.py)
|
||||
|
||||
"""
|
@ -1,47 +0,0 @@
|
||||
context = context # pylint: disable=undefined-variable
|
||||
REQUEST = REQUEST # pylint: disable=undefined-variable
|
||||
import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error
|
||||
|
||||
|
||||
G = sco_fake_gen.ScoFake(context.Notes)
|
||||
G.verbose = False
|
||||
|
||||
# --- Création d'un étudiant
|
||||
|
||||
etud = G.create_etud(
|
||||
code_nip="",
|
||||
nom="Poire",
|
||||
prenom="Kevin",
|
||||
code_ine="",
|
||||
civilite="M",
|
||||
etape="TST1",
|
||||
email="test1@localhost",
|
||||
emailperso="perso1@localhost",
|
||||
date_naissance="01/05/2001",
|
||||
lieu_naissance="Stains",
|
||||
dept_naissance="93",
|
||||
domicile="11, rue du test",
|
||||
codepostaldomicile="93430",
|
||||
villedomicile="Villetaneuse",
|
||||
paysdomicile="France",
|
||||
telephone="0102030405",
|
||||
typeadresse="domicile",
|
||||
boursier=None,
|
||||
description="etudiant test",
|
||||
)
|
||||
|
||||
print(etud)
|
||||
print(" ")
|
||||
|
||||
info = context.Scolarite.etud_info(etud["etudid"], format = "json", REQUEST=REQUEST)
|
||||
load_info = json.loads(info)
|
||||
print(load_info)
|
||||
|
||||
#malgrè l'entrée de donnée dans les paramètres la fonction ne les prend pas en compte. Sauf pour date_naissance,
|
||||
#dept_naissance, nom et prenom, lieu_naissance et civilite la fonction crée aussi un code nip et ine donc pas de pb
|
||||
#pour ca.
|
||||
|
||||
print(" ")
|
||||
print(etud["telephone"])
|
||||
print(etud["domicile"])
|
||||
print(etud["emailperso"])
|
@ -10,6 +10,12 @@ from app.scodoc import sco_bulletins_standard
|
||||
from app.scodoc import notesdb as ndb
|
||||
|
||||
|
||||
def truncate_database():
|
||||
"Erase content of all tables from current dept database"
|
||||
# use a stored SQL function, see createtables.sql
|
||||
ndb.SimpleQuery("SELECT truncate_tables('scodoc');", {})
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def test_client():
|
||||
# Setup
|
||||
@ -29,9 +35,8 @@ def test_client():
|
||||
# u.set_password("admin")
|
||||
login_user(u)
|
||||
# db.session.add(u)
|
||||
|
||||
g.scodoc_dept = "TEST00"
|
||||
g.db_conn = ndb.open_dept_connection()
|
||||
ndb.set_sco_dept("TEST00") # set db connection
|
||||
truncate_database() # erase tables
|
||||
yield client
|
||||
# ndb.close_dept_connection()
|
||||
# Teardown:
|
||||
|
Loading…
Reference in New Issue
Block a user