From 46cdaf75b8765c91cf4b260c112314df4a28bcb0 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 22 Feb 2024 18:32:51 +0100 Subject: [PATCH] Fix unit tests --- app/models/modules.py | 2 +- scodoc.py | 1 + tests/conftest.py | 12 +++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/modules.py b/app/models/modules.py index 3da839a7..5abb5340 100644 --- a/app/models/modules.py +++ b/app/models/modules.py @@ -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: diff --git a/scodoc.py b/scodoc.py index 4c082082..91421385 100755 --- a/scodoc.py +++ b/scodoc.py @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index f9e72a66..78ed0dc0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 = {}