40 lines
1.2 KiB
Python
40 lines
1.2 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
|
|
|
|
|
|
@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")
|
|
admin_role = Role.query.filter_by(name="Admin").first()
|
|
u.add_role(admin_role, "TEST00")
|
|
# u.set_password("admin")
|
|
login_user(u)
|
|
# db.session.add(u)
|
|
|
|
g.scodoc_dept = "RT"
|
|
g.db_conn = ndb.open_dept_connection()
|
|
yield client
|
|
# ndb.close_dept_connection()
|
|
# Teardown:
|
|
db.session.remove()
|
|
db.drop_all()
|