Merge branch 'issue-1624' into 'master'

Fix issue #1624

Closes #1624

See merge request openlp/openlp!650
This commit is contained in:
Raoul Snyman 2023-08-18 21:01:55 +00:00
commit 0d7f664626
2 changed files with 11 additions and 4 deletions

View File

@ -26,7 +26,7 @@ from pathlib import Path
from types import FunctionType, ModuleType
from typing import List, Optional, Type, Union
from sqlalchemy import create_engine, func
from sqlalchemy import create_engine, func, text
from sqlalchemy.exc import DBAPIError, InvalidRequestError, OperationalError, SQLAlchemyError
from sqlalchemy.orm import Session
from sqlalchemy.orm.decl_api import DeclarativeMeta
@ -318,7 +318,7 @@ class DBManager(object):
if self.is_dirty and self.db_url.startswith('sqlite'):
try:
engine = create_engine(self.db_url)
engine.connect().execute("vacuum")
engine.connect().execute(text('vacuum'))
except OperationalError:
# Just ignore the operational error
pass

View File

@ -26,16 +26,20 @@ from unittest.mock import MagicMock, patch
from sqlalchemy.exc import OperationalError as SQLAlchemyOperationalError
from openlp.core.common.settings import Settings
from openlp.core.db.manager import DBManager
@patch('openlp.core.db.manager.text')
@patch('openlp.core.db.manager.init_url')
@patch('openlp.core.db.manager.create_engine')
def test_manager_finalise_exception(mocked_create_engine, mocked_init_url, temp_folder, settings):
def test_manager_finalise_exception(mocked_create_engine: MagicMock, mocked_init_url: MagicMock,
mocked_text: MagicMock, temp_folder: str, settings: Settings):
"""Test that the finalise method silently fails on an exception"""
# GIVEN: A db Manager object
mocked_init_url.return_value = f'sqlite:///{temp_folder}/test_db.sqlite'
mocked_session = MagicMock()
mocked_text.side_effect = lambda t: t
def init_schema(url):
return mocked_session
@ -55,13 +59,16 @@ def test_manager_finalise_exception(mocked_create_engine, mocked_init_url, temp_
mocked_create_engine.return_value.connect.return_value.execute.assert_called_once_with('vacuum')
@patch('openlp.core.db.manager.text')
@patch('openlp.core.db.manager.init_url')
@patch('openlp.core.db.manager.create_engine')
def test_manager_finalise(mocked_create_engine, mocked_init_url, temp_folder, settings):
def test_manager_finalise(mocked_create_engine: MagicMock, mocked_init_url: MagicMock, mocked_text: MagicMock,
temp_folder: str, settings: Settings):
"""Test that the finalise method works correctly"""
# GIVEN: A db Manager object
mocked_init_url.return_value = f'sqlite:///{temp_folder}/test_db.sqlite'
mocked_session = MagicMock()
mocked_text.side_effect = lambda t: t
def init_schema(url):
return mocked_session