def test_upgrade_2_both_selected(self): """ Tcest that upgrade 2 completes properly when the user chooses to use a both HTTP and HTTPS proxies """ # GIVEN: An version 1 web bible with proxy settings # WHEN: Calling upgrade_db self.mocked_message_box_instance.clickedButton.return_value = self.mocked_both_button upgrade_db(self.db_url, upgrade) # THEN: The proxy settings should have been removed, the version should have been changed to version 2, and the # proxy server saved to the settings engine = create_engine(self.db_url) conn = engine.connect() assert len( conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"'). fetchall()) == 0 assert len( conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"' ).fetchall()) == 0 assert len( conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"' ).fetchall()) == 0 assert conn.execute('SELECT * FROM metadata WHERE key = "version"' ).first().value == '2' assert self.mocked_settings.setValue.call_args_list == [ call('advanced/proxy http', 'proxy_server'), call('advanced/proxy https', 'proxy_server'), call('advanced/proxy username', 'proxy_username'), call('advanced/proxy password', 'proxy_password'), call('advanced/proxy mode', ProxyMode.MANUAL_PROXY) ]
def test_upgrade_2_none_selected(self): """ Test that upgrade 2 completes properly when the user chooses not to use a proxy ('No') """ # GIVEN: An version 1 web bible with proxy settings # WHEN: Calling upgrade_db and the user has 'clicked' the 'No' button self.mocked_message_box_instance.clickedButton.return_value = self.mocked_no_button upgrade_db(self.db_url, upgrade) # THEN: The proxy meta data should have been removed, and the version should have been changed to version 2 engine = create_engine(self.db_url) conn = engine.connect() assert len( conn.execute('SELECT * FROM metadata WHERE key = "proxy_server"'). fetchall()) == 0 assert len( conn.execute('SELECT * FROM metadata WHERE key = "proxy_username"' ).fetchall()) == 0 assert len( conn.execute('SELECT * FROM metadata WHERE key = "proxy_password"' ).fetchall()) == 0 assert conn.execute('SELECT * FROM metadata WHERE key = "version"' ).first().value == '2' self.mocked_settings_instance.setValue.assert_not_called()
def test_skip_db_upgrade_with_no_database(self): """ 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) mocked_upgrade = MagicMock() # WHEN: We attempt to upgrade a non-existant database upgrade_db(url, mocked_upgrade) # THEN: upgrade should NOT have been called assert mocked_upgrade.called is False, 'Database upgrade function should NOT have been called'
def test_upgrade_2_none_selected(self): """ Test that upgrade 2 completes properly when the user chooses not to use a proxy ('No') """ # GIVEN: An version 1 web bible with proxy settings # WHEN: Calling upgrade_db and the user has 'clicked' the 'No' button upgrade_db(self.db_url, upgrade) # THEN: The proxy meta data should have been removed, and the version should have been changed to version 2 self.mocked_message_box.assert_not_called() engine = create_engine(self.db_url) conn = engine.connect() assert conn.execute('SELECT * FROM metadata WHERE key = "version"' ).first().value == '2'
def test_upgrade_invalid_song_db(self): """ Test that we can upgrade an invalid song db to the current schema """ # GIVEN: A song db with invalid version invalid_db_path = os.path.join(TEST_RESOURCES_PATH, "songs", 'songs-2.2-invalid.sqlite') invalid_db_tmp_path = os.path.join(self.tmp_folder, 'songs-2.2-invalid.sqlite') shutil.copyfile(invalid_db_path, invalid_db_tmp_path) db_url = 'sqlite:///' + invalid_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 without errors self.assertEqual(updated_to_version, latest_version, 'The song DB should have been upgrade to the latest version')
def test_upgrade_old_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')
def test_upgrade_old_projector_db(self): """ Test that we can upgrade a version 1 db to the current schema """ # GIVEN: An old prjector db old_db = os.path.join(TEST_RESOURCES_PATH, "projector", TEST_DB_PJLINK1) tmp_db = os.path.join(self.tmp_folder, TEST_DB) shutil.copyfile(old_db, tmp_db) db_url = 'sqlite:///{db}'.format(db=tmp_db) # 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 assert updated_to_version == latest_version, 'The projector DB should have been upgrade to the latest version'
def test_upgrade_invalid_song_db(self): """ Test that we can upgrade an invalid song db to the current schema """ # GIVEN: A song db with invalid version invalid_db_path = os.path.join(TEST_RESOURCES_PATH, "songs", 'songs-2.2-invalid.sqlite') invalid_db_tmp_path = os.path.join(self.tmp_folder, 'songs-2.2-invalid.sqlite') shutil.copyfile(invalid_db_path, invalid_db_tmp_path) db_url = 'sqlite:///' + invalid_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 without errors self.assertEqual(updated_to_version, latest_version, 'The song DB should have been upgrade to the latest version')
def test_upgrade_old_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')