forked from openlp/openlp
Test for db upgrade skip
This commit is contained in:
parent
4b22def91d
commit
208c1b022f
@ -62,7 +62,7 @@ def database_exists(url):
|
|||||||
create_database(engine.url)
|
create_database(engine.url)
|
||||||
database_exists(engine.url) #=> True
|
database_exists(engine.url) #=> True
|
||||||
|
|
||||||
Borrowed from SQLAlchemy_Utils since we only need this one function.
|
Borrowed from SQLAlchemy_Utils (v0.32.14 )since we only need this one function.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = copy(make_url(url))
|
url = copy(make_url(url))
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
Package to test the openlp.core.lib package.
|
Package to test the openlp.core.lib package.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from tempfile import mkdtemp
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
@ -30,13 +33,27 @@ from sqlalchemy.pool import NullPool
|
|||||||
from sqlalchemy.orm.scoping import ScopedSession
|
from sqlalchemy.orm.scoping import ScopedSession
|
||||||
from sqlalchemy import MetaData
|
from sqlalchemy import MetaData
|
||||||
|
|
||||||
from openlp.core.lib.db import init_db, get_upgrade_op, delete_database
|
from openlp.core.lib.db import init_db, get_upgrade_op, delete_database, upgrade_db
|
||||||
|
from openlp.core.lib.projector import upgrade as pjlink_upgrade
|
||||||
|
|
||||||
|
|
||||||
class TestDB(TestCase):
|
class TestDB(TestCase):
|
||||||
"""
|
"""
|
||||||
A test case for all the tests for the :mod:`~openlp.core.lib.db` module.
|
A test case for all the tests for the :mod:`~openlp.core.lib.db` module.
|
||||||
"""
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
"""
|
||||||
|
Set up anything necessary for all tests
|
||||||
|
"""
|
||||||
|
self.tmp_folder = mkdtemp(prefix='openlp_')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""
|
||||||
|
Clean up
|
||||||
|
"""
|
||||||
|
# Ignore errors since windows can have problems with locked files
|
||||||
|
shutil.rmtree(self.tmp_folder, ignore_errors=True)
|
||||||
|
|
||||||
def test_init_db_calls_correct_functions(self):
|
def test_init_db_calls_correct_functions(self):
|
||||||
"""
|
"""
|
||||||
Test that the init_db function makes the correct function calls
|
Test that the init_db function makes the correct function calls
|
||||||
@ -145,3 +162,17 @@ class TestDB(TestCase):
|
|||||||
MockedAppLocation.get_section_data_path.assert_called_with(test_plugin)
|
MockedAppLocation.get_section_data_path.assert_called_with(test_plugin)
|
||||||
mocked_delete_file.assert_called_with(test_location)
|
mocked_delete_file.assert_called_with(test_location)
|
||||||
self.assertFalse(result, 'The result of delete_file should be False (was rigged that way)')
|
self.assertFalse(result, 'The result of delete_file should be False (was rigged that way)')
|
||||||
|
|
||||||
|
@patch('tests.functional.openlp_core_lib.test_db.pjlink_upgrade')
|
||||||
|
def test_skip_db_upgrade_with_no_database(self, mocked_upgrade):
|
||||||
|
"""
|
||||||
|
Test the upgrade_db function does not try to update a missing database
|
||||||
|
"""
|
||||||
|
# GIVEN: Database URL that does not (yet) exist
|
||||||
|
url = 'sqlite:///{tmp}/test_db.sqlite'.format(tmp=self.tmp_folder)
|
||||||
|
|
||||||
|
# WHEN: We attempt to upgrade a non-existant database
|
||||||
|
upgrade_db(url, pjlink_upgrade)
|
||||||
|
|
||||||
|
# THEN: upgrade should NOT have been called
|
||||||
|
self.assertFalse(mocked_upgrade.called, 'Database upgrade function should NOT have been called')
|
||||||
|
Loading…
Reference in New Issue
Block a user