コード例 #1
0
ファイル: test_mediaitem.py プロジェクト: jkunle/paul
 def setUp(self):
     """
     Set up the components need for all tests.
     """
     with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\
             patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'):
         self.media_item = BibleMediaItem(None, MagicMock())
     self.setup_application()
コード例 #2
0
 def setUp(self):
     """
     Set up the components need for all tests.
     """
     with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\
             patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'):
         self.media_item = BibleMediaItem(None, MagicMock())
     self.setup_application()
     self.mocked_main_window = MagicMock()
     Registry.create()
     Registry().register('main_window', self.mocked_main_window)
コード例 #3
0
 def setUp(self):
     """
     Set up the components need for all tests.
     """
     with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\
             patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'):
         self.media_item = BibleMediaItem(None, MagicMock())
     self.setup_application()
コード例 #4
0
ファイル: test_selectplanform.py プロジェクト: ipic/projecao
 def test_less_mocking_service_refreshed_when_refresh_button_clicked_test(
         self):
     """
     Test that a service is refreshed when the "Refresh Service" button is clicked
     """
     # GIVEN: An SelectPlanForm instance with airplane mode enabled, resources available,
     # mocked out "on_new_service_clicked"
     with patch('PyQt5.QtWidgets.QDialog.exec'), \
             patch('openlp.plugins.planningcenter.forms.selectplanform.date') as mock_date:
         # need to always return 9/29/2019 for date.today()
         mock_date.today.return_value = date(2019, 9, 29)
         mock_date.side_effect = lambda *args, **kw: date(*args, **kw)
         # init ServiceManager
         Registry().register('plugin_manager', MagicMock())
         Registry().register('application', MagicMock())
         Registry().register('renderer', MagicMock())
         self.service_manager = ServiceManager()
         self.service_manager.setup_ui(self.service_manager)
         # init songs plugin
         with patch('openlp.plugins.songs.lib.mediaitem.EditSongForm'), \
                 patch('openlp.plugins.custom.lib.mediaitem.EditCustomForm'), \
                 patch('openlp.core.lib.mediamanageritem.create_widget_action'), \
                 patch('openlp.core.widgets.toolbar.create_widget_action'):
             # init songs plugin
             songs_plugin = SongsPlugin()
             song_media_item = SongMediaItem(None, songs_plugin)
             song_media_item.search_text_edit = MagicMock()
             song_media_item.settings_section = 'songs'
             song_media_item.initialise()
             # init custom plugin
             custom_plugin = CustomPlugin()
             CustomMediaItem(None, custom_plugin)
             # init bible plugin
             bible_plugin = BiblePlugin()
             bible_media_item = BibleMediaItem(None, bible_plugin)
             bible_media_item.build_display_results = MagicMock()
             self.form.exec()
         # WHEN:
         # The Service Type combo is set to index 1 and "Import New" button is clicked
         self.form.service_type_combo_box.setCurrentIndex(1)
         QtTest.QTest.mouseClick(self.form.import_as_new_button,
                                 QtCore.Qt.LeftButton)
         # make changes to the now imported service items
         # first, for serviceitem[0] update last_updated in xml_string and change "sweet" to "sublime"
         old_match = re.search(
             'modifiedDate="(.+?)Z*"', self.service_manager.service_items[0]
             ['service_item'].xml_version)
         old_string = old_match.group(1)
         now_string = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
         self.service_manager.service_items[0]['service_item'].xml_version = \
             self.service_manager.service_items[0]['service_item'].xml_version.replace(old_string, now_string)
         self.service_manager.service_items[0]['service_item'].xml_version = \
             self.service_manager.service_items[0]['service_item'].xml_version.replace("sweet", "sublime")
         # second, add the word modified to the slide text for serviceitem[1]
         self.service_manager.service_items[1]['service_item'].slides[0]['text'] = \
             self.service_manager.service_items[1]['service_item'].slides[0]['text'].replace("Test", "Modified Test")
         # third, delete serviceitems[2] and serviceitem[3]
         del self.service_manager.service_items[3]
         del self.service_manager.service_items[2]
         # last, draw the form again and request refresh
         self.form.exec()
         self.form.service_type_combo_box.setCurrentIndex(1)
         QtTest.QTest.mouseClick(self.form.update_existing_button,
                                 QtCore.Qt.LeftButton)
     # THEN:
     # There should be 4 service items added
     self.assertEqual(len(self.service_manager.service_items), 5,
                      '5 items should be in the ServiceManager')
     # Amazon Grace should still include sublime
     self.assertTrue('sublime' in self.service_manager.service_items[0]
                     ['service_item'].xml_version)
     # Slides in service_item[1] should still contain the word "Modified"
     self.assertTrue('Modified' in self.service_manager.service_items[1]
                     ['service_item'].slides[0]['text'])
