]> littlesong.place Git - littlesongplace.git/commitdiff
Fix path issues that broke tests
authorChris Fulljames <christianfulljames@gmail.com>
Thu, 30 Jan 2025 01:33:41 +0000 (20:33 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Thu, 30 Jan 2025 01:33:41 +0000 (20:33 -0500)
main.py
test/test_offline.py
todo.txt

diff --git a/main.py b/main.py
index 6de9afeed4069059d8357b15ffbe1d37c07524c1..5b296a8acc7222de27496e09ae60a43472bd9fa3 100644 (file)
--- 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()
 
index f4ff08321723077ea6b33b7e731221481e1115c6..4e0ae564fcfb35b9b8849fb88c970ea41269faf7 100644 (file)
@@ -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
 
index ac015e5ffb012222442f4c24a96350d6619d54f7..157506a6795037ad530b7f549e9bf141ea26192f 100644 (file)
--- 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