Skip to content

Commit

Permalink
Allow tests to complete using TESTING env
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Jul 8, 2024
1 parent d16c687 commit cbdc875
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions BookingSystem/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit cbdc875

Please sign in to comment.