tests: Fix tests for current backend

This commit is contained in:
Ferdinand Thiessen 2021-12-21 22:56:03 +01:00
parent 9b42d2b5b7
commit aaec6b43ae
5 changed files with 16 additions and 25 deletions

View File

@ -35,7 +35,7 @@ install_requires =
[options.extras_require]
argon = argon2-cffi
ldap = flask_ldapconn; ldap3
test = pytest; coverage
tests = pytest; pytest-depends; coverage
[options.package_data]
* = *.toml

View File

@ -4,7 +4,7 @@ import pytest
from flaschengeist import database
from flaschengeist.app import create_app, install_all
from flask_migrate import upgrade
# read in SQL for populating test data
with open(os.path.join(os.path.dirname(__file__), "data.sql"), "r") as f:
@ -25,12 +25,16 @@ def app():
app = create_app(
{
"TESTING": True,
"DATABASE": {"file_path": f"/{db_path}"},
"DATABASE": {
"engine": "sqlite",
"database": f"/{db_path}"
},
"LOGGING": {"level": "DEBUG"},
}
)
with app.app_context():
install_all()
upgrade(directory='migrations', revision='heads')
# install_all()
engine = database.db.engine
with engine.connect() as connection:
for statement in _data_sql:

View File

@ -1,4 +1,8 @@
INSERT INTO user ('userid', 'firstname', 'lastname', 'mail', 'id') VALUES ('user', 'Max', 'Mustermann', 'abc@def.gh', 1);
INSERT INTO "user" ('userid', 'firstname', 'lastname', 'mail', 'deleted', 'id') VALUES ('user', 'Max', 'Mustermann', 'abc@def.gh', 0, 1);
INSERT INTO "user" ('userid', 'firstname', 'lastname', 'mail', 'deleted', 'id') VALUES ('deleted_user', 'John', 'Doe', 'doe@example.com', 1, 2);
-- Password = 1234
INSERT INTO user_attribute VALUES(1,1,'password',X'800495c4000000000000008cc0373731346161336536623932613830366664353038656631323932623134393936393561386463353536623037363761323037623238346264623833313265323333373066376233663462643332666332653766303537333564366335393133366463366234356539633865613835643661643435343931376636626663343163653333643635646530386634396231323061316236386162613164373663663333306564306463303737303733336136353363393538396536343266393865942e');
INSERT INTO session ('expires', 'token', 'lifetime', 'id', 'user_id') VALUES ('2999-01-01 00:00:00', 'f4ecbe14be3527ca998143a49200e294', 600, 1, 1);
INSERT INTO session ('expires', 'token', 'lifetime', 'id', 'user_id') VALUES ('2999-01-01 00:00:00', 'f4ecbe14be3527ca998143a49200e294', 600, 1, 1);
-- ROLES
INSERT INTO role ('name', 'id') VALUES ('role_1', 1);
INSERT INTO permission ('name', 'id') VALUES ('permission_1', 1);

View File

@ -15,9 +15,9 @@ def test_login(client):
# Login successful
assert result.status_code == 201
# User set correctly
assert json["user"]["userid"] == USERID
assert json["userid"] == USERID
# Token works
assert client.get("/auth", headers={"Authorization": f"Bearer {json['session']['token']}"}).status_code == 200
assert client.get("/auth", headers={"Authorization": f"Bearer {json['token']}"}).status_code == 200
def test_login_decorator(client):

View File

@ -1,17 +0,0 @@
import pytest
from werkzeug.exceptions import BadRequest
import flaschengeist.plugins.events.event_controller as event_controller
from flaschengeist.plugins.events.models import EventType
VALID_TOKEN = "f4ecbe14be3527ca998143a49200e294"
EVENT_TYPE_NAME = "Test Type"
def test_create_event_type(app):
with app.app_context():
type = event_controller.create_event_type(EVENT_TYPE_NAME)
assert isinstance(type, EventType)
with pytest.raises(BadRequest):
event_controller.create_event_type(EVENT_TYPE_NAME)