From 067b8eef712c6da928b78c849a9f7526c1671dfa Mon Sep 17 00:00:00 2001 From: Son NK Date: Fri, 12 Jul 2019 11:35:30 +0200 Subject: [PATCH] use .env.example in test, disable CSRF in tests --- tests/conftest.py | 9 ++++++++- tests/test_server.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 79e8a78b..20dc3469 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,9 @@ import os -os.environ["CONFIG"] = ".env.example" +os.environ["CONFIG"] = os.path.abspath( + os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env.example") +) + # use in-memory database # need to set before importing any other module as DB_URI is init at import time @@ -16,7 +19,10 @@ from server import create_app def flask_app(): app = create_app() + # use in-memory database + app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" app.config["TESTING"] = True + app.config["WTF_CSRF_ENABLED"] = False with app.app_context(): db.create_all() @@ -31,6 +37,7 @@ def flask_client(): # use in-memory database app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" app.config["TESTING"] = True + app.config["WTF_CSRF_ENABLED"] = False client = app.test_client() diff --git a/tests/test_server.py b/tests/test_server.py index e7a66d2f..23bf8c48 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -3,4 +3,4 @@ def test_redirect_login_page(flask_client): rv = flask_client.get("/") assert rv.status_code == 302 - assert rv.location == "http://localhost/auth/login" + assert rv.location == "http://sl.local/auth/login"