mirror of https://gitlab.com/openlp/openlp.git
Create a connection and then run execute
This commit is contained in:
parent
14d3eff0bb
commit
58076ace93
|
@ -315,11 +315,10 @@ class DBManager(object):
|
|||
"""
|
||||
VACUUM the database on exit.
|
||||
"""
|
||||
if self.is_dirty:
|
||||
engine = create_engine(self.db_url)
|
||||
if self.db_url.startswith('sqlite'):
|
||||
try:
|
||||
engine.execute("vacuum")
|
||||
except OperationalError:
|
||||
# Just ignore the operational error
|
||||
pass
|
||||
if self.is_dirty and self.db_url.startswith('sqlite'):
|
||||
try:
|
||||
engine = create_engine(self.db_url)
|
||||
engine.connect().execute("vacuum")
|
||||
except OperationalError:
|
||||
# Just ignore the operational error
|
||||
pass
|
||||
|
|
|
@ -40,7 +40,7 @@ def test_manager_finalise_exception(mocked_create_engine, mocked_init_url, temp_
|
|||
def init_schema(url):
|
||||
return mocked_session
|
||||
|
||||
mocked_create_engine.return_value.execute.side_effect = SQLAlchemyOperationalError(
|
||||
mocked_create_engine.return_value.connect.return_value.execute.side_effect = SQLAlchemyOperationalError(
|
||||
statement='vacuum',
|
||||
params=[],
|
||||
orig=SQLiteOperationalError('database is locked')
|
||||
|
@ -52,7 +52,7 @@ def test_manager_finalise_exception(mocked_create_engine, mocked_init_url, temp_
|
|||
manager.finalise()
|
||||
|
||||
# THEN: vacuum should have been called on the database
|
||||
mocked_create_engine.return_value.execute.assert_called_once_with('vacuum')
|
||||
mocked_create_engine.return_value.connect.return_value.execute.assert_called_once_with('vacuum')
|
||||
|
||||
|
||||
@patch('openlp.core.db.manager.init_url')
|
||||
|
@ -73,4 +73,4 @@ def test_manager_finalise(mocked_create_engine, mocked_init_url, temp_folder, se
|
|||
manager.finalise()
|
||||
|
||||
# THEN: vacuum should have been called on the database
|
||||
mocked_create_engine.return_value.execute.assert_called_once_with('vacuum')
|
||||
mocked_create_engine.return_value.connect.return_value.execute.assert_called_once_with('vacuum')
|
||||
|
|
Loading…
Reference in New Issue