Skip to content
Snippets Groups Projects
Commit 37101eaf authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

#57 Database tar imot db_path

parent 657a3233
No related branches found
No related tags found
2 merge requests!44#57 Database: testmodus og bruk samme instans overalt,!42WIP: #57 Én databaseinstans og testmodus for database
Pipeline #76596 passed
......@@ -8,10 +8,8 @@ from soitool.enumerates import CodebookSort
# Set name and path to (future) database
DBNAME = "database"
TESTDBNAME = "testDatabase"
CURDIR = os.path.dirname(__file__)
DBPATH = os.path.join(CURDIR, DBNAME)
TESTDBPATH = os.path.join(CURDIR, TESTDBNAME)
# Number og seconds in 24h
SECONDS_IN_24H = 24 * 60 * 60
......@@ -40,16 +38,9 @@ class Database:
If db is created, tables are created and filled.
Holds a QTimer that requests an update of CodeBook on every timeout.
Database can be run in testmode, this will create a seperate database-file.
"""
def __init__(self, testmode=False):
if testmode:
db_path = TESTDBPATH
else:
db_path = DBPATH
def __init__(self, db_path=DBPATH):
db_exists = os.path.exists(db_path)
......@@ -67,7 +58,7 @@ class Database:
self.fill_tables()
print("Tables filled with data.")
self.conn.row_factory = sqlite3.Row # Enables row['columnName']
self.conn.row_factory = sqlite3.Row # Enables row["columnName"]
def create_tables(self):
"""Create tables CodeBook, CategoryWords and ByHeart."""
......
......@@ -5,9 +5,13 @@ import unittest
import json
from time import sleep
from datetime import datetime
from soitool.database import Database, TESTDBPATH
from soitool.database import Database
from soitool.coder import get_code_length_needed
TESTDBNAME = "testDatabase"
SOITOOL_DIR = Path(__file__).parent.parent / "soitool"
TESTDBPATH = os.path.join(SOITOOL_DIR, TESTDBNAME)
TESTDATA_PATH = Path(__file__).parent.parent / "soitool/testdata"
......@@ -16,7 +20,7 @@ class DatabaseTest(unittest.TestCase):
def setUp(self):
"""Connect to/create database."""
self.database = Database(testmode=True)
self.database = Database(db_path=TESTDBPATH)
self.addCleanup(self.delete_db)
def test_connection(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment