Example #1
0
    def invalid_import_source_test(self):
        """
        Test SongBeamerImport.do_import handles different invalid import_source values
        """
        # GIVEN: A mocked out SongImport class, and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = SongBeamerImport(mocked_manager, filenames=[])
            importer.import_wizard = mocked_import_wizard
            importer.stop_import_flag = True

            # WHEN: Import source is not a list
            for source in ['not a list', 0]:
                importer.import_source = source

                # THEN: do_import should return none and the progress bar maximum should not be set.
                self.assertIsNone(
                    importer.do_import(),
                    'do_import should return None when import_source is not a list'
                )
                self.assertEqual(
                    mocked_import_wizard.progress_bar.setMaximum.called, False,
                    'setMaxium on import_wizard.progress_bar should not have been called'
                )
Example #2
0
    def file_import_test(self):
        """
        Test the actual import of real song files and check that the imported data is correct.
        """

        # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard",
        #       and mocked out "author", "add_copyright", "add_verse", "finish" methods.
        with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
            for song_file in SONG_TEST_DATA:
                mocked_manager = MagicMock()
                mocked_import_wizard = MagicMock()
                mocked_add_verse = MagicMock()
                mocked_finish = MagicMock()
                mocked_finish.return_value = True
                importer = SongBeamerImport(mocked_manager, filenames=[])
                importer.import_wizard = mocked_import_wizard
                importer.stop_import_flag = False
                importer.add_verse = mocked_add_verse
                importer.finish = mocked_finish

                # WHEN: Importing each file
                importer.import_source = [os.path.join(TEST_PATH, song_file)]
                title = SONG_TEST_DATA[song_file]['title']
                add_verse_calls = SONG_TEST_DATA[song_file]['verses']
                song_book_name = SONG_TEST_DATA[song_file]['song_book_name']
                song_number = SONG_TEST_DATA[song_file]['song_number']
                song_authors = SONG_TEST_DATA[song_file]['authors']

                # THEN: do_import should return none, the song data should be as expected, and finish should have been
                #       called.
                self.assertIsNone(
                    importer.do_import(),
                    'do_import should return None when it has completed')
                self.assertEqual(
                    importer.title, title,
                    'title for %s should be "%s"' % (song_file, title))
                for verse_text, verse_tag in add_verse_calls:
                    mocked_add_verse.assert_any_call(verse_text, verse_tag)
                if song_book_name:
                    self.assertEqual(
                        importer.song_book_name, song_book_name,
                        'song_book_name for %s should be "%s"' %
                        (song_file, song_book_name))
                if song_number:
                    self.assertEqual(
                        importer.song_number, song_number,
                        'song_number for %s should be %s' %
                        (song_file, song_number))
                if song_authors:
                    for author in importer.authors:
                        self.assertIn(author, song_authors)
                mocked_finish.assert_called_with()
    def file_import_test(self):
        """
        Test the actual import of real song files and check that the imported data is correct.
        """

        # GIVEN: Test files with a mocked out SongImport class, a mocked out "manager", a mocked out "import_wizard",
        #       and mocked out "author", "add_copyright", "add_verse", "finish" methods.
        with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
            for song_file in SONG_TEST_DATA:
                mocked_manager = MagicMock()
                mocked_import_wizard = MagicMock()
                mocked_add_verse = MagicMock()
                mocked_finish = MagicMock()
                mocked_finish.return_value = True
                importer = SongBeamerImport(mocked_manager, filenames=[])
                importer.import_wizard = mocked_import_wizard
                importer.stop_import_flag = False
                importer.add_verse = mocked_add_verse
                importer.finish = mocked_finish

                # WHEN: Importing each file
                importer.import_source = [os.path.join(TEST_PATH, song_file)]
                title = SONG_TEST_DATA[song_file]['title']
                add_verse_calls = SONG_TEST_DATA[song_file]['verses']
                song_book_name = SONG_TEST_DATA[song_file]['song_book_name']
                song_number = SONG_TEST_DATA[song_file]['song_number']
                song_authors = SONG_TEST_DATA[song_file]['authors']

                # THEN: do_import should return none, the song data should be as expected, and finish should have been
                #       called.
                self.assertIsNone(importer.do_import(), 'do_import should return None when it has completed')
                self.assertEqual(importer.title, title, 'title for %s should be "%s"' % (song_file, title))
                for verse_text, verse_tag in add_verse_calls:
                    mocked_add_verse.assert_any_call(verse_text, verse_tag)
                if song_book_name:
                    self.assertEqual(importer.song_book_name, song_book_name,
                                     'song_book_name for %s should be "%s"' % (song_file, song_book_name))
                if song_number:
                    self.assertEqual(importer.song_number, song_number,
                                     'song_number for %s should be %s' % (song_file, song_number))
                if song_authors:
                    for author in importer.authors:
                        self.assertIn(author, song_authors)
                mocked_finish.assert_called_with()
    def valid_import_source_test(self):
        """
        Test SongBeamerImport.do_import handles different invalid import_source values
        """
        # GIVEN: A mocked out SongImport class, and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = SongBeamerImport(mocked_manager, filenames=[])
            importer.import_wizard = mocked_import_wizard
            importer.stop_import_flag = True

            # WHEN: Import source is a list
            importer.import_source = ['List', 'of', 'files']

            # THEN: do_import should return none and the progress bar setMaximum should be called with the length of
            #       import_source.
            self.assertIsNone(importer.do_import(),
                              'do_import should return None when import_source is a list and stop_import_flag is True')
            mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
    def invalid_import_source_test(self):
        """
        Test SongBeamerImport.do_import handles different invalid import_source values
        """
        # GIVEN: A mocked out SongImport class, and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = SongBeamerImport(mocked_manager, filenames=[])
            importer.import_wizard = mocked_import_wizard
            importer.stop_import_flag = True

            # WHEN: Import source is not a list
            for source in ['not a list', 0]:
                importer.import_source = source

                # THEN: do_import should return none and the progress bar maximum should not be set.
                self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is not a list')
                self.assertEqual(mocked_import_wizard.progress_bar.setMaximum.called, False,
                                 'setMaxium on import_wizard.progress_bar should not have been called')
Example #6
0
    def valid_import_source_test(self):
        """
        Test SongBeamerImport.do_import handles different invalid import_source values
        """
        # GIVEN: A mocked out SongImport class, and a mocked out "manager"
        with patch('openlp.plugins.songs.lib.importers.songbeamer.SongImport'):
            mocked_manager = MagicMock()
            mocked_import_wizard = MagicMock()
            importer = SongBeamerImport(mocked_manager, filenames=[])
            importer.import_wizard = mocked_import_wizard
            importer.stop_import_flag = True

            # WHEN: Import source is a list
            importer.import_source = ['List', 'of', 'files']

            # THEN: do_import should return none and the progress bar setMaximum should be called with the length of
            #       import_source.
            self.assertIsNone(
                importer.do_import(),
                'do_import should return None when import_source is a list and stop_import_flag is True'
            )
            mocked_import_wizard.progress_bar.setMaximum.assert_called_with(
                len(importer.import_source))