From: Chris Fulljames Date: Thu, 30 Jan 2025 01:33:41 +0000 (-0500) Subject: Fix path issues that broke tests X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=470f6c3fb126518ed307104d6f270bd09e61b0ac;p=littlesongplace.git Fix path issues that broke tests --- diff --git a/main.py b/main.py index 6de9afe..5b296a8 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ from werkzeug.utils import secure_filename from werkzeug.middleware.proxy_fix import ProxyFix DATA_DIR = Path(os.environ["DATA_DIR"]) if "DATA_DIR" in os.environ else Path(".") +SCRIPT_DIR = Path(__file__).parent ################################################################################ # Logging @@ -622,8 +623,9 @@ def get_db(): db = getattr(g, '_database', None) if db is None: db = g._database = sqlite3.connect(DATA_DIR / "database.db") - if os.path.exists('schema_update.sql'): - with app.open_resource('schema_update.sql', mode='r') as f: + schema_update_script = SCRIPT_DIR / 'schema_update.sql' + if schema_update_script.exists(): + with app.open_resource(schema_update_script, mode='r') as f: db.cursor().executescript(f.read()) db.commit() db.row_factory = sqlite3.Row @@ -646,8 +648,8 @@ def query_db(query, args=(), one=False): def init_db(): """Clear the existing data and create new tables""" with app.app_context(): - db = get_db() - with app.open_resource('schema.sql', mode='r') as f: + db = sqlite3.connect(DATA_DIR / "database.db") + with app.open_resource(SCRIPT_DIR / 'schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit() diff --git a/test/test_offline.py b/test/test_offline.py index f4ff083..4e0ae56 100644 --- a/test/test_offline.py +++ b/test/test_offline.py @@ -2,6 +2,7 @@ import html import json import os import re +import sqlite3 import sys import tempfile from pathlib import Path @@ -23,10 +24,11 @@ def app(): # Initialize Database with main.app.app_context(): - db = main.get_db() + db = sqlite3.connect(main.DATA_DIR / "database.db") with main.app.open_resource('schema.sql', mode='r') as f: db.cursor().executescript(f.read()) db.commit() + db.close() yield main.app diff --git a/todo.txt b/todo.txt index ac015e5..157506a 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,5 @@ - Comments: - Update DB -- Fix play button not changing when clicking prev/next while paused - YouTube importer - Autoplay toggle - Volume control