Fix unit tests

This commit is contained in:
Emmanuel Viennet 2024-02-22 18:32:51 +01:00
parent d1d89cc427
commit 46cdaf75b8
3 changed files with 11 additions and 4 deletions

View File

@ -116,7 +116,7 @@ class Module(models.ScoDocModel):
def create_from_dict(cls, data: dict) -> "Module":
"""Create from given dict, add parcours"""
mod = super().create_from_dict(data)
for p in data["parcours"]:
for p in data.get("parcours", []) or []:
if isinstance(p, ApcParcours):
parcour: ApcParcours = p
else:

View File

@ -59,6 +59,7 @@ cli.register(app)
@app.context_processor
def inject_sco_utils():
"Make scu available in all Jinja templates"
# if modified, put the same in conftest.py#27
return dict(scu=scu)

View File

@ -1,17 +1,17 @@
import pytest
from flask import g
from flask_login import login_user, logout_user, current_user
from flask_login import login_user
from config import TestConfig
import app
from app import db, create_app
from app import initialize_scodoc_database, clear_scodoc_cache
from app import models
from app.auth.models import User, Role, UserRole, Permission
from app.auth.models import User, Role
from app.auth.models import get_super_admin
from app.scodoc import sco_bulletins_standard
from app.scodoc import notesdb as ndb
import app.scodoc.sco_utils as scu
RESOURCES_DIR = "/opt/scodoc/tests/ressources"
@ -23,6 +23,12 @@ def test_client():
# Run tests:
with apptest.test_client() as client:
with apptest.app_context():
@apptest.context_processor
def inject_sco_utils():
"Make scu available in all Jinja templates"
return dict(scu=scu)
with apptest.test_request_context():
# initialize scodoc "g":
g.stored_get_formsemestre = {}