forked from ScoDoc/ScoDoc
Améliore tests unitaires: create_module
This commit is contained in:
parent
f647ff1139
commit
346701d91e
@ -40,7 +40,6 @@ Le tout mis en forme au format markdown et rangé dans le répertoire DATA_DIR (
|
||||
TODO: ajouter un argument au script permettant de ne générer qu'un seul fichier (exemple: `python make_samples.py nom_exemple`)
|
||||
|
||||
"""
|
||||
import numpy as np
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
@ -13,6 +13,8 @@ from app.auth.models import get_super_admin
|
||||
from app.scodoc import sco_bulletins_standard
|
||||
from app.scodoc import notesdb as ndb
|
||||
|
||||
RESOURCES_DIR = "/opt/scodoc/tests/ressources"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def test_client():
|
||||
|
@ -3,6 +3,7 @@
|
||||
"""Test Logos
|
||||
Mise en place de l'environnement de test pour logos
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
from shutil import copytree, rmtree, copy
|
||||
|
||||
@ -13,9 +14,9 @@ from app import db, Departement
|
||||
from app.auth.models import User, Role
|
||||
from config import TestConfig
|
||||
from scodoc import app
|
||||
from tests.conftest import test_client
|
||||
from tests.conftest import test_client, RESOURCES_DIR
|
||||
|
||||
RESOURCES_DIR = "/opt/scodoc/tests/ressources/test_logos"
|
||||
LOGO_RESOURCES_DIR = os.path.join(RESOURCES_DIR, "test_logos")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -56,15 +57,15 @@ def create_logos(create_dept):
|
||||
dept2_id = dept2.id
|
||||
FILE_LIST = ["logo_A.jpg", "logo_C.jpg", "logo_D.png", "logo_E.jpg", "logo_F.jpeg"]
|
||||
for filename in FILE_LIST:
|
||||
from_path = Path(RESOURCES_DIR).joinpath(filename)
|
||||
from_path = Path(LOGO_RESOURCES_DIR).joinpath(filename)
|
||||
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(filename)
|
||||
copy(from_path.absolute(), to_path.absolute())
|
||||
copytree(
|
||||
f"{RESOURCES_DIR}/logos_1",
|
||||
f"{LOGO_RESOURCES_DIR}/logos_1",
|
||||
f"{scu.SCODOC_LOGOS_DIR}/logos_{dept1_id}",
|
||||
)
|
||||
copytree(
|
||||
f"{RESOURCES_DIR}/logos_2",
|
||||
f"{LOGO_RESOURCES_DIR}/logos_2",
|
||||
f"{scu.SCODOC_LOGOS_DIR}/logos_{dept2_id}",
|
||||
)
|
||||
yield dept1, dept2, dept3
|
||||
|
@ -17,7 +17,7 @@ import typing
|
||||
|
||||
from config import Config
|
||||
from app.auth.models import User
|
||||
from app.models import FormationModalite
|
||||
from app.models import FormationModalite, Matiere
|
||||
from app.scodoc import notesdb as ndb
|
||||
from app.scodoc import sco_codes_parcours
|
||||
from app.scodoc import sco_edit_formation
|
||||
@ -210,8 +210,6 @@ class ScoFake(object):
|
||||
heures_td=None,
|
||||
heures_tp=None,
|
||||
coefficient=None,
|
||||
ue_id=None,
|
||||
formation_id=None,
|
||||
matiere_id=None,
|
||||
semestre_id=1,
|
||||
numero=None,
|
||||
@ -220,10 +218,13 @@ class ScoFake(object):
|
||||
code_apogee=None,
|
||||
module_type=scu.ModuleType.STANDARD,
|
||||
) -> int:
|
||||
matiere = Matiere.query.get(matiere_id)
|
||||
ue_id = matiere.ue.id
|
||||
formation_id = matiere.ue.formation.id
|
||||
oid = sco_edit_module.do_module_create(locals())
|
||||
oids = sco_edit_module.module_list(args={"module_id": oid})
|
||||
if not oids:
|
||||
raise ScoValueError("module not created ! (oid=%s)" % oid)
|
||||
raise ScoValueError(f"module not created ! (oid={oid})")
|
||||
return oid
|
||||
|
||||
@logging_meth
|
||||
@ -361,8 +362,6 @@ class ScoFake(object):
|
||||
code="TSM%s" % len(mod_ids),
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
mod_ids.append(mod)
|
||||
return formation_id, ue_ids, mod_ids
|
||||
|
@ -46,8 +46,6 @@ def build_formation_test(
|
||||
code=f"TSM{i}",
|
||||
coefficient=1.0,
|
||||
titre=f"module test {i}",
|
||||
ue_id=_ue1,
|
||||
formation_id=formation_id,
|
||||
semestre_id=2,
|
||||
module_type=scu.ModuleType.RESSOURCE
|
||||
if parcours.APC_SAE
|
||||
@ -69,8 +67,6 @@ def build_formation_test(
|
||||
code="BAD",
|
||||
coefficient=1.0,
|
||||
titre="module sport",
|
||||
ue_id=ue_sport,
|
||||
formation_id=formation_id,
|
||||
semestre_id=2,
|
||||
)
|
||||
module_ids.append(mod_sport)
|
||||
|
@ -32,8 +32,6 @@ def test_abs_counts(test_client):
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
|
@ -36,8 +36,6 @@ def test_abs_demijournee(test_client):
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
@ -142,8 +140,6 @@ def test_abs_basic(test_client):
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id, # faiblesse de l'API
|
||||
formation_id=formation_id, # faiblesse de l'API
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
|
@ -42,7 +42,7 @@ def test_evaluation_poids(test_client):
|
||||
semestre_id=1,
|
||||
date_debut="01/01/2021",
|
||||
date_fin="30/06/2021",
|
||||
) # formsemestre_id=716
|
||||
)
|
||||
moduleimpl_id = G.create_moduleimpl(
|
||||
module_id=module_ids[0],
|
||||
formsemestre_id=formsemestre_id,
|
||||
|
@ -6,18 +6,20 @@
|
||||
|
||||
# test écrit par Fares Amer, mai 2021 et porté sur ScoDoc 8 en juillet 2021
|
||||
|
||||
# Créer 2 formations, une test et une normale. Créer 2 semestres dans la formation normale et un
|
||||
# dans la formation test, créer 2 semestres dans la formation normale (un test et un normal),
|
||||
# 2 ue (un test et un normal), 2 modules (un test et un normal) et 2 matieres (test et normal).
|
||||
# Et dans la formations test, un semestre, un module, un ue et une matiere.
|
||||
# Afficher la liste de tout ca puis supprimer les ue, mod, mat et sem test ainsi
|
||||
# que la formation test. Afficher la liste des UE, formations et modules restante.
|
||||
# Créer 2 formations, une test et une normale. Créer 2 semestres dans la
|
||||
# formation normale et un dans la formation test, créer 2 semestres dans la
|
||||
# formation normale (un test et un normal), 2 ue (un test et un normal), 2
|
||||
# modules (un test et un normal) et 2 matieres (test et normal). Et dans la
|
||||
# formations test, un semestre, un module, un ue et une matiere. Afficher la
|
||||
# liste de tout ca puis supprimer les ue, mod, mat et sem test ainsi que la
|
||||
# formation test. Afficher la liste des UE, formations et modules restante.
|
||||
#
|
||||
# Vérification :
|
||||
#
|
||||
# - Les listes initiales comprennent bien tout les éléments créés avec les bon noms etc
|
||||
# - Les listes initiales comprennent bien tout les éléments créés avec les bons
|
||||
# noms etc
|
||||
# - La supression s'est bien effectué au niveau de scodoc web et en python
|
||||
# - Vérifier que les fonctions listes font bien la mise à jour après supression
|
||||
# - Vérifier que les fonctions listes font bien la mise à jour après suppression
|
||||
#
|
||||
# Fonction de l'API utilisé :
|
||||
#
|
||||
@ -42,13 +44,12 @@
|
||||
# - do_formation_delete
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask
|
||||
from flask import g
|
||||
import pytest
|
||||
from app.models.moduleimpls import ModuleImpl
|
||||
from tests.unit import sco_fake_gen
|
||||
|
||||
from app.models.moduleimpls import ModuleImpl
|
||||
from app.scodoc import sco_edit_formation, sco_formsemestre
|
||||
from app.scodoc import sco_edit_matiere
|
||||
from app.scodoc import sco_edit_module
|
||||
@ -59,6 +60,9 @@ from app.scodoc import sco_formsemestre_edit
|
||||
from app.scodoc import sco_moduleimpl
|
||||
from app.views import notes
|
||||
|
||||
from tests.conftest import RESOURCES_DIR
|
||||
from tests.unit import sco_fake_gen
|
||||
|
||||
|
||||
def test_formations(test_client):
|
||||
"""Test création/édition/import/export formations"""
|
||||
@ -77,8 +81,6 @@ def test_formations(test_client):
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id, # faiblesse de l'API
|
||||
formation_id=formation_id, # faiblesse de l'API
|
||||
)
|
||||
|
||||
ue_id2 = G.create_ue(formation_id=formation_id, acronyme="TST2", titre="ue test2")
|
||||
@ -88,8 +90,6 @@ def test_formations(test_client):
|
||||
code="TSM2",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id2,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
uet_id = G.create_ue(formation_id=formation_id, acronyme="TSTt", titre="ue testt")
|
||||
@ -99,8 +99,6 @@ def test_formations(test_client):
|
||||
code="TSMt",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=uet_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
formation_id2 = G.create_formation(acronyme="", titre="Formation test")
|
||||
@ -112,8 +110,6 @@ def test_formations(test_client):
|
||||
code="TSM3",
|
||||
coefficient=1.0,
|
||||
titre="module test3",
|
||||
ue_id=ue3,
|
||||
formation_id=formation_id2,
|
||||
)
|
||||
|
||||
# --- Création et implémentation des semestres
|
||||
@ -334,11 +330,14 @@ def test_formations(test_client):
|
||||
assert len(load_lif3) == 1
|
||||
|
||||
|
||||
def test_import_formation(test_client):
|
||||
def test_import_formation(test_client, filename="formation-exemple-1.xml"):
|
||||
"""Test import/export formations"""
|
||||
G = sco_fake_gen.ScoFake(verbose=False)
|
||||
# Lecture fichier XML local:
|
||||
with open("tests/unit/formation-exemple-1.xml") as f:
|
||||
with open(
|
||||
os.path.join(RESOURCES_DIR, "formations", filename),
|
||||
encoding="utf-8",
|
||||
) as f:
|
||||
doc = f.read()
|
||||
|
||||
# --- Création de la formation
|
||||
|
@ -8,7 +8,6 @@ Utiliser comme:
|
||||
from pathlib import Path
|
||||
from shutil import copy
|
||||
|
||||
import pytest as pytest
|
||||
from _pytest.python_api import approx
|
||||
|
||||
import app
|
||||
@ -20,7 +19,7 @@ from app.scodoc.sco_logos import (
|
||||
write_logo,
|
||||
delete_logo,
|
||||
)
|
||||
from tests.unit.config_test_logos import create_dept, create_logos, RESOURCES_DIR
|
||||
from tests.unit.config_test_logos import create_dept, create_logos, LOGO_RESOURCES_DIR
|
||||
|
||||
|
||||
def test_select_global_only(create_logos):
|
||||
@ -90,7 +89,7 @@ def test_get_png_without_data(create_logos):
|
||||
|
||||
def test_delete_unique_global_jpg_logo(create_logos):
|
||||
dept1, dept2, dept3 = create_logos
|
||||
from_path = Path(RESOURCES_DIR).joinpath("logo_A.jpg")
|
||||
from_path = Path(LOGO_RESOURCES_DIR).joinpath("logo_A.jpg")
|
||||
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath("logo_W.jpg")
|
||||
copy(from_path.absolute(), to_path.absolute())
|
||||
assert to_path.exists()
|
||||
@ -100,7 +99,7 @@ def test_delete_unique_global_jpg_logo(create_logos):
|
||||
|
||||
def test_delete_unique_local_jpg_logo(create_logos):
|
||||
dept1, dept2, dept3 = create_logos
|
||||
from_path = Path(RESOURCES_DIR).joinpath("logo_A.jpg")
|
||||
from_path = Path(LOGO_RESOURCES_DIR).joinpath("logo_A.jpg")
|
||||
to_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_W.jpg")
|
||||
copy(from_path.absolute(), to_path.absolute())
|
||||
assert to_path.exists()
|
||||
@ -110,9 +109,9 @@ def test_delete_unique_local_jpg_logo(create_logos):
|
||||
|
||||
def test_delete_multiple_local_jpg_logo(create_logos):
|
||||
dept1, dept2, dept3 = create_logos
|
||||
from_path_A = Path(RESOURCES_DIR).joinpath("logo_A.jpg")
|
||||
from_path_A = Path(LOGO_RESOURCES_DIR).joinpath("logo_A.jpg")
|
||||
to_path_A = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_V.jpg")
|
||||
from_path_B = Path(RESOURCES_DIR).joinpath("logo_D.png")
|
||||
from_path_B = Path(LOGO_RESOURCES_DIR).joinpath("logo_D.png")
|
||||
to_path_B = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_V.png")
|
||||
copy(from_path_A.absolute(), to_path_A.absolute())
|
||||
copy(from_path_B.absolute(), to_path_B.absolute())
|
||||
@ -125,7 +124,7 @@ def test_delete_multiple_local_jpg_logo(create_logos):
|
||||
|
||||
def test_create_global_jpg_logo(create_logos):
|
||||
dept1, dept2, dept3 = create_logos
|
||||
path = Path(f"{RESOURCES_DIR}/logo_C.jpg")
|
||||
path = Path(f"{LOGO_RESOURCES_DIR}/logo_C.jpg")
|
||||
stream = path.open("rb")
|
||||
logo_path = Path(scu.SCODOC_LOGOS_DIR).joinpath("logo_X.jpg")
|
||||
assert not logo_path.exists()
|
||||
@ -136,7 +135,7 @@ def test_create_global_jpg_logo(create_logos):
|
||||
|
||||
def test_create_locale_jpg_logo(create_logos):
|
||||
dept1, dept2, dept3 = create_logos
|
||||
path = Path(f"{RESOURCES_DIR}/logo_C.jpg")
|
||||
path = Path(f"{LOGO_RESOURCES_DIR}/logo_C.jpg")
|
||||
stream = path.open("rb")
|
||||
logo_path = Path(scu.SCODOC_LOGOS_DIR).joinpath(f"logos_{dept1.id}", "logo_Y.jpg")
|
||||
assert not logo_path.exists()
|
||||
@ -149,7 +148,7 @@ def test_create_jpg_instead_of_png_logo(create_logos):
|
||||
dept1, dept2, dept3 = create_logos
|
||||
# action
|
||||
logo = Logo("D") # create global logo (replace logo_D.png)
|
||||
path = Path(f"{RESOURCES_DIR}/logo_C.jpg")
|
||||
path = Path(f"{LOGO_RESOURCES_DIR}/logo_C.jpg")
|
||||
stream = path.open("rb")
|
||||
logo.create(stream)
|
||||
# test
|
||||
@ -163,7 +162,7 @@ def test_create_jpg_instead_of_png_logo(create_logos):
|
||||
assert logo is not None
|
||||
assert logo.filepath == f"{scu.SCODOC_LOGOS_DIR}/logo_D.jpg" # created.absolute()
|
||||
# restore initial state
|
||||
original = Path(f"{RESOURCES_DIR}/logo_D.png")
|
||||
original = Path(f"{LOGO_RESOURCES_DIR}/logo_D.png")
|
||||
copy(original, removed)
|
||||
created.unlink(missing_ok=True)
|
||||
|
||||
|
@ -69,8 +69,6 @@ def test_notes_modules(test_client):
|
||||
code="TSM1",
|
||||
coefficient=coef_mod_1,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
@ -261,8 +259,6 @@ def test_notes_modules(test_client):
|
||||
code="TSM2",
|
||||
coefficient=coef_mod_2,
|
||||
titre="module test 2",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
moduleimpl_id2 = G.create_moduleimpl(
|
||||
module_id=module_id2,
|
||||
@ -356,8 +352,6 @@ def test_notes_modules_att_dem(test_client):
|
||||
code="TSM1",
|
||||
coefficient=coef_mod_1,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
#
|
||||
# --------------------------------
|
||||
|
@ -37,8 +37,6 @@ def test_notes_rattrapage(test_client):
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
|
@ -64,8 +64,6 @@ def run_sco_basic(verbose=False) -> FormSemestre:
|
||||
code="TSM1",
|
||||
coefficient=1.0,
|
||||
titre="module test",
|
||||
ue_id=ue_id,
|
||||
formation_id=formation_id,
|
||||
)
|
||||
|
||||
# --- Mise place d'un semestre
|
||||
|
Loading…
Reference in New Issue
Block a user