Added Database tests

This commit is contained in:
2024-01-09 22:20:32 +00:00
parent feaa253a01
commit b7dd1b9ef0
9 changed files with 72 additions and 28 deletions

0
scripts/__init__.py Normal file
View File

View File

@ -20,11 +20,10 @@ def create_connection(path: str, filename: str):
print("Table creation complete")
# Populate with test data if we are in Test Mode
if os.environ.get("ENVIRON") != "test":
return
sql = open("scripts/test_data.sql", "r");
conn.executescript(sql.read())
if os.environ.get("ENVIRON") == "test":
sql = open("scripts/test_data.sql", "r");
conn.executescript(sql.read())
except sqlite3.Error as e:
print(e)
finally:
@ -43,15 +42,17 @@ def remove_file(dir: str):
os.remove(dir)
except FileNotFoundError:
pass
if __name__ == '__main__':
dir = r"./data/"
db_name = r"wmgzon.db"
# Check for test environ
if os.environ.get("ENVIRON") == "test":
# Remove the original test database
print("TEST ENVIRONMENT ACTIVE")
db_name = "test_" + db_name
remove_file(dir + db_name)
create_connection(dir, db_name)
dir = r"./data/"
db_name = r"wmgzon.db"
# Check for test environ
if os.environ.get("ENVIRON") == "test":
# Remove the original test database
print("TEST ENVIRONMENT ACTIVE")
db_name = "test_" + db_name
remove_file(dir + db_name)
create_connection(dir, db_name)