def export_same_filename_test(self):
        """
        Test that files is not overwritten if songs has same title and author
        """
        # GIVEN: A mocked song_to_xml, 2 mocked songs, a mocked application and an OpenLyricsExport instance
        with patch('openlp.plugins.songs.lib.openlyricsexport.OpenLyrics.song_to_xml') as mocked_song_to_xml:
            mocked_song_to_xml.return_value = '<?xml version="1.0" encoding="UTF-8"?>\n<empty/>'
            author = MagicMock()
            author.display_name = 'Test Author'
            song = MagicMock()
            song.authors = [author]
            song.title = 'Test Title'
            parent = MagicMock()
            parent.stop_export_flag = False
            mocked_application_object = MagicMock()
            Registry().register('application', mocked_application_object)
            ol_export = OpenLyricsExport(parent, [song, song], self.temp_folder)

            # WHEN: Doing the export
            ol_export.do_export()

            # THEN: The exporter should have created 2 files
            self.assertTrue(os.path.exists(os.path.join(self.temp_folder,
                                                        '%s (%s).xml' % (song.title, author.display_name))))
            self.assertTrue(os.path.exists(os.path.join(self.temp_folder,
                                                        '%s (%s)-1.xml' % (song.title, author.display_name))))
Esempio n. 2
0
 def perform_wizard(self):
     """
     Perform the actual export. This creates an *openlyricsexport* instance and calls the *do_export* method.
     """
     songs = [
         song.data(QtCore.Qt.UserRole)
         for song in find_list_widget_items(self.selected_list_widget)
     ]
     exporter = OpenLyricsExport(self, songs,
                                 self.output_directory_path_edit.path)
     try:
         if exporter.do_export():
             self.progress_label.setText(
                 translate(
                     'SongsPlugin.SongExportForm',
                     'Finished export. To import these files use the <strong>OpenLyrics</strong> importer.'
                 ))
         else:
             self.progress_label.setText(
                 translate('SongsPlugin.SongExportForm',
                           'Your song export failed.'))
     except OSError as ose:
         self.progress_label.setText(
             translate(
                 'SongsPlugin.SongExportForm',
                 'Your song export failed because this '
                 'error occurred: {error}').format(error=ose.strerror))
Esempio n. 3
0
    def export_same_filename_test(self):
        """
        Test that files is not overwritten if songs has same title and author
        """
        # GIVEN: A mocked song_to_xml, 2 mocked songs, a mocked application and an OpenLyricsExport instance
        with patch(
                'openlp.plugins.songs.lib.openlyricsexport.OpenLyrics.song_to_xml'
        ) as mocked_song_to_xml:
            mocked_song_to_xml.return_value = '<?xml version="1.0" encoding="UTF-8"?>\n<empty/>'
            author = MagicMock()
            author.display_name = 'Test Author'
            song = MagicMock()
            song.authors = [author]
            song.title = 'Test Title'
            parent = MagicMock()
            parent.stop_export_flag = False
            mocked_application_object = MagicMock()
            Registry().register('application', mocked_application_object)
            ol_export = OpenLyricsExport(parent, [song, song],
                                         self.temp_folder)

            # WHEN: Doing the export
            ol_export.do_export()

            # THEN: The exporter should have created 2 files
            self.assertTrue(
                os.path.exists(
                    os.path.join(
                        self.temp_folder,
                        '%s (%s).xml' % (song.title, author.display_name))))
            self.assertTrue(
                os.path.exists(
                    os.path.join(
                        self.temp_folder,
                        '%s (%s)-1.xml' % (song.title, author.display_name))))
Esempio n. 4
0
 def performWizard(self):
     """
     Perform the actual export. This creates an *openlyricsexport* instance
     and calls the *do_export* method.
     """
     songs = [
         song.data(QtCore.Qt.UserRole)
         for song in self._findListWidgetItems(self.selectedListWidget)
     ]
     exporter = OpenLyricsExport(self, songs, self.directoryLineEdit.text())
     if exporter.do_export():
         self.progressLabel.setText(translate('SongsPlugin.SongExportForm',
                 'Finished export. To import these files use the <strong>OpenLyrics</strong> importer.'))
     else:
         self.progressLabel.setText(translate('SongsPlugin.SongExportForm', 'Your song export failed.'))
Esempio n. 5
0
 def perform_wizard(self):
     """
     Perform the actual export. This creates an *openlyricsexport* instance and calls the *do_export* method.
     """
     songs = [
         song.data(QtCore.Qt.UserRole)
         for song in self._find_list_widget_items(self.selected_list_widget)
     ]
     exporter = OpenLyricsExport(self, songs, self.directory_line_edit.text())
     try:
         if exporter.do_export():
             self.progress_label.setText(
                 translate('SongsPlugin.SongExportForm',
                           'Finished export. To import these files use the <strong>OpenLyrics</strong> importer.'))
         else:
             self.progress_label.setText(translate('SongsPlugin.SongExportForm', 'Your song export failed.'))
     except OSError as ose:
         self.progress_label.setText(translate('SongsPlugin.SongExportForm', 'Your song export failed because this '
                                               'error occurred: %s') % ose.strerror)
Esempio n. 6
0
        def test_export_sort_of_authers_filename(self):
            """
            Test that files is not overwritten if songs has same title and author
            """
            # GIVEN: A mocked song_to_xml, 1 mocked songs, a mocked application and an OpenLyricsExport instance
            with patch('openlp.plugins.songs.lib.openlyricsexport.OpenLyrics.song_to_xml') as mocked_song_to_xml:
                mocked_song_to_xml.return_value = '<?xml version="1.0" encoding="UTF-8"?>\n<empty/>'
                authorA = MagicMock()
                authorA.display_name = 'a Author'
                authorB = MagicMock()
                authorB.display_name = 'b Author'
                songA = MagicMock()
                songA.authors = [authorA, authorB]
                songA.title = 'Test Title'
                songB = MagicMock()
                songB.authors = [authorB, authorA]
                songB.title = 'Test Title'

                parent = MagicMock()
                parent.stop_export_flag = False
                mocked_application_object = MagicMock()
                Registry().register('application', mocked_application_object)
                ol_export = OpenLyricsExport(parent, [songA, songB], self.temp_folder)

                # WHEN: Doing the export
                ol_export.do_export()

                # THEN: The exporter orders authers
                assert (self.temp_folder / '{title} ({display_name}).xml'.format(
                    title=song.title,
                    display_name=", ".join([authorA.display_name, authorB.display_name])
                )).exists() is True
                assert (self.temp_folder / '{title} ({display_name})-1.xml'.format(
                    title=song.title,
                    display_name=", ".join([authorA.display_name, authorB.display_name])
                )).exists() is True