From e9e5976d2208939742bb397b9fcf62bd67fa82c1 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Fri, 11 Mar 2016 22:56:07 +0100 Subject: [PATCH] Finished first test. --- openlp/plugins/songs/lib/importers/opspro.py | 4 +-- .../openlp_plugins/songs/test_opsproimport.py | 18 +++++++---- .../openlp_plugins/songs/test_videopsalm.py | 3 -- .../opsprosongs/You are so faithful.json | 31 +++++++++++++++++++ 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 tests/resources/opsprosongs/You are so faithful.json diff --git a/openlp/plugins/songs/lib/importers/opspro.py b/openlp/plugins/songs/lib/importers/opspro.py index 9572f8923..56463d093 100644 --- a/openlp/plugins/songs/lib/importers/opspro.py +++ b/openlp/plugins/songs/lib/importers/opspro.py @@ -159,8 +159,8 @@ class OpsProImport(SongImport): # Remove comments verse_text = re.sub('\(.*?\)\r\n', '', verse_text, flags=re.IGNORECASE) self.add_verse(verse_text, verse_def) - print(verse_def) - print(verse_text) + #print(verse_def) + #print(verse_text) self.finish() def extract_mdb_password(self): diff --git a/tests/functional/openlp_plugins/songs/test_opsproimport.py b/tests/functional/openlp_plugins/songs/test_opsproimport.py index 0eb03af9f..67b7c5959 100644 --- a/tests/functional/openlp_plugins/songs/test_opsproimport.py +++ b/tests/functional/openlp_plugins/songs/test_opsproimport.py @@ -23,6 +23,7 @@ This module contains tests for the WorshipCenter Pro song importer. """ import os +import json from unittest import TestCase, SkipTest from tests.functional import patch, MagicMock @@ -44,7 +45,6 @@ class TestRecord(object): self.Field = field self.Value = value - class TestOpsProSongImport(TestCase): """ Test the functions in the :mod:`opsproimport` module. @@ -74,7 +74,7 @@ class TestOpsProSongImport(TestCase): """ Test importing lyrics with a chorus in OPS Pro """ - # GIVEN: A mocked out SongImport class, and a mocked out "manager" + # GIVEN: A mocked out SongImport class, a mocked out "manager" and a mocked song and lyrics entry mocked_manager = MagicMock() importer = OpsProImport(mocked_manager, filenames=[]) song = MagicMock() @@ -95,7 +95,13 @@ class TestOpsProSongImport(TestCase): # WHEN: An importer object is created importer.process_song(song, lyrics, []) - # THEN: The importer object should not be None - print(importer.verses) - print(importer.verse_order_list) - self.assertIsNone(importer, 'Import should not be none') \ No newline at end of file + # THEN: The imported data should look like expected + result_file = open(os.path.join(TEST_PATH, 'You are so faithful.json'), 'rb') + result_data = json.loads(result_file.read().decode()) + self.assertListEqual(importer.verses, self._get_data(result_data, 'verses')) + self.assertListEqual(importer.verse_order_list_generated, self._get_data(result_data, 'verse_order_list')) + + def _get_data(self, data, key): + if key in data: + return data[key] + return '' diff --git a/tests/functional/openlp_plugins/songs/test_videopsalm.py b/tests/functional/openlp_plugins/songs/test_videopsalm.py index f75a67627..1bf13241d 100644 --- a/tests/functional/openlp_plugins/songs/test_videopsalm.py +++ b/tests/functional/openlp_plugins/songs/test_videopsalm.py @@ -23,11 +23,8 @@ This module contains tests for the VideoPsalm song importer. """ import os -from unittest import TestCase from tests.helpers.songfileimport import SongImportTestHelper -from openlp.core.common import Registry -from tests.functional import patch, MagicMock TEST_PATH = os.path.abspath( os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources', 'videopsalmsongs')) diff --git a/tests/resources/opsprosongs/You are so faithful.json b/tests/resources/opsprosongs/You are so faithful.json new file mode 100644 index 000000000..965d73ab8 --- /dev/null +++ b/tests/resources/opsprosongs/You are so faithful.json @@ -0,0 +1,31 @@ +{ + "title": "You are so faithful", + "verse_order_list": ["v1", "c1", "v2", "c1", "v3", "c1", "v4"], + "verses": [ + [ + "v1", + "You are so faithful\r\nso faithful, so faithful.\r\nYou are so faithful\r\nso faithful, so faithful.", + null + ], + [ + "c1", + "That's why I praise you\r\nin the morning\r\nThat's why I praise you\r\nin the noontime.\r\nThat's why I praise you\r\nin the evening\r\nThat's why I praise you\r\nall the time.", + null + ], + [ + "v2", + "You are so loving\r\nso loving, so loving.\r\nYou are so loving\r\nso loving, so loving.", + null + ], + [ + "v3", + "You are so caring\r\nso caring, so caring.\r\nYou are so caring\r\nso caring, so caring.", + null + ], + [ + "v4", + "You are so mighty\r\nso mighty, so mighty.\r\nYou are so mighty\r\nso mighty, so mighty.", + null + ] + ] +}