db: Create a function for checking if this is a new database

So the tagdb can attempt to import tracks if none have been added to the
sql database yet.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-10-13 13:51:16 -04:00
parent f82e299736
commit 6b5b2a745e
2 changed files with 16 additions and 0 deletions

View File

@ -2,6 +2,13 @@
import lib
import pathlib
def new_db():
from . import sql
try:
return sql.execute("SELECT COUNT(*) from tracks").fetchone()[0] == 0
except:
return True
from . import artist
from . import album

9
db/test_db.py Normal file
View File

@ -0,0 +1,9 @@
# Copyright 2021 (c) Anna Schumaker.
import db
import unittest
class TestDB(unittest.TestCase):
def test_new_db(self):
self.assertTrue(db.new_db())
db.make_fake_track(1, 1, "Test Track", "/a/b/c/1.ogg")
self.assertFalse(db.new_db())