Tests plugin 4

This commit is contained in:
Tim Bentley 2020-03-10 16:59:25 +00:00
parent 050e49465e
commit 4ce197ecc2
14 changed files with 248 additions and 184 deletions

View File

@ -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'

View File

@ -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
"""

View File

@ -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):
class TestChordProFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'ChordProImport'
self.importer_module_name = 'chordpro'
super(TestChordProFileImport, self).__init__(*args, **kwargs)
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
self.settings.value.side_effect = lambda value: True if value == 'songs/enable chords' else 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()

View File

@ -28,12 +28,14 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'easyslides'
class TestEasySlidesFileImport(SongImportTestHelper):
def test_easyslides(mock_settings):
class TestEasySlidesFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'EasySlidesImport'
self.importer_module_name = 'easyslides'
super(TestEasySlidesFileImport, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
def test_song_import(self):
"""
@ -43,3 +45,8 @@ class TestEasySlidesFileImport(SongImportTestHelper):
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()

View File

@ -28,7 +28,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'lyrix'
class TestLyrixFileImport(SongImportTestHelper):
def test_Lyrix(mock_settings):
class TestLyrixFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'LyrixImport'
@ -45,3 +47,8 @@ class TestLyrixFileImport(SongImportTestHelper):
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()

View File

@ -29,7 +29,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'powerpraise'
class TestPowerPraiseFileImport(SongImportTestHelper):
def test_power_praise(mock_settings):
class TestPowerPraiseFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'PowerPraiseImport'
@ -44,3 +46,8 @@ class TestPowerPraiseFileImport(SongImportTestHelper):
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()

View File

@ -31,7 +31,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'presentationmanager'
class TestPresentationManagerFileImport(SongImportTestHelper):
def test_presenter_manager(mock_settings):
class TestPresentationManagerFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'PresentationManagerImport'
@ -47,3 +49,8 @@ class TestPresentationManagerFileImport(SongImportTestHelper):
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()

View File

@ -29,7 +29,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'songpro'
class TestSongProFileImport(SongImportTestHelper):
def test_song_pro(mock_settings):
class TestSongProFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SongProImport'
@ -42,3 +44,8 @@ class TestSongProFileImport(SongImportTestHelper):
"""
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()

View File

@ -33,7 +33,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'songshowplus'
class TestSongShowPlusFileImport(SongImportTestHelper):
def test_song_show_plus(mock_settings):
class TestSongShowPlusFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SongShowPlusImport'
@ -53,6 +55,11 @@ class TestSongShowPlusFileImport(SongImportTestHelper):
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):
"""

View File

@ -30,7 +30,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'sundayplus'
class TestSundayPlusFileImport(SongImportTestHelper):
def test_sunday_plus(mock_settings):
class TestSundayPlusFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'SundayPlusImport'
@ -46,3 +48,8 @@ class TestSundayPlusFileImport(SongImportTestHelper):
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()

View File

@ -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,7 +29,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'videopsalm'
class TestVideoPsalmFileImport(SongImportTestHelper):
def test_video_psalms(mock_settings):
class TestVideoPsalmFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'VideoPsalmImport'
@ -41,9 +43,15 @@ class TestVideoPsalmFileImport(SongImportTestHelper):
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
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()

View File

@ -29,7 +29,9 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'worshipassistant'
class TestWorshipAssistantFileImport(SongImportTestHelper):
def test_chordpro(mock_settings):
class TestWorshipAssistantFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'WorshipAssistantImport'
@ -45,3 +47,8 @@ class TestWorshipAssistantFileImport(SongImportTestHelper):
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()

View File

@ -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,17 +32,7 @@ from tests.utils.constants import RESOURCE_PATH
TEST_PATH = RESOURCE_PATH / 'songs' / 'zionworx'
class TestZionWorxImport(TestCase):
"""
Test the functions in the :mod:`zionworximport` module.
"""
def setUp(self):
"""
Create the registry
"""
Registry.create()
def test_create_importer(self):
def test_create_importer(registry):
"""
Test creating an instance of the ZionWorx file importer
"""
@ -59,7 +47,9 @@ class TestZionWorxImport(TestCase):
assert isinstance(importer, SongImport)
class TestZionWorxFileImport(SongImportTestHelper):
def test_zion_wrox(mock_settings):
class TestZionWorxFileImport(SongImportTestHelper):
def __init__(self, *args, **kwargs):
self.importer_class_name = 'ZionWorxImport'
@ -71,3 +61,8 @@ class TestZionWorxFileImport(SongImportTestHelper):
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()

View File

@ -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' %