[System][Tests]: Added infrastructure for tests, added first unit test

This commit is contained in:
Ferdinand Thiessen 2021-01-23 02:18:44 +01:00
parent 94aac573e6
commit 62815d9278
3 changed files with 45 additions and 1 deletions

View File

@ -21,7 +21,7 @@ setup(
# Needed for python < 3.7
"backports-datetime-fromisoformat",
],
extras_require={"ldap": ["flask_ldapconn", "ldap3"]},
extras_require={"ldap": ["flask_ldapconn", "ldap3"], "tests": ["pytest"]},
entry_points={
"flaschengeist.plugin": [
# Authentication providers

28
tests/conftest.py Normal file
View File

@ -0,0 +1,28 @@
import os
import tempfile
import pytest
from flaschengeist.app import create_app, install_all
@pytest.fixture
def app():
db_fd, db_path = tempfile.mkstemp()
app = create_app(
{
"TESTING": True,
"DATABASE": {"file_path": f"/{db_path}"},
"FLASCHENGEIST": {"auth": "auth_plain"},
"auth_plain": {"enabled": True},
}
)
with app.app_context():
install_all()
yield app
os.close(db_fd)
os.unlink(db_path)
@pytest.fixture
def client(app):
return app.test_client()

16
tests/test_auth.py Normal file
View File

@ -0,0 +1,16 @@
import pytest
# with app.app_context():
# engine = database.db.engine
# with engine.connect() as connection:
# connection.execute("")
def test_login_decorator(client):
"""Testing the login_required decorator"""
# No header at all
assert client.get("/auth").status_code == 401
# Invalid header
assert client.get("/auth", headers={"Authorization": "INVALID"}).status_code == 401
# Invalid Token
assert client.get("/auth", headers={"Authorization": "Bearer INVALID"}).status_code == 401