From 4ca013e21148da0f4a2595cc005ce8dd7e167d2a Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 25 Nov 2014 12:25:41 +0100 Subject: [PATCH] Added test for song db upgrade --- .../openlp_plugins/songs/test_db.py | 35 ++++++++++++++++++ tests/resources/songs/songs-1.9.7.sqlite | Bin 0 -> 35840 bytes 2 files changed, 35 insertions(+) create mode 100755 tests/resources/songs/songs-1.9.7.sqlite 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 0000000000000000000000000000000000000000..98505464bcec08c1a4cc6921e03d6f9ae1ff4f15 GIT binary patch literal 35840 zcmeHQ?Qh%08Rv<%6)Sbzq)EBN@p85i*aDo`a^j|GoHVMVBwih-bCjh)Pzbbiw%Aal zDpFD0Pj#|k12Syr3Je(bC+zz^uHQCbf5xznZGfT0u(eKmQccrF;l;O8@alorFuW4*YHp;t^P>5^MOb!}qA%#q0kbtZ;M* z5!fOE;`*;$)cF5PZNHr(M>H}%@Hrdco0fiNWwTngVt#5lYxG9VEV8+GA6IPph}AsH zbuN!*&Q6b0<`mr$l(;;8H-G)i+vD$ENzHjKoY5>c3dKgR%-QQTtLR;ss5An z^wB7_%@t-}9?d|Bkq7hFvia--Mdb)ByAA3!81t!LX4G@*PAQcy!`!B4K4K+m(ngK> z#WJ<6hm2O(rPKm-og$+R)1$WQ`IB^|?o$V(m=%~7h0`Zf_aJY@wqQ5RT%aCfXFvMr z%G{JNv6H1U5ljE^*&p&;%^C*>%mbr*v%XgLX=R<3nOTElm#)IjWGd^Ff^v|@lRR2u zw#C4QOR1Y+UA4xFmRt8|$tp=%Qmk363ITcWzU%2?r01A5<^hUjz?YhKjhUr&T68(I++j=ccSQ&ThoNfB zRSp7puxi#K{x&SzrZ!07g~}jj3n-sg3}$rEt(Cwa4^VO|mIw8|=DGlr3o<8DH^HU` zFTr7Vt6&N%*1-t?7TN(<4;fzBVm7oFaIxyvd}zUdU@FTS3A9!aZChYJb4vWoEtohP zG4VbF2peVQfd62Nta`3#)n;B9RGVPKs%hD>9aKQS37Bw&GOx%?4;+C;D2i5H&to1q zWq~{{ltFj0>{M2s6-^KbKK(OlWyO%P!B~%q~yN%+98jB77_gbKg22&Ex}Fp(PpWm|47g2b#Eo50)2h zWtZ>M_jC8@gjGtX(hZU{jvpr*3&IuOt-`n`-xG=hGOdg4irJZ&x1*NDDc%@PB#n^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