From aaec6b43ae697b96f766002dff4440793ec20269 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 21 Dec 2021 22:56:03 +0100 Subject: [PATCH] tests: Fix tests for current backend --- setup.cfg | 2 +- tests/conftest.py | 10 +++++++--- tests/data.sql | 8 ++++++-- tests/test_auth.py | 4 ++-- tests/test_events.py | 17 ----------------- 5 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 tests/test_events.py diff --git a/setup.cfg b/setup.cfg index b5347c8..982d0ab 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 5290fd8..f1dbb31 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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: diff --git a/tests/data.sql b/tests/data.sql index 6c6a989..98bb489 100644 --- a/tests/data.sql +++ b/tests/data.sql @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/tests/test_auth.py b/tests/test_auth.py index 5e7cadb..b4c60a5 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -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): diff --git a/tests/test_events.py b/tests/test_events.py deleted file mode 100644 index a847ce1..0000000 --- a/tests/test_events.py +++ /dev/null @@ -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)