示例#1
0
    def on_import_yes_clicked_test(self, mocked_translate, mocked_question):
        """
        Test that when a song is imported and the user clicks the "yes" button, the UI goes back to the previous page
        """
        # GIVEN: A valid SongSelectForm with a mocked out QMessageBox.question() method
        mocked_translate.side_effect = lambda *args: args[1]
        mocked_question.return_value = QtGui.QMessageBox.Yes
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        mocked_song_select_importer = MagicMock()
        ssform.song_select_importer = mocked_song_select_importer
        ssform.song = None

        # WHEN: The import button is clicked, and the user clicks Yes
        with patch.object(
                ssform,
                'on_back_button_clicked') as mocked_on_back_button_clicked:
            ssform.on_import_button_clicked()

        # THEN: The on_back_button_clicked() method should have been called
        mocked_song_select_importer.save_song.assert_called_with(None)
        mocked_question.assert_called_with(
            ssform, 'Song Imported',
            'Your song has been imported, would you like to import more songs?',
            QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
            QtGui.QMessageBox.Yes)
        mocked_on_back_button_clicked.assert_called_with()
        self.assertIsNone(ssform.song)
示例#2
0
    def test_on_import_no_clicked(self, mocked_translate, mocked_question):
        """
        Test that when a song is imported and the user clicks the "no" button, the UI exits
        """
        # GIVEN: A valid SongSelectForm with a mocked out QMessageBox.question() method
        mocked_translate.side_effect = lambda *args: args[1]
        mocked_question.return_value = QtWidgets.QMessageBox.No
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        mocked_song_select_importer = MagicMock()
        ssform.song_select_importer = mocked_song_select_importer
        ssform.song = None

        # WHEN: The import button is clicked, and the user clicks Yes
        with patch.object(ssform, 'done') as mocked_done:
            ssform.on_import_button_clicked()

        # THEN: The on_back_button_clicked() method should have been called
        mocked_song_select_importer.save_song.assert_called_with(None)
        mocked_question.assert_called_with(
            ssform, 'Song Imported',
            'Your song has been imported, would you like to import more songs?',
            QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
            QtWidgets.QMessageBox.Yes)
        mocked_done.assert_called_with(QtWidgets.QDialog.Accepted)
        self.assertIsNone(ssform.song)
示例#3
0
    def test_on_search_finished(self):
        """
        Test that search fields are enabled when search is finished.
        """
        # GIVEN: A mocked SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        ssform.initialise()

        # WHEN: The search is finished
        ssform.on_search_finished()

        # THEN: The search box and search button should be enabled
        self.assertTrue(ssform.search_button.isEnabled())
        self.assertTrue(ssform.search_combobox.isEnabled())
示例#4
0
    def test_on_search_results_widget_double_clicked(self):
        """
        Test that a song is retrieved when a song in the results list is double-clicked
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        expected_song = {'title': 'Amazing Grace'}

        # WHEN: A song result is double-clicked
        with patch.object(ssform, '_view_song') as mocked_view_song:
            ssform.on_search_results_widget_double_clicked(expected_song)

        # THEN: The song is fetched and shown to the user
        mocked_view_song.assert_called_with(expected_song)
示例#5
0
    def test_on_search_button_clicked(self, MockedSearchWorker, mocked_run_thread):
        """
        Test that search fields are disabled when search button is clicked.
        """
        # GIVEN: A mocked SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        ssform.initialise()

        # WHEN: The search button is clicked
        ssform.on_search_button_clicked()

        # THEN: The search box and search button should be disabled
        assert ssform.search_button.isEnabled() is False
        assert ssform.search_combobox.isEnabled() is False
示例#6
0
    def test_update_song_progress(self):
        """
        Test the _update_song_progress() method
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())

        # WHEN: _update_song_progress() is called
        with patch.object(ssform, 'song_progress_bar') as mocked_song_progress_bar:
            mocked_song_progress_bar.value.return_value = 2
            ssform._update_song_progress()

        # THEN: The song progress bar should be updated
        mocked_song_progress_bar.setValue.assert_called_with(3)
