Added Database tests
This commit is contained in:
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal 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)
|
||||
|
Reference in New Issue
Block a user