musicmuster/tests/test_misc.py
Keith Edmunds 71257e4d67 Ensure one db instance only
Ensure testing db is correctly set to sqlite
2024-06-16 08:40:03 +01:00

41 lines
979 B
Python

# Standard library imports
import unittest
# PyQt imports
# Third party imports
import pytest
# App imports
from app.models import db, Settings
class TestMMMisc(unittest.TestCase):
def setUp(self):
db.create_all()
def tearDown(self):
db.drop_all()
def test_log_exception(self):
"""Test deliberate exception"""
with pytest.raises(Exception):
1 / 0
def test_create_settings(self):
SETTING_NAME = "wombat"
NO_SUCH_SETTING = "abc"
VALUE = 3
with db.Session() as session:
setting = Settings(session, SETTING_NAME)
# test repr
_ = str(setting)
setting.f_int = VALUE
test = Settings.get_setting(session, SETTING_NAME)
assert test.name == SETTING_NAME
assert test.f_int == VALUE
test_new = Settings.get_setting(session, NO_SUCH_SETTING)
assert test_new.name == NO_SUCH_SETTING