From 06f66e6976258c7463741e8a62e7b16ad7eecfd8 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 7 Aug 2021 16:32:24 +0200 Subject: [PATCH 1/3] ajout creation user "bach" pour certains tests --- tests/conftest.py | 13 ++++++++++--- .../scenarios}/test_scenario1_formation.py | 0 2 files changed, 10 insertions(+), 3 deletions(-) rename {scotests => tests/scenarios}/test_scenario1_formation.py (100%) diff --git a/tests/conftest.py b/tests/conftest.py index 3e7888f0e9..758250f4da 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,11 +30,18 @@ def test_client(): db.create_all() Role.insert_roles() u = User(user_name="admin") - admin_role = Role.query.filter_by(name="SuperAdmin").first() - u.add_role(admin_role, "TEST00") + super_admin_role = Role.query.filter_by(name="SuperAdmin").first() + u.add_role(super_admin_role, "TEST00") # u.set_password("admin") login_user(u) - # db.session.add(u) + # Vérifie que l'utilisateur bach existe + u = User.query.filter_by(user_name="bach").first() + if u is None: + u = User(user_name="bach") + if not "Admin" in {r.name for r in u.roles}: + admin_role = Role.query.filter_by(name="Admin").first() + u.add_role(admin_role, "TEST00") + db.session.add(u) ndb.set_sco_dept("TEST00") # set db connection truncate_database() # erase tables yield client diff --git a/scotests/test_scenario1_formation.py b/tests/scenarios/test_scenario1_formation.py similarity index 100% rename from scotests/test_scenario1_formation.py rename to tests/scenarios/test_scenario1_formation.py From bf0b2c66bdfdc640c362a8724b20a40aa6a8d767 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 7 Aug 2021 16:33:47 +0200 Subject: [PATCH 2/3] pseudo-test pour initalisation Selenium --- tests/scenarios/test_scenario1_formation.py | 116 +++++++++----------- 1 file changed, 52 insertions(+), 64 deletions(-) diff --git a/tests/scenarios/test_scenario1_formation.py b/tests/scenarios/test_scenario1_formation.py index 564b3e1abc..8027be2164 100644 --- a/tests/scenarios/test_scenario1_formation.py +++ b/tests/scenarios/test_scenario1_formation.py @@ -1,73 +1,61 @@ -import sco_formations +# -*- coding: utf-8 -*- + +""" +Scenario: préparation base de données pour tests Selenium + +S'utilise comme un test avec pytest, mais n'est pas un test ! +Modifie la base de données du département TEST00 + +Usage: pytest tests/scenarios/test_scenario1_formation.py +""" +# code écrit par Fares Amer, mai 2021 et porté sur ScoDoc 8 en août 2021 + 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_moduleimpl +from tests.unit import sco_fake_gen +from app.scodoc import sco_edit_module +from app.scodoc import sco_formations +from app.scodoc import sco_moduleimpl -G = sco_fake_gen.ScoFake(context.Notes) -G.verbose = False - -file = open("scotests/export_formation1.xml") -doc = file.read() -file.close() +context = None # #context -# --- Création de la formation +def test_scenario1(test_client): + """Applique "scenario 1""" + G = sco_fake_gen.ScoFake(verbose=False) -f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) + # Lecture fichier XML local: + with open("tests/unit/formation-exemple-1.xml") as f: + doc = f.read() -# --- Création des semestres + # --- Création de la formation + f = sco_formations.formation_import_xml(doc=doc, context=context) -sem1 = G.create_formsemestre( - formation_id=f[0], - semestre_id=1, - date_debut="01/09/2020", - date_fin="01/02/2021", -) + # --- Création des semestres + formation_id = f[0] + # --- Mise en place de 4 semestres + sems = [ + G.create_formsemestre( + formation_id=formation_id, + semestre_id=x[0], + date_debut=x[1], + date_fin=x[2], + ) + for x in ( + (1, "01/09/2020", "01/02/2021"), + (2, "02/02/2021", "01/06/2021"), + (3, "01/09/2020", "01/02/2021"), + (4, "02/02/2021", "01/06/2021"), + ) + ] -sem3 = G.create_formsemestre( - formation_id=f[0], - semestre_id=3, - date_debut="01/09/2020", - date_fin="01/02/2021", -) - -sem2 = G.create_formsemestre( - formation_id=f[0], - semestre_id=2, - date_debut="02/02/2021", - date_fin="01/06/2021", -) - -sem4 = G.create_formsemestre( - formation_id=f[0], - semestre_id=4, - date_debut="02/02/2021", - date_fin="01/06/2021", -) - - -# --- Implémentation des modules - -li_module = context.Notes.do_module_list() -mods_imp = [] -for mod in li_module: - if mod["semestre_id"] == 1: - formsemestre_id = sem1["formsemestre_id"] - elif mod["semestre_id"] == 2: - formsemestre_id = sem2["formsemestre_id"] - elif mod["semestre_id"] == 3: - formsemestre_id = sem3["formsemestre_id"] - else: - formsemestre_id = sem4["formsemestre_id"] - - mi = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_id, - responsable_id="bach", - ) - mods_imp.append(mi) \ No newline at end of file + # --- Implémentation des modules + modules = sco_edit_module.do_module_list(context, {"formation_id": formation_id}) + mods_imp = [] + for mod in modules: + mi = G.create_moduleimpl( + module_id=mod["module_id"], + formsemestre_id=sems[mod["semestre_id"] - 1]["formsemestre_id"], + responsable_id="bach", + ) + mods_imp.append(mi) From 76a62707404d5130086bf7c7f18406d0fa462775 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 7 Aug 2021 16:34:03 +0200 Subject: [PATCH 3/3] typo --- tests/unit/sco_fake_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/sco_fake_gen.py b/tests/unit/sco_fake_gen.py index 9303ef385c..42c58452ef 100644 --- a/tests/unit/sco_fake_gen.py +++ b/tests/unit/sco_fake_gen.py @@ -66,7 +66,7 @@ def logging_meth(func): class ScoFake(object): - """Helper for ScoSoc tests""" + """Helper for ScoDoc tests""" def __init__(self, verbose=True): self.verbose = verbose