コード例 #5
0
class TestMediaItem(TestCase, TestMixin):
    """
    Test the bible mediaitem methods.
    """

    def setUp(self):
        """
        Set up the components need for all tests.
        """
        with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\
                patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'):
            self.media_item = BibleMediaItem(None, MagicMock())
        self.setup_application()
        self.mocked_main_window = MagicMock()
        Registry.create()
        Registry().register('main_window', self.mocked_main_window)

    def test_display_results_no_results(self):
        """
        Test the display_results method when called with a single bible, returning no results
        """

        # GIVEN: A mocked build_display_results which returns an empty list
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results with a single bible version
            self.media_item.display_results('NIV')

            # THEN: No items should be added to the list, and select all should have been called.
            mocked_build_display_results.assert_called_once_with('NIV', '', 'results')
            self.assertFalse(mocked_list_view.addItem.called)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})

    def test_display_results_two_bibles_no_results(self):
        """
        Test the display_results method when called with two bibles, returning no results
        """

        # GIVEN: A mocked build_display_results which returns an empty list
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results with two single bible versions
            self.media_item.display_results('NIV', 'GNB')

            # THEN: build_display_results should have been called with two bible versions.
            #       No items should be added to the list, and select all should have been called.
            mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results')
            self.assertFalse(mocked_list_view.addItem.called)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})

    def test_display_results_returns_lots_of_results(self):
            """
            Test the display_results method a large number of results (> 100) are returned
            """

            # GIVEN: A mocked build_display_results which returns a large list of results
            long_list = list(range(100))
            with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': long_list})\
                    as mocked_build_display_results:
                mocked_list_view = MagicMock()
                self.media_item.search_results = 'results'
                self.media_item.list_view = mocked_list_view

                # WHEN: Calling display_results
                self.media_item.display_results('NIV', 'GNB')

                # THEN: addItem should have been called 100 times, and the lsit items should not be selected.
                mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results')
                self.assertEqual(mocked_list_view.addItem.call_count, 100)
                mocked_list_view.selectAll.assert_called_once_with()
                self.assertEqual(self.media_item.search_results, {})
                self.assertEqual(self.media_item.second_search_results, {})

    def on_quick_search_button_general_test(self):
        """
        Test that general things, which should be called on all Quick searches are called.
        """

        # GIVEN: self.application as self.app, all the required functions
        Registry.create()
        Registry().register('application', self.app)
        self.media_item.quickSearchButton = MagicMock()
        self.app.process_events = MagicMock()
        self.media_item.quickVersionComboBox = MagicMock()
        self.media_item.quickVersionComboBox.currentText = MagicMock()
        self.media_item.quickSecondComboBox = MagicMock()
        self.media_item.quickSecondComboBox.currentText = MagicMock()
        self.media_item.quick_search_edit = MagicMock()
        self.media_item.quick_search_edit.text = MagicMock()
        self.media_item.quickLockButton = MagicMock()
        self.media_item.list_view = MagicMock()
        self.media_item.search_results = MagicMock()
        self.media_item.display_results = MagicMock()
        self.media_item.check_search_result = MagicMock()
        self.app.set_normal_cursor = MagicMock()

        # WHEN: on_quick_search_button is called
        self.media_item.on_quick_search_button()

        # THEN: Search should had been started and finalized properly
        self.assertEqual(1, self.app.process_events.call_count, 'Normal cursor should had been called once')
        self.assertEqual(1, self.media_item.quickVersionComboBox.currentText.call_count, 'Should had been called once')
        self.assertEqual(1, self.media_item.quickSecondComboBox.currentText.call_count, 'Should had been called once')
        self.assertEqual(1, self.media_item.quick_search_edit.text.call_count, 'Text edit Should had been called once')
        self.assertEqual(1, self.media_item.quickLockButton.isChecked.call_count, 'Lock Should had been called once')
        self.assertEqual(1, self.media_item.display_results.call_count, 'Display results Should had been called once')
        self.assertEqual(2, self.media_item.quickSearchButton.setEnabled.call_count, 'Disable and Enable the button')
        self.assertEqual(1, self.media_item.check_search_result.call_count, 'Check results Should had been called once')
        self.assertEqual(1, self.app.set_normal_cursor.call_count, 'Normal cursor should had been called once')
