From cbdc875678301c958c5af3e899096ea453398d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Gr=C3=B8n=C3=A5s?= <44143748+sondregronas@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:45:56 +0200 Subject: [PATCH] Allow tests to complete using TESTING env --- BookingSystem/app.py | 12 +++++++----- tests/conftest.py | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/BookingSystem/app.py b/BookingSystem/app.py index b069fc2..e42abba 100644 --- a/BookingSystem/app.py +++ b/BookingSystem/app.py @@ -27,9 +27,10 @@ def create_app() -> flask.Flask: app = flask.Flask(__name__, template_folder='templates', static_folder='static') app.secret_key = os.getenv('SECRET_KEY') + app.config['TESTING'] = os.getenv('TESTING', 'false').lower() == 'true' app.config['SESSION_TYPE'] = 'cachelib' app.config['SESSION_CACHELIB'] = cachelib.FileSystemCache(cache_dir='./flask_session', threshold=500) - if os.getenv('DEBUG') == 'True': + if os.getenv('DEBUG', 'false').lower() == 'true': app.debug = True # We're behind a reverse proxy, so we need to fix the scheme and host @@ -127,14 +128,15 @@ def debug_login() -> flask.Response: Compress(app) Minify(app, static=False, go=False) # Some static files don't minify well (breaks JS) + init_db() + Settings.verify_settings_exist() + if not DEBUG and not app.config['TESTING']: + start_routine() + return app -init_db() app = create_app() -Settings.verify_settings_exist() -if not DEBUG: - start_routine() if __name__ == '__main__': app.run(host='0.0.0.0') diff --git a/tests/conftest.py b/tests/conftest.py index a5af0bd..8493367 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,12 @@ +import os import sys from pathlib import Path import flask import pytest -sys.path.append(str(Path(__file__).parent.parent) + '\\BookingSystem') +sys.path.append(str(Path(__file__).parent.parent) + '\\BookingSystem') # Add BookingSystem to path for imports +os.environ['TESTING'] = 'true' # Set TESTING to true before importing app import BookingSystem.app as app from BookingSystem.db import init_db from BookingSystem.user import User @@ -40,7 +42,6 @@ def is_admin(self) -> bool: @pytest.fixture def client(): flask_app = app.create_app() - flask_app.config['TESTING'] = True init_db() yield flask_app.test_client()