# 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
