From 2c6da0603b779856b1a3ae98af2af0ed94c5577b Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 16 Apr 2014 22:33:06 +0200 Subject: [PATCH] Fix tests --- openlp/plugins/songs/lib/openlyricsimport.py | 2 +- .../songs/test_openlyricsimport.py | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/songs/lib/openlyricsimport.py b/openlp/plugins/songs/lib/openlyricsimport.py index 6e6cc8efa..cdb017bae 100644 --- a/openlp/plugins/songs/lib/openlyricsimport.py +++ b/openlp/plugins/songs/lib/openlyricsimport.py @@ -71,7 +71,7 @@ class OpenLyricsImport(SongImport): # special characters in the path (see lp:757673 and lp:744337). parsed_file = etree.parse(open(file_path, 'r'), parser) xml = etree.tostring(parsed_file).decode() - return self.open_lyrics.xml_to_song(xml) + self.open_lyrics.xml_to_song(xml) except etree.XMLSyntaxError: log.exception('XML syntax error in file %s' % file_path) self.log_error(file_path, SongStrings.XMLSyntaxError) diff --git a/tests/functional/openlp_plugins/songs/test_openlyricsimport.py b/tests/functional/openlp_plugins/songs/test_openlyricsimport.py index 5465a03e4..5f005e10e 100644 --- a/tests/functional/openlp_plugins/songs/test_openlyricsimport.py +++ b/tests/functional/openlp_plugins/songs/test_openlyricsimport.py @@ -73,24 +73,22 @@ class TestOpenLyricsImport(TestCase): # THEN: The importer should be an instance of SongImport self.assertIsInstance(importer, SongImport) - @patch('openlp.plugins.songs.lib.db.Song') - @patch('openlp.plugins.songs.lib.songbeamerimport.SongImport') - def file_import_test(self, mock_songimport, mock_song): + def file_import_test(self): """ - Test the actual import of real song files and check that the imported data is correct. + Test the actual import of real song files and check that the importer is called. """ - # GIVEN: Test files with a mocked out "manager" and a mocked out "import_wizard" for song_file in SONG_TEST_DATA: mocked_manager = MagicMock() mocked_import_wizard = MagicMock() importer = OpenLyricsImport(mocked_manager, filenames=[]) importer.import_wizard = mocked_import_wizard + importer.open_lyrics = MagicMock() + importer.open_lyrics.xml_to_song = MagicMock() # WHEN: Importing each file importer.import_source = [os.path.join(TEST_PATH, song_file)] - song = importer.do_import() + importer.do_import() - # THEN: the song title should be as expected - self.assertEqual(song.title, SONG_TEST_DATA[song_file]['title'], - 'title for %s should be "%s"' % (song_file, SONG_TEST_DATA[song_file]['title'])) + # THEN: The xml_to_song() method should have been called + self.assertTrue(importer.open_lyrics.xml_to_song.called)