示例#7
0
    def test_on_search_show_info(self, mocked_information):
        """
        Test that when the search_show_info signal is emitted, the on_search_show_info() method shows a dialog
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        expected_title = 'Test Title'
        expected_text = 'This is a test'

        # WHEN: on_search_show_info is called
        ssform.on_search_show_info(expected_title, expected_text)

        # THEN: An information dialog should be shown
        mocked_information.assert_called_with(ssform, expected_title, expected_text)
示例#8
0
    def test_create_form(self):
        """
        Test that we can create the SongSelect form
        """
        # GIVEN: The SongSelectForm class and a mocked db manager
        mocked_plugin = MagicMock()
        mocked_db_manager = MagicMock()

        # WHEN: We create an instance
        ssform = SongSelectForm(None, mocked_plugin, mocked_db_manager)

        # THEN: The correct properties should have been assigned
        assert mocked_plugin == ssform.plugin, 'The correct plugin should have been assigned'
        assert mocked_db_manager == ssform.db_manager, 'The correct db_manager should have been assigned'
示例#9
0
    def test_login_fails(self, mocked_translate, mocked_critical,
                         MockedSongSelectImport):
        """
        Test that when the login fails, the form returns to the correct state
        """
        # GIVEN: A valid SongSelectForm with a mocked out SongSelectImport, and a bunch of mocked out controls
        mocked_song_select_import = MagicMock()
        mocked_song_select_import.login.return_value = False
        MockedSongSelectImport.return_value = mocked_song_select_import
        mocked_translate.side_effect = lambda *args: args[1]
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        ssform.initialise()
        with patch.object(ssform, 'username_edit') as mocked_username_edit, \
                patch.object(ssform, 'password_edit') as mocked_password_edit, \
                patch.object(ssform, 'save_password_checkbox') as mocked_save_password_checkbox, \
                patch.object(ssform, 'login_button') as mocked_login_button, \
                patch.object(ssform, 'login_spacer') as mocked_login_spacer, \
                patch.object(ssform, 'login_progress_bar') as mocked_login_progress_bar, \
                patch.object(ssform.application, 'process_events') as mocked_process_events:

            # WHEN: The login button is clicked, and the login is rigged to fail
            ssform.on_login_button_clicked()

            # THEN: The right things should have happened in the right order
            expected_username_calls = [call(False), call(True)]
            expected_password_calls = [call(False), call(True)]
            expected_save_password_calls = [call(False), call(True)]
            expected_login_btn_calls = [call(False), call(True)]
            expected_login_spacer_calls = [call(False), call(True)]
            expected_login_progress_visible_calls = [call(True), call(False)]
            expected_login_progress_value_calls = [call(0), call(0)]
            assert expected_username_calls == mocked_username_edit.setEnabled.call_args_list, \
                'The username edit should be disabled then enabled'
            assert expected_password_calls == mocked_password_edit.setEnabled.call_args_list, \
                'The password edit should be disabled then enabled'
            assert expected_save_password_calls == mocked_save_password_checkbox.setEnabled.call_args_list, \
                'The save password checkbox should be disabled then enabled'
            assert expected_login_btn_calls == mocked_login_button.setEnabled.call_args_list, \
                'The login button should be disabled then enabled'
            assert expected_login_spacer_calls == mocked_login_spacer.setVisible.call_args_list, \
                'Thee login spacer should be make invisible, then visible'
            assert expected_login_progress_visible_calls == mocked_login_progress_bar.setVisible.call_args_list, \
                'Thee login progress bar should be make visible, then invisible'
            assert expected_login_progress_value_calls == mocked_login_progress_bar.setValue.call_args_list, \
                'Thee login progress bar should have the right values set'
            assert 2 == mocked_process_events.call_count, 'The process_events() method should be called twice'
            mocked_critical.assert_called_with(
                ssform, 'Error Logging In', 'There was a problem logging in, '
                'perhaps your username or password is '
                'incorrect?')
示例#10
0
    def test_on_search_results_widget_selection_changed(self):
        """
        Test that the view button is updated when the search results list is changed
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())

        # WHEN: There is at least 1 item selected
        with patch.object(ssform, 'search_results_widget') as mocked_search_results_widget, \
                patch.object(ssform, 'view_button') as mocked_view_button:
            mocked_search_results_widget.selectedItems.return_value = [1]
            ssform.on_search_results_widget_selection_changed()

        # THEN: The view button should be enabled
        mocked_view_button.setEnabled.assert_called_with(True)
示例#11
0
    def test_on_back_button_clicked(self):
        """
        Test that when the back button is clicked, the stacked widget is set back one page
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())

        # WHEN: The back button is clicked
        with patch.object(ssform, 'stacked_widget') as mocked_stacked_widget, \
                patch.object(ssform, 'search_combobox') as mocked_search_combobox:
            ssform.on_back_button_clicked()

        # THEN: The stacked widget should be set back one page
        mocked_stacked_widget.setCurrentIndex.assert_called_with(1)
        mocked_search_combobox.setFocus.assert_called_with()
示例#12
0
    def test_on_view_button_clicked(self):
        """
        Test that a song is retrieved when the view button is clicked
        """
        # GIVEN: A SongSelect form
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        expected_song = {'title': 'Amazing Grace'}

        # WHEN: A song result is double-clicked
        with patch.object(ssform, '_view_song') as mocked_view_song, \
                patch.object(ssform, 'search_results_widget') as mocked_search_results_widget:
            mocked_search_results_widget.currentItem.return_value = expected_song
            ssform.on_view_button_clicked()

        # THEN: The song is fetched and shown to the user
        mocked_view_song.assert_called_with(expected_song)
示例#13
0
    def test_on_stop_button_clicked(self, MockedSongSelectImport):
        """
        Test that the search is stopped when the stop button is clicked
        """
        # GIVEN: A mocked SongSelectImporter and a SongSelect form
        mocked_song_select_importer = MagicMock()
        MockedSongSelectImport.return_value = mocked_song_select_importer
        ssform = SongSelectForm(None, MagicMock(), MagicMock())
        ssform.initialise()

        # WHEN: The stop button is clicked
        ssform.on_stop_button_clicked()

        # THEN: The view button, search box and search button should be enabled
        mocked_song_select_importer.stop.assert_called_with()
        self.assertTrue(ssform.search_button.isEnabled())
        self.assertTrue(ssform.search_combobox.isEnabled())
示例#14
0
 def initialise(self):
     """
     Initialise the plugin
     """
     log.info('Songs Initialising')
     super(SongsPlugin, self).initialise()
     self.songselect_form = SongSelectForm(Registry().get('main_window'),
                                           self, self.manager)
     self.songselect_form.initialise()
     self.song_import_item.setVisible(True)
     self.song_export_item.setVisible(True)
     self.tools_reindex_item.setVisible(True)
     self.tools_find_duplicates.setVisible(True)
     action_list = ActionList.get_instance()
     action_list.add_action(self.song_import_item, UiStrings().Import)
     action_list.add_action(self.song_export_item, UiStrings().Export)
     action_list.add_action(self.tools_reindex_item, UiStrings().Tools)
     action_list.add_action(self.tools_find_duplicates, UiStrings().Tools)