diff --git a/tests/functional/openlp_plugins/presentations/test_maclocontroller.py b/tests/functional/openlp_plugins/presentations/test_maclocontroller.py index f07c82d8b..39d6de492 100644 --- a/tests/functional/openlp_plugins/presentations/test_maclocontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_maclocontroller.py @@ -26,9 +26,10 @@ from tempfile import mkdtemp from unittest import TestCase, skipIf, SkipTest from unittest.mock import MagicMock, patch, call -from openlp.core.common.registry import Registry from openlp.core.common import is_macosx from openlp.core.common.path import Path +from openlp.core.common.registry import Registry +from openlp.core.common.settings import Settings from openlp.plugins.presentations.lib.maclocontroller import MacLOController, MacLODocument from tests.helpers.testmixin import TestMixin @@ -55,7 +56,7 @@ class TestMacLOController(TestCase, TestMixin): Registry.create() self.setup_application() self.build_settings() - Registry().register('settings', self.settings) + Registry().register('settings', Settings()) self.mock_plugin = MagicMock() self.temp_folder = mkdtemp() self.mock_plugin.settings_section = self.temp_folder @@ -159,6 +160,8 @@ class TestMacLODocument(TestCase): Test the MacLODocument Class """ def setUp(self): + Registry().create() + Registry().register('settings', Settings()) mocked_plugin = MagicMock() mocked_plugin.settings_section = 'presentations' self.file_name = Path(TEST_RESOURCES_PATH) / 'presentations' / 'test.odp' diff --git a/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py b/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py index 5a9c9a8cd..da7afde5a 100644 --- a/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py +++ b/tests/functional/openlp_plugins/presentations/test_powerpointcontroller.py @@ -55,7 +55,7 @@ def test_constructor(settings, mock_plugin): assert 'Powerpoint' == controller.name, 'The name of the presentation controller should be correct' -def test_show_error_msg(): +def test_show_error_msg(get_thumbnail_folder): """ Test the PowerpointDocument.show_error_msg() method gets called on com exception """ diff --git a/tests/functional/openlp_plugins/songs/test_chordproimport.py b/tests/functional/openlp_plugins/songs/test_chordproimport.py index 023ebf687..989a9a173 100644 --- a/tests/functional/openlp_plugins/songs/test_chordproimport.py +++ b/tests/functional/openlp_plugins/songs/test_chordproimport.py @@ -21,6 +21,7 @@ """ This module contains tests for the OpenSong song importer. """ +from openlp.core.common.registry import Registry from tests.helpers.songfileimport import SongImportTestHelper from tests.utils.constants import RESOURCE_PATH @@ -28,19 +29,27 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'chordpro' -class TestChordProFileImport(SongImportTestHelper): +def test_chordpro(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'ChordProImport' - self.importer_module_name = 'chordpro' - super(TestChordProFileImport, self).__init__(*args, **kwargs) + class TestChordProFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an ChordPro file works correctly on various files - """ - # Mock out the settings - always return False - self.settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False - # Do the test import - self.file_import([TEST_PATH / 'swing-low.chordpro'], - self.load_external_result_data(TEST_PATH / 'swing-low.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'ChordProImport' + self.importer_module_name = 'chordpro' + super().__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an ChordPro file works correctly on various files + """ + # Mock out the settings - always return False + Registry().get('settings').value.side_effect = lambda value: True \ + if value == 'songs/enable chords' else False + # Do the test import + self.file_import([TEST_PATH / 'swing-low.chordpro'], + self.load_external_result_data(TEST_PATH / 'swing-low.json')) + + test_file_import = TestChordProFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_easyslidesimport.py b/tests/functional/openlp_plugins/songs/test_easyslidesimport.py index e41e82784..417776d8e 100644 --- a/tests/functional/openlp_plugins/songs/test_easyslidesimport.py +++ b/tests/functional/openlp_plugins/songs/test_easyslidesimport.py @@ -28,18 +28,25 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'easyslides' -class TestEasySlidesFileImport(SongImportTestHelper): +def test_easyslides(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'EasySlidesImport' - self.importer_module_name = 'easyslides' - super(TestEasySlidesFileImport, self).__init__(*args, **kwargs) + class TestEasySlidesFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an EasySlides file works correctly on various files - """ - self.file_import(TEST_PATH / 'amazing-grace.xml', - self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) - self.file_import(TEST_PATH / 'Export_2017-01-12_BB.xml', - self.load_external_result_data(TEST_PATH / 'Export_2017-01-12_BB.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'EasySlidesImport' + self.importer_module_name = 'easyslides' + super().__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an EasySlides file works correctly on various files + """ + self.file_import(TEST_PATH / 'amazing-grace.xml', + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + self.file_import(TEST_PATH / 'Export_2017-01-12_BB.xml', + self.load_external_result_data(TEST_PATH / 'Export_2017-01-12_BB.json')) + + test_file_import = TestEasySlidesFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_lyriximport.py b/tests/functional/openlp_plugins/songs/test_lyriximport.py index f1bc912ba..4c30de506 100644 --- a/tests/functional/openlp_plugins/songs/test_lyriximport.py +++ b/tests/functional/openlp_plugins/songs/test_lyriximport.py @@ -28,20 +28,27 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'lyrix' -class TestLyrixFileImport(SongImportTestHelper): +def test_Lyrix(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'LyrixImport' - self.importer_module_name = 'lyrix' - super(TestLyrixFileImport, self).__init__(*args, **kwargs) + class TestLyrixFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an LyriX file works correctly on various files - """ - self.file_import([TEST_PATH / 'A06.TXT'], - self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) - self.file_import([TEST_PATH / 'A002.TXT'], - self.load_external_result_data(TEST_PATH / 'Amazing Grace2.json')) - self.file_import([TEST_PATH / 'AO05.TXT'], - self.load_external_result_data(TEST_PATH / 'in die regterhand.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'LyrixImport' + self.importer_module_name = 'lyrix' + super(TestLyrixFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an LyriX file works correctly on various files + """ + self.file_import([TEST_PATH / 'A06.TXT'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + self.file_import([TEST_PATH / 'A002.TXT'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace2.json')) + self.file_import([TEST_PATH / 'AO05.TXT'], + self.load_external_result_data(TEST_PATH / 'in die regterhand.json')) + + test_file_import = TestLyrixFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py b/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py index cd91fe993..667150727 100644 --- a/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py +++ b/tests/functional/openlp_plugins/songs/test_powerpraiseimport.py @@ -29,18 +29,25 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'powerpraise' -class TestPowerPraiseFileImport(SongImportTestHelper): +def test_power_praise(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'PowerPraiseImport' - self.importer_module_name = 'powerpraise' - super(TestPowerPraiseFileImport, self).__init__(*args, **kwargs) + class TestPowerPraiseFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading a PowerPraise file works correctly - """ - self.file_import([TEST_PATH / 'Naher, mein Gott zu Dir.ppl'], - self.load_external_result_data(TEST_PATH / 'Naher, mein Gott zu Dir.json')) - self.file_import([TEST_PATH / 'You are so faithful.ppl'], - self.load_external_result_data(TEST_PATH / 'You are so faithful.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'PowerPraiseImport' + self.importer_module_name = 'powerpraise' + super(TestPowerPraiseFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading a PowerPraise file works correctly + """ + self.file_import([TEST_PATH / 'Naher, mein Gott zu Dir.ppl'], + self.load_external_result_data(TEST_PATH / 'Naher, mein Gott zu Dir.json')) + self.file_import([TEST_PATH / 'You are so faithful.ppl'], + self.load_external_result_data(TEST_PATH / 'You are so faithful.json')) + + test_file_import = TestPowerPraiseFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py b/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py index 492bebbd2..f8e1ea7cf 100644 --- a/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py +++ b/tests/functional/openlp_plugins/songs/test_presentationmanagerimport.py @@ -31,19 +31,26 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'presentationmanager' -class TestPresentationManagerFileImport(SongImportTestHelper): +def test_presenter_manager(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'PresentationManagerImport' - self.importer_module_name = 'presentationmanager' - super(TestPresentationManagerFileImport, self).__init__(*args, **kwargs) + class TestPresentationManagerFileImport(SongImportTestHelper): - @skipIf(is_macosx(), 'This test fails for an undetermined reason on macOS') - def test_song_import(self): - """ - Test that loading a PresentationManager file works correctly - """ - self.file_import([TEST_PATH / 'Great Is Thy Faithfulness.sng'], - self.load_external_result_data(TEST_PATH / 'Great Is Thy Faithfulness.json')) - self.file_import([TEST_PATH / 'Amazing Grace.sng'], - self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'PresentationManagerImport' + self.importer_module_name = 'presentationmanager' + super(TestPresentationManagerFileImport, self).__init__(*args, **kwargs) + + @skipIf(is_macosx(), 'This test fails for an undetermined reason on macOS') + def test_song_import(self): + """ + Test that loading a PresentationManager file works correctly + """ + self.file_import([TEST_PATH / 'Great Is Thy Faithfulness.sng'], + self.load_external_result_data(TEST_PATH / 'Great Is Thy Faithfulness.json')) + self.file_import([TEST_PATH / 'Amazing Grace.sng'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + + test_file_import = TestPresentationManagerFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_songproimport.py b/tests/functional/openlp_plugins/songs/test_songproimport.py index 302c65ed7..1f9035237 100644 --- a/tests/functional/openlp_plugins/songs/test_songproimport.py +++ b/tests/functional/openlp_plugins/songs/test_songproimport.py @@ -29,16 +29,23 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'songpro' -class TestSongProFileImport(SongImportTestHelper): +def test_song_pro(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'SongProImport' - self.importer_module_name = 'songpro' - super(TestSongProFileImport, self).__init__(*args, **kwargs) + class TestSongProFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an SongPro file works correctly - """ - self.file_import(TEST_PATH / 'amazing-grace.txt', - self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'SongProImport' + self.importer_module_name = 'songpro' + super(TestSongProFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an SongPro file works correctly + """ + self.file_import(TEST_PATH / 'amazing-grace.txt', + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + + test_file_import = TestSongProFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py index b2785d032..3d67f1ca7 100644 --- a/tests/functional/openlp_plugins/songs/test_songshowplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_songshowplusimport.py @@ -33,25 +33,32 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'songshowplus' -class TestSongShowPlusFileImport(SongImportTestHelper): +def test_song_show_plus(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'SongShowPlusImport' - self.importer_module_name = 'songshowplus' - super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs) + class TestSongShowPlusFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading a SongShow Plus file works correctly on various files - """ - self.file_import([TEST_PATH / 'Amazing Grace.sbsong'], - self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) - self.file_import([TEST_PATH / 'Beautiful Garden Of Prayer.sbsong'], - self.load_external_result_data(TEST_PATH / 'Beautiful Garden Of Prayer.json')) - self.file_import([TEST_PATH / 'a mighty fortress is our god.sbsong'], - self.load_external_result_data(TEST_PATH / 'a mighty fortress is our god.json')) - self.file_import([TEST_PATH / 'cleanse-me.sbsong'], - self.load_external_result_data(TEST_PATH / 'cleanse-me.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'SongShowPlusImport' + self.importer_module_name = 'songshowplus' + super(TestSongShowPlusFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading a SongShow Plus file works correctly on various files + """ + self.file_import([TEST_PATH / 'Amazing Grace.sbsong'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + self.file_import([TEST_PATH / 'Beautiful Garden Of Prayer.sbsong'], + self.load_external_result_data(TEST_PATH / 'Beautiful Garden Of Prayer.json')) + self.file_import([TEST_PATH / 'a mighty fortress is our god.sbsong'], + self.load_external_result_data(TEST_PATH / 'a mighty fortress is our god.json')) + self.file_import([TEST_PATH / 'cleanse-me.sbsong'], + self.load_external_result_data(TEST_PATH / 'cleanse-me.json')) + + test_file_import = TestSongShowPlusFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() def test_create_importer(registry): diff --git a/tests/functional/openlp_plugins/songs/test_sundayplusimport.py b/tests/functional/openlp_plugins/songs/test_sundayplusimport.py index 9d74f6494..1248c3957 100644 --- a/tests/functional/openlp_plugins/songs/test_sundayplusimport.py +++ b/tests/functional/openlp_plugins/songs/test_sundayplusimport.py @@ -30,19 +30,26 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'sundayplus' -class TestSundayPlusFileImport(SongImportTestHelper): +def test_sunday_plus(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'SundayPlusImport' - self.importer_module_name = 'sundayplus' - super(TestSundayPlusFileImport, self).__init__(*args, **kwargs) + class TestSundayPlusFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an SundayPlus file works correctly on various files - """ - with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ - mocked_retrieve_windows_encoding: - mocked_retrieve_windows_encoding.return_value = 'cp1252' - self.file_import([TEST_PATH / 'Amazing Grace.ptf'], - self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'SundayPlusImport' + self.importer_module_name = 'sundayplus' + super(TestSundayPlusFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an SundayPlus file works correctly on various files + """ + with patch('openlp.plugins.songs.lib.importers.sundayplus.retrieve_windows_encoding') as \ + mocked_retrieve_windows_encoding: + mocked_retrieve_windows_encoding.return_value = 'cp1252' + self.file_import([TEST_PATH / 'Amazing Grace.ptf'], + self.load_external_result_data(TEST_PATH / 'Amazing Grace.json')) + + test_file_import = TestSundayPlusFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_videopsalm.py b/tests/functional/openlp_plugins/songs/test_videopsalm.py index af138f2a1..f4bd4195e 100644 --- a/tests/functional/openlp_plugins/songs/test_videopsalm.py +++ b/tests/functional/openlp_plugins/songs/test_videopsalm.py @@ -21,7 +21,7 @@ """ This module contains tests for the VideoPsalm song importer. """ - +from openlp.core.common.registry import Registry from tests.helpers.songfileimport import SongImportTestHelper from tests.utils.constants import RESOURCE_PATH @@ -29,21 +29,29 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'videopsalm' -class TestVideoPsalmFileImport(SongImportTestHelper): +def test_video_psalms(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'VideoPsalmImport' - self.importer_module_name = 'videopsalm' - super(TestVideoPsalmFileImport, self).__init__(*args, **kwargs) + class TestVideoPsalmFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an VideoPsalm file works correctly on various files - """ - # Mock out the settings - always return False - self.settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else False - # Do the test import - self.file_import(TEST_PATH / 'videopsalm-as-safe-a-stronghold.json', - self.load_external_result_data(TEST_PATH / 'as-safe-a-stronghold.json')) - self.file_import(TEST_PATH / 'videopsalm-as-safe-a-stronghold2.json', - self.load_external_result_data(TEST_PATH / 'as-safe-a-stronghold2.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'VideoPsalmImport' + self.importer_module_name = 'videopsalm' + super(TestVideoPsalmFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an VideoPsalm file works correctly on various files + """ + # Mock out the settings - always return False + Registry().get('settings').value.side_effect = lambda value: True \ + if value == 'songs/enable chords' else False + # Do the test import + self.file_import(TEST_PATH / 'videopsalm-as-safe-a-stronghold.json', + self.load_external_result_data(TEST_PATH / 'as-safe-a-stronghold.json')) + self.file_import(TEST_PATH / 'videopsalm-as-safe-a-stronghold2.json', + self.load_external_result_data(TEST_PATH / 'as-safe-a-stronghold2.json')) + + test_file_import = TestVideoPsalmFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py b/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py index 75d95c8ff..6c2da532d 100644 --- a/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py +++ b/tests/functional/openlp_plugins/songs/test_worshipassistantimport.py @@ -29,19 +29,26 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'worshipassistant' -class TestWorshipAssistantFileImport(SongImportTestHelper): +def test_chordpro(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'WorshipAssistantImport' - self.importer_module_name = 'worshipassistant' - super(TestWorshipAssistantFileImport, self).__init__(*args, **kwargs) + class TestWorshipAssistantFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an Worship Assistant file works correctly - """ - self.file_import(TEST_PATH / 'du_herr.csv', self.load_external_result_data(TEST_PATH / 'du_herr.json')) - self.file_import(TEST_PATH / 'would_you_be_free.csv', - self.load_external_result_data(TEST_PATH / 'would_you_be_free.json')) - self.file_import(TEST_PATH / 'would_you_be_free2.csv', - self.load_external_result_data(TEST_PATH / 'would_you_be_free.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'WorshipAssistantImport' + self.importer_module_name = 'worshipassistant' + super(TestWorshipAssistantFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an Worship Assistant file works correctly + """ + self.file_import(TEST_PATH / 'du_herr.csv', self.load_external_result_data(TEST_PATH / 'du_herr.json')) + self.file_import(TEST_PATH / 'would_you_be_free.csv', + self.load_external_result_data(TEST_PATH / 'would_you_be_free.json')) + self.file_import(TEST_PATH / 'would_you_be_free2.csv', + self.load_external_result_data(TEST_PATH / 'would_you_be_free.json')) + + test_file_import = TestWorshipAssistantFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/functional/openlp_plugins/songs/test_zionworximport.py b/tests/functional/openlp_plugins/songs/test_zionworximport.py index 84137f7a2..a25720049 100644 --- a/tests/functional/openlp_plugins/songs/test_zionworximport.py +++ b/tests/functional/openlp_plugins/songs/test_zionworximport.py @@ -21,10 +21,8 @@ """ This module contains tests for the ZionWorx song importer. """ -from unittest import TestCase from unittest.mock import MagicMock, patch -from openlp.core.common.registry import Registry from openlp.plugins.songs.lib.importers.songimport import SongImport from openlp.plugins.songs.lib.importers.zionworx import ZionWorxImport from tests.helpers.songfileimport import SongImportTestHelper @@ -34,40 +32,37 @@ from tests.utils.constants import RESOURCE_PATH TEST_PATH = RESOURCE_PATH / 'songs' / 'zionworx' -class TestZionWorxImport(TestCase): +def test_create_importer(registry): """ - Test the functions in the :mod:`zionworximport` module. + Test creating an instance of the ZionWorx file importer """ - def setUp(self): - """ - Create the registry - """ - Registry.create() + # GIVEN: A mocked out SongImport class, and a mocked out "manager" + with patch('openlp.plugins.songs.lib.importers.zionworx.SongImport'): + mocked_manager = MagicMock() - def test_create_importer(self): - """ - Test creating an instance of the ZionWorx file importer - """ - # GIVEN: A mocked out SongImport class, and a mocked out "manager" - with patch('openlp.plugins.songs.lib.importers.zionworx.SongImport'): - mocked_manager = MagicMock() + # WHEN: An importer object is created + importer = ZionWorxImport(mocked_manager, file_paths=[]) - # WHEN: An importer object is created - importer = ZionWorxImport(mocked_manager, file_paths=[]) - - # THEN: The importer should be an instance of SongImport - assert isinstance(importer, SongImport) + # THEN: The importer should be an instance of SongImport + assert isinstance(importer, SongImport) -class TestZionWorxFileImport(SongImportTestHelper): +def test_zion_wrox(mock_settings): - def __init__(self, *args, **kwargs): - self.importer_class_name = 'ZionWorxImport' - self.importer_module_name = 'zionworx' - super(TestZionWorxFileImport, self).__init__(*args, **kwargs) + class TestZionWorxFileImport(SongImportTestHelper): - def test_song_import(self): - """ - Test that loading an ZionWorx file works correctly on various files - """ - self.file_import(TEST_PATH / 'zionworx.csv', self.load_external_result_data(TEST_PATH / 'zionworx.json')) + def __init__(self, *args, **kwargs): + self.importer_class_name = 'ZionWorxImport' + self.importer_module_name = 'zionworx' + super(TestZionWorxFileImport, self).__init__(*args, **kwargs) + + def test_song_import(self): + """ + Test that loading an ZionWorx file works correctly on various files + """ + self.file_import(TEST_PATH / 'zionworx.csv', self.load_external_result_data(TEST_PATH / 'zionworx.json')) + + test_file_import = TestZionWorxFileImport() + test_file_import.setUp() + test_file_import.test_song_import() + test_file_import.tearDown() diff --git a/tests/helpers/songfileimport.py b/tests/helpers/songfileimport.py index cdf64ee30..11c74d568 100644 --- a/tests/helpers/songfileimport.py +++ b/tests/helpers/songfileimport.py @@ -24,16 +24,12 @@ song files from third party applications. """ import json import logging -from unittest import TestCase from unittest.mock import MagicMock, call, patch -from openlp.core.common.registry import Registry - - log = logging.getLogger(__name__) -class SongImportTestHelper(TestCase): +class SongImportTestHelper(object): """ This class is designed to be a helper class to reduce repetition when testing the import of song files. """ @@ -47,9 +43,6 @@ class SongImportTestHelper(TestCase): """ Patch and set up the mocks required. """ - Registry.create() - Registry().register('settings', MagicMock()) - self.settings = Registry().get('settings') self.add_copyright_patcher = patch('openlp.plugins.songs.lib.importers.%s.%s.add_copyright' % (self.importer_module_name, self.importer_class_name)) self.add_verse_patcher = patch('openlp.plugins.songs.lib.importers.%s.%s.add_verse' %