コード例 #6
0
ファイル: test_mediaitem.py プロジェクト: jkunle/paul
class TestMediaItem(TestCase, TestMixin):
    """
    Test the bible mediaitem methods.
    """
    def setUp(self):
        """
        Set up the components need for all tests.
        """
        with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\
                patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'):
            self.media_item = BibleMediaItem(None, MagicMock())
        self.setup_application()

    def display_results_no_results_test(self):
        """
        Test the display_results method when called with a single bible, returning no results
        """

        # GIVEN: A mocked build_display_results which returns an empty list
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results with a single bible version
            self.media_item.display_results('NIV')

            # THEN: No items should be added to the list, and select all should have been called.
            mocked_build_display_results.assert_called_once_with(
                'NIV', '', 'results')
            self.assertFalse(mocked_list_view.addItem.called)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})

    def display_results_two_bibles_no_results_test(self):
        """
        Test the display_results method when called with two bibles, returning no results
        """

        # GIVEN: A mocked build_display_results which returns an empty list
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results with two single bible versions
            self.media_item.display_results('NIV', 'GNB')

            # THEN: build_display_results should have been called with two bible versions.
            #       No items should be added to the list, and select all should have been called.
            mocked_build_display_results.assert_called_once_with(
                'NIV', 'GNB', 'results')
            self.assertFalse(mocked_list_view.addItem.called)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})

    def display_results_returns_lots_of_results_test_test(self):
        """
            Test the display_results method a large number of results (> 100) are returned
            """

        # GIVEN: A mocked build_display_results which returns a large list of results
        long_list = list(range(100))
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': long_list})\
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results
            self.media_item.display_results('NIV', 'GNB')

            # THEN: addItem should have been called 100 times, and the lsit items should not be selected.
            mocked_build_display_results.assert_called_once_with(
                'NIV', 'GNB', 'results')
            self.assertEqual(mocked_list_view.addItem.call_count, 100)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})
コード例 #7
0
class TestMediaItem(TestCase, TestMixin):
    """
    Test the bible mediaitem methods.
    """

    def setUp(self):
        """
        Set up the components need for all tests.
        """
        with patch('openlp.plugins.bibles.lib.mediaitem.MediaManagerItem._setup'),\
                patch('openlp.plugins.bibles.lib.mediaitem.BibleMediaItem.setup_item'):
            self.media_item = BibleMediaItem(None, MagicMock())
        self.setup_application()

    def display_results_no_results_test(self):
        """
        Test the display_results method when called with a single bible, returning no results
        """

        # GIVEN: A mocked build_display_results which returns an empty list
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results with a single bible version
            self.media_item.display_results('NIV')

            # THEN: No items should be added to the list, and select all should have been called.
            mocked_build_display_results.assert_called_once_with('NIV', '', 'results')
            self.assertFalse(mocked_list_view.addItem.called)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})

    def display_results_two_bibles_no_results_test(self):
        """
        Test the display_results method when called with two bibles, returning no results
        """

        # GIVEN: A mocked build_display_results which returns an empty list
        with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': []}) \
                as mocked_build_display_results:
            mocked_list_view = MagicMock()
            self.media_item.search_results = 'results'
            self.media_item.list_view = mocked_list_view

            # WHEN: Calling display_results with two single bible versions
            self.media_item.display_results('NIV', 'GNB')

            # THEN: build_display_results should have been called with two bible versions.
            #       No items should be added to the list, and select all should have been called.
            mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results')
            self.assertFalse(mocked_list_view.addItem.called)
            mocked_list_view.selectAll.assert_called_once_with()
            self.assertEqual(self.media_item.search_results, {})
            self.assertEqual(self.media_item.second_search_results, {})

    def display_results_returns_lots_of_results_test_test(self):
            """
            Test the display_results method a large number of results (> 100) are returned
            """

            # GIVEN: A mocked build_display_results which returns a large list of results
            long_list = list(range(100))
            with patch('openlp.plugins.bibles.lib.BibleMediaItem.build_display_results', **{'return_value': long_list})\
                    as mocked_build_display_results:
                mocked_list_view = MagicMock()
                self.media_item.search_results = 'results'
                self.media_item.list_view = mocked_list_view

                # WHEN: Calling display_results
                self.media_item.display_results('NIV', 'GNB')

                # THEN: addItem should have been called 100 times, and the lsit items should not be selected.
                mocked_build_display_results.assert_called_once_with('NIV', 'GNB', 'results')
                self.assertEqual(mocked_list_view.addItem.call_count, 100)
                mocked_list_view.selectAll.assert_called_once_with()
                self.assertEqual(self.media_item.search_results, {})
                self.assertEqual(self.media_item.second_search_results, {})