ScoDoc/tests/conftest.py
Place Jean-Marie 3d9f362daf exclude .idea files from git
refactoring setinngs variables

in progress: import xml files

ajout creation user "bach" pour certains tests

pseudo-test pour initalisation Selenium

typo

Ajout/suppression de département en tant qu'utilisateur scodoc (non root)

complement scodoc.py pour import xml files

--amend

scodoc is able to perform database operation

move export..xml to tests/scenario dir
2021-08-09 22:23:00 +02:00

52 lines
1.8 KiB
Python

import pytest
from flask import g
from flask_login import login_user, logout_user, current_user
import app as myapp
from app import db, create_app
from app.auth.models import User, Role, Permission
from app.scodoc import sco_bulletins_standard
from app.scodoc import notesdb as ndb
def truncate_database():
"Erase content of all tables from current dept database"
# use a stored SQL function, see createtables.sql
ndb.SimpleQuery("SELECT truncate_tables('scodoc');", {})
@pytest.fixture()
def test_client():
# Setup
myapp.Config.TESTING = True
myapp.Config.SQLALCHEMY_DATABASE_URI = "sqlite://"
myapp.Config.SERVER_NAME = "test.gr"
apptest = create_app()
# Run tests:
with apptest.test_client() as client:
with apptest.app_context():
with apptest.test_request_context():
db.create_all()
Role.insert_roles()
u = User(user_name="admin")
super_admin_role = Role.query.filter_by(name="SuperAdmin").first()
u.add_role(super_admin_role, "TEST00")
# u.set_password("admin")
login_user(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
# ndb.close_dept_connection()
# Teardown:
db.session.remove()
db.drop_all()