diff --git a/tests/functional/openlp_plugins/songs/test_db.py b/tests/functional/openlp_plugins/songs/test_db.py index e696ea94b..e37cc58cb 100644 --- a/tests/functional/openlp_plugins/songs/test_db.py +++ b/tests/functional/openlp_plugins/songs/test_db.py @@ -29,9 +29,15 @@ """ This module contains tests for the db submodule of the Songs plugin. """ +import os +import shutil from unittest import TestCase +from tempfile import mkdtemp from openlp.plugins.songs.lib.db import Song, Author, AuthorType +from openlp.plugins.songs.lib import upgrade +from openlp.core.lib.db import upgrade_db +from tests.utils.constants import TEST_RESOURCES_PATH class TestDB(TestCase): @@ -39,6 +45,18 @@ class TestDB(TestCase): Test the functions in the :mod:`db` module. """ + def setUp(self): + """ + Setup for tests + """ + self.tmp_folder = mkdtemp() + + def tearDown(self): + """ + Clean up after tests + """ + shutil.rmtree(self.tmp_folder) + def test_add_author(self): """ Test adding an author to a song @@ -153,3 +171,20 @@ class TestDB(TestCase): # THEN: It should return the name with the type in brackets self.assertEqual("John Doe (Words)", display_name) + + def test_upgrade_song_db(self): + """ + Test that we can upgrade an old song db to the current schema + """ + # GIVEN: An old song db + old_db_path = os.path.join(TEST_RESOURCES_PATH, "songs", 'songs-1.9.7.sqlite') + old_db_tmp_path = os.path.join(self.tmp_folder, 'songs-1.9.7.sqlite') + shutil.copyfile(old_db_path, old_db_tmp_path) + db_url = 'sqlite:///' + old_db_tmp_path + + # WHEN: upgrading the db + updated_to_version, latest_version = upgrade_db(db_url, upgrade) + + # Then the song db should have been upgraded to the latest version + self.assertEqual(updated_to_version, latest_version, + 'The song DB should have been upgrade to the latest version') diff --git a/tests/resources/songs/songs-1.9.7.sqlite b/tests/resources/songs/songs-1.9.7.sqlite new file mode 100755 index 000000000..98505464b Binary files /dev/null and b/tests/resources/songs/songs-1.9.7.sqlite differ