2021-07-20 08:01:56 +02:00
|
|
|
import pytest
|
|
|
|
|
2021-07-20 17:32:04 +02:00
|
|
|
from flask import g
|
2021-07-30 09:36:30 +02:00
|
|
|
from flask_login import login_user, logout_user, current_user
|
2021-07-20 17:32:04 +02:00
|
|
|
|
|
|
|
import app as myapp
|
|
|
|
from app import db, create_app
|
2021-07-20 08:01:56 +02:00
|
|
|
from app.auth.models import User, Role, Permission
|
2021-07-20 17:32:04 +02:00
|
|
|
from app.scodoc import sco_bulletins_standard
|
|
|
|
from app.scodoc import notesdb as ndb
|
2021-07-20 08:01:56 +02:00
|
|
|
|
|
|
|
|
2021-07-20 17:32:04 +02:00
|
|
|
@pytest.fixture()
|
2021-07-20 08:01:56 +02:00
|
|
|
def test_client():
|
|
|
|
# Setup
|
2021-07-20 17:32:04 +02:00
|
|
|
myapp.Config.TESTING = True
|
|
|
|
myapp.Config.SQLALCHEMY_DATABASE_URI = "sqlite://"
|
2021-07-30 09:36:30 +02:00
|
|
|
myapp.Config.SERVER_NAME = "test.gr"
|
2021-07-20 17:32:04 +02:00
|
|
|
apptest = create_app()
|
2021-07-20 08:01:56 +02:00
|
|
|
# Run tests:
|
2021-07-20 17:32:04 +02:00
|
|
|
with apptest.test_client() as client:
|
|
|
|
with apptest.app_context():
|
2021-07-30 09:36:30 +02:00
|
|
|
with apptest.test_request_context():
|
|
|
|
db.create_all()
|
|
|
|
Role.insert_roles()
|
|
|
|
u = User(user_name="admin")
|
2021-07-31 18:01:10 +02:00
|
|
|
admin_role = Role.query.filter_by(name="SuperAdmin").first()
|
2021-07-30 09:36:30 +02:00
|
|
|
u.add_role(admin_role, "TEST00")
|
|
|
|
# u.set_password("admin")
|
|
|
|
login_user(u)
|
|
|
|
# db.session.add(u)
|
|
|
|
|
2021-07-31 18:01:10 +02:00
|
|
|
g.scodoc_dept = "TEST00"
|
2021-07-30 09:36:30 +02:00
|
|
|
g.db_conn = ndb.open_dept_connection()
|
|
|
|
yield client
|
|
|
|
# ndb.close_dept_connection()
|
|
|
|
# Teardown:
|
|
|
|
db.session.remove()
|
|
|
|
db.drop_all()
|