From 56f935b2a8bd47cfaa6494026778d1cf5d348dfa Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 1 Aug 2021 10:52:28 +0300 Subject: [PATCH] improved our shell: reload context and admin user --- scodoc.py | 17 +++++ scotests/test_AnnuleAbsencesDatesNoJust.py | 66 ------------------- .../unit/formation-exemple-1.xml | 0 3 files changed, 17 insertions(+), 66 deletions(-) delete mode 100644 scotests/test_AnnuleAbsencesDatesNoJust.py rename scotests/export_formation1.xml => tests/unit/formation-exemple-1.xml (100%) diff --git a/scodoc.py b/scodoc.py index f53035bc2..9f6a61023 100755 --- a/scodoc.py +++ b/scodoc.py @@ -32,6 +32,14 @@ cli.register(app) def make_shell_context(): from app.scodoc import notesdb as ndb from app.scodoc import sco_utils as scu + from flask_login import login_user, logout_user, current_user + + admin_role = Role.query.filter_by(name="SuperAdmin").first() + admin = ( + User.query.join(UserRole) + .filter((UserRole.user_id == User.id) & (UserRole.role_id == admin_role.id)) + .first() + ) return { "db": db, @@ -45,9 +53,18 @@ def make_shell_context(): "pp": pp, "flask": flask, "current_app": flask.current_app, + "current_user": current_user, + "login_user": login_user, + "logout_user": logout_user, + "admin": admin, + "ctx": app.test_request_context(), } +# ctx.push() +# login_user(admin) + + @app.cli.command() def user_db_init(): # user-db-init """Initialize the users database.""" diff --git a/scotests/test_AnnuleAbsencesDatesNoJust.py b/scotests/test_AnnuleAbsencesDatesNoJust.py deleted file mode 100644 index 7fa933653..000000000 --- a/scotests/test_AnnuleAbsencesDatesNoJust.py +++ /dev/null @@ -1,66 +0,0 @@ -# -*- mode: python -*- -# -*- coding: utf-8 - - -""" Création d'une absence et utilisation de AnnuleAbsenceDatesNoJust """ -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_views - - -G = sco_fake_gen.ScoFake(context.Notes) -G.verbose = False - -# --- 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", -) - -# --- Création d'un étudiant -etud = G.create_etud(code_nip=None) -G.inscrit_etudiant(sem, etud) -etudid = etud["etudid"] - -# --- Création d'une absence -sco_abs_views.doSignaleAbsence( - context.Absences, - datedebut="22/01/2021", - datefin="22/01/2021", - demijournee=2, - etudid=etudid, - REQUEST=REQUEST, -) - -# --- Annulation d'absence -context.Absences.AnnuleAbsencesDatesNoJust(etudid, dates="22/01/2021") - -""" Erreur : File "/opt/scodoc/Products/ScoDoc/ZAbsences.py", line 323, in AnnuleAbsencesDatesNoJust - vars(), -psycopg2.DataError: invalid input syntax for type date: "2" -LINE 1: ...es where etudid='EID1' and (not estjust) and jour='2' and mo... """ \ No newline at end of file diff --git a/scotests/export_formation1.xml b/tests/unit/formation-exemple-1.xml similarity index 100% rename from scotests/export_formation1.xml rename to tests/unit/formation-exemple-1.xml