← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~phill-ridout/openlp/test-fixes into lp:openlp

 

Phill has proposed merging lp:~phill-ridout/openlp/test-fixes into lp:openlp.

Requested reviews:
  Raoul Snyman (raoul-snyman)

For more details, see:
https://code.launchpad.net/~phill-ridout/openlp/test-fixes/+merge/325039

Fixed some bible media item tests and one render test. The 02-Functional tests now pass, but we get a seg fault on the interface-tests

lp:~phill-ridout/openlp/test-fixes (revision 2748)
[SUCCESS] https://ci.openlp.io/job/Branch-01-Pull/2054/
[SUCCESS] https://ci.openlp.io/job/Branch-02-Functional-Tests/1964/
[SUCCESS] https://ci.openlp.io/job/Branch-03-Interface-Tests/1888/
[SUCCESS] https://ci.openlp.io/job/Branch-04a-Code_Analysis/1267/
[SUCCESS] https://ci.openlp.io/job/Branch-04b-Test_Coverage/1117/
[SUCCESS] https://ci.openlp.io/job/Branch-04c-Code_Analysis2/246/
[SUCCESS] https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/92/

Process finished with exit code 0
-- 
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'tests/functional/openlp_core_lib/test_renderer.py'
--- tests/functional/openlp_core_lib/test_renderer.py	2017-05-23 05:00:42 +0000
+++ tests/functional/openlp_core_lib/test_renderer.py	2017-06-03 23:33:01 +0000
@@ -182,13 +182,15 @@
     @patch('openlp.core.lib.renderer.QtWebKitWidgets.QWebView')
     @patch('openlp.core.lib.renderer.build_lyrics_format_css')
     @patch('openlp.core.lib.renderer.build_lyrics_outline_css')
-    def test_set_text_rectangle(self, mock_outline_css, mock_lyrics_css, mock_webview):
+    @patch('openlp.core.lib.renderer.build_chords_css')
+    def test_set_text_rectangle(self, mock_build_chords_css, mock_outline_css, mock_lyrics_css, mock_webview):
         """
         Test set_text_rectangle returns a proper html string
         """
         # GIVEN: test object and data
         mock_lyrics_css.return_value = ' FORMAT CSS; '
         mock_outline_css.return_value = ' OUTLINE CSS; '
+        mock_build_chords_css.return_value = ' CHORDS CSS; '
         theme_data = Theme()
         theme_data.font_main_name = 'Arial'
         theme_data.font_main_size = 20

=== modified file 'tests/functional/openlp_plugins/bibles/test_mediaitem.py'
--- tests/functional/openlp_plugins/bibles/test_mediaitem.py	2017-04-03 20:28:16 +0000
+++ tests/functional/openlp_plugins/bibles/test_mediaitem.py	2017-06-03 23:33:01 +0000
@@ -31,7 +31,7 @@
 
 from openlp.core.common import Registry
 from openlp.core.lib import MediaManagerItem
-from openlp.plugins.bibles.lib.mediaitem import BibleMediaItem, BibleSearch, ResultsTab, SearchStatus, \
+from openlp.plugins.bibles.lib.mediaitem import BibleMediaItem, BibleSearch, ResultsTab, SearchStatus, SearchTabs, \
     get_reference_separators, VALID_TEXT_SEARCH
 
 
@@ -206,29 +206,63 @@
         """
         Test the correct widget gets focus when the BibleMediaItem receives focus
         """
-        # GIVEN: An instance of :class:`MediaManagerItem` and a mocked out search_tab  and search_edit
+        # GIVEN: An instance of :class:`MediaManagerItem` and mocked out tabs and primary widgets
         self.media_item.search_tab = MagicMock(**{'isVisible.return_value': True})
         self.media_item.search_edit = MagicMock()
-
-        # WHEN: Calling on_focus
-        self.media_item.on_focus()
-
-        # THEN: setFocus and selectAll should have been called on search_edit
-        self.assertEqual(self.media_item.search_edit.mock_calls, [call.setFocus(), call.selectAll()])
-
-    def test_on_focus_search_tab_not_visible(self):
-        """
-        Test the correct widget gets focus when the BibleMediaItem receives focus
-        """
-        # GIVEN: An instance of :class:`MediaManagerItem` and a mocked out search_tab and select_book_combo_box
-        self.media_item.search_tab = MagicMock(**{'isVisible.return_value': False})
-        self.media_item.select_book_combo_box = MagicMock()
-
-        # WHEN: Calling on_focus
-        self.media_item.on_focus()
-
-        # THEN: setFocus should have been called on select_book_combo_box
-        self.assertTrue(self.media_item.select_book_combo_box.setFocus.called)
+        self.media_item.select_tab = MagicMock(**{'isVisible.return_value': False})
+        self.media_item.select_book_combo_box = MagicMock()
+        self.media_item.options_tab = MagicMock(**{'isVisible.return_value': False})
+        self.media_item.version_combo_box = MagicMock()
+
+        # WHEN: Calling on_focus
+        self.media_item.on_focus()
+
+        # THEN: search_edit should now have focus and its text selected
+        self.media_item.search_edit.assert_has_calls([call.setFocus(), call.selectAll()])
+        self.media_item.select_book_combo_box.assert_not_called()
+        self.media_item.version_combo_box.setFocus.assert_not_called()
+
+    def test_on_focus_select_tab_visible(self):
+        """
+        Test the correct widget gets focus when the BibleMediaItem receives focus
+        """
+        # GIVEN: An instance of :class:`MediaManagerItem` and mocked out tabs and primary widgets
+        self.media_item.search_tab = MagicMock(**{'isVisible.return_value': False})
+        self.media_item.search_edit = MagicMock()
+        self.media_item.select_tab = MagicMock(**{'isVisible.return_value': True})
+        self.media_item.select_book_combo_box = MagicMock()
+        self.media_item.options_tab = MagicMock(**{'isVisible.return_value': False})
+        self.media_item.version_combo_box = MagicMock()
+
+        # WHEN: Calling on_focus
+        self.media_item.on_focus()
+
+        # THEN: select_book_combo_box should have focus
+        self.media_item.search_edit.setFocus.assert_not_called()
+        self.media_item.search_edit.selectAll.assert_not_called()
+        self.media_item.select_book_combo_box.setFocus.assert_called_once_with()
+        self.media_item.version_combo_box.setFocus.assert_not_called()
+
+    def test_on_focus_options_tab_visible(self):
+        """
+        Test the correct widget gets focus when the BibleMediaItem receives focus
+        """
+        # GIVEN: An instance of :class:`MediaManagerItem` and mocked out tabs and primary widgets
+        self.media_item.search_tab = MagicMock(**{'isVisible.return_value': False})
+        self.media_item.search_edit = MagicMock()
+        self.media_item.select_tab = MagicMock(**{'isVisible.return_value': False})
+        self.media_item.select_book_combo_box = MagicMock()
+        self.media_item.options_tab = MagicMock(**{'isVisible.return_value': True})
+        self.media_item.version_combo_box = MagicMock()
+
+        # WHEN: Calling on_focus
+        self.media_item.on_focus()
+
+        # THEN: version_combo_box have received focus
+        self.media_item.search_edit.setFocus.assert_not_called()
+        self.media_item.search_edit.selectAll.assert_not_called()
+        self.media_item.select_book_combo_box.setFocus.assert_not_called()
+        self.media_item.version_combo_box.setFocus.assert_called_once_with()
 
     def test_config_update_show_second_bible(self):
         """
@@ -611,12 +645,15 @@
         # GIVEN: An instance of :class:`MediaManagerItem` and mocked out search_tab and select_tab
         self.media_item.search_tab = MagicMock()
         self.media_item.select_tab = MagicMock()
+        self.media_item.options_tab = MagicMock()
+        self.media_item.search_button = MagicMock()
         with patch.object(self.media_item, 'on_focus'):
 
             # WHEN: The search_tab has been selected
-            self.media_item.on_search_tab_bar_current_changed(0)
+            self.media_item.on_search_tab_bar_current_changed(SearchTabs.Search)
 
-            # THEN: search_tab should be setVisible and select_tab should be hidder
+            # THEN: The search_button should be enabled, search_tab should be setVisible and select_tab should be hidden
+            self.media_item.search_button.setEnabled.assert_called_once_with(True)
             self.media_item.search_tab.setVisible.assert_called_once_with(True)
             self.media_item.select_tab.setVisible.assert_called_once_with(False)
 
@@ -627,12 +664,15 @@
         # GIVEN: An instance of :class:`MediaManagerItem` and mocked out search_tab and select_tab
         self.media_item.search_tab = MagicMock()
         self.media_item.select_tab = MagicMock()
+        self.media_item.options_tab = MagicMock()
+        self.media_item.search_button = MagicMock()
         with patch.object(self.media_item, 'on_focus'):
 
             # WHEN: The select_tab has been selected
-            self.media_item.on_search_tab_bar_current_changed(1)
+            self.media_item.on_search_tab_bar_current_changed(SearchTabs.Select)
 
-            # THEN: search_tab should be setVisible and select_tab should be hidder
+            # THEN: The search_button should be enabled, select_tab should be setVisible and search_tab should be hidden
+            self.media_item.search_button.setEnabled.assert_called_once_with(True)
             self.media_item.search_tab.setVisible.assert_called_once_with(False)
             self.media_item.select_tab.setVisible.assert_called_once_with(True)
 
@@ -660,44 +700,23 @@
         # THEN: The select_book_combo_box model sort should have been reset
         self.media_item.select_book_combo_box.model().sort.assert_called_once_with(-1)
 
-    def test_on_clear_button_clicked_saved_tab(self):
-        """
-        Test on_clear_button_clicked when the saved tab is selected
-        """
-        # GIVEN: An instance of :class:`MediaManagerItem` and mocked out saved_tab and select_tab and a mocked out
-        #        list_view and search_edit
-        self.media_item.list_view = MagicMock()
-        self.media_item.search_edit = MagicMock()
-        self.media_item.results_view_tab = MagicMock(**{'currentIndex.return_value': ResultsTab.Saved})
-        self.media_item.saved_results = ['Some', 'Results']
-        with patch.object(self.media_item, 'on_focus'):
-
-            # WHEN: Calling on_clear_button_clicked
-            self.media_item.on_clear_button_clicked()
-
-            # THEN: The list_view should be cleared
-            self.assertEqual(self.media_item.saved_results, [])
-            self.media_item.list_view.clear.assert_called_once_with()
-
-    def test_on_clear_button_clicked_search_tab(self):
+    def test_on_clear_button_clicked(self):
         """
         Test on_clear_button_clicked when the search tab is selected
         """
         # GIVEN: An instance of :class:`MediaManagerItem` and mocked out search_tab and select_tab and a mocked out
         #        list_view and search_edit
-        self.media_item.list_view = MagicMock()
-        self.media_item.search_edit = MagicMock()
+        self.media_item.list_view = MagicMock(**{'selectedItems.return_value': ['Some', 'Results']})
         self.media_item.results_view_tab = MagicMock(**{'currentIndex.return_value': ResultsTab.Search})
-        self.media_item.current_results = ['Some', 'Results']
-        with patch.object(self.media_item, 'on_focus'):
+        with patch.object(self.media_item, 'on_results_view_tab_total_update'):
 
             # WHEN: Calling on_clear_button_clicked
             self.media_item.on_clear_button_clicked()
 
             # THEN: The list_view and the search_edit should be cleared
             self.assertEqual(self.media_item.current_results, [])
-            self.media_item.list_view.clear.assert_called_once_with()
-            self.media_item.search_edit.clear.assert_called_once_with()
+            self.assertEqual(self.media_item.list_view.takeItem.call_count, 2)
+            self.media_item.list_view.row.assert_has_calls([call('Some'), call('Results')])
 
     def test_on_save_results_button_clicked(self):
         """
@@ -809,6 +828,7 @@
             #       to the dialog box
             self.media_item.second_bible = None
             self.media_item.second_combo_box = MagicMock(**{'currentData.return_value': self.mocked_bible_1})
+            self.media_item.saved_results = ['saved_results']
             self.media_item.on_second_combo_box_index_changed(5)
 
             # THEN: The list_view should be cleared and the currently selected bible should not be channged
@@ -836,6 +856,7 @@
             #       to the dialog box
             self.media_item.second_bible = None
             self.media_item.second_combo_box = MagicMock(**{'currentData.return_value': self.mocked_bible_1})
+            self.media_item.saved_results = ['saved_results']
             self.media_item.on_second_combo_box_index_changed(5)
 
             # THEN: The selected bible should be set as the current bible
@@ -862,6 +883,7 @@
             #       to the dialog box
             self.media_item.second_bible = self.mocked_bible_1
             self.media_item.second_combo_box = MagicMock(**{'currentData.return_value': None})
+            self.media_item.saved_results = ['saved_results']
             self.media_item.on_second_combo_box_index_changed(0)
 
             # THEN: The selected bible should be set as the current bible
@@ -902,6 +924,7 @@
         self.media_item.select_book_combo_box = MagicMock(**{'currentData.return_value': 2})
         self.media_item.bible = self.mocked_bible_1
         self.mocked_plugin.manager.get_verse_count_by_book_ref_id.return_value = 6
+        self.media_item.select_tab = MagicMock(**{'isVisible.return_value': True})
         self.media_item.search_button = MagicMock()
         with patch.object(self.media_item, 'adjust_combo_box') as mocked_adjust_combo_box:
             # WHEN: Calling on_advanced_book_combo_box
@@ -1383,6 +1406,8 @@
         #       'bibles/is search while typing enabled' is requested
         self.setting_values = {'bibles/is search while typing enabled': True}
         self.media_item.search_timer.isActive.return_value = False
+        self.media_item.bible = self.mocked_bible_1
+        self.media_item.bible.is_web_bible = False
 
         # WHEN: Calling on_search_edit_text_changed
         self.media_item.on_search_edit_text_changed()
@@ -1402,7 +1427,7 @@
             self.media_item.on_search_timer_timeout()
 
             # THEN: The search_status should be set to SearchAsYouType and text_search should have been called
-            self.assertEqual(self.media_item.search_status, SearchStatus().SearchAsYouType)
+            self.assertEqual(self.media_item.search_status, SearchStatus.SearchAsYouType)
             mocked_text_search.assert_called_once_with()
 
     def test_display_results_no_results(self):

=== modified file 'tests/interfaces/openlp_core_ui/test_projectoreditform.py'
--- tests/interfaces/openlp_core_ui/test_projectoreditform.py	2017-04-24 05:17:55 +0000
+++ tests/interfaces/openlp_core_ui/test_projectoreditform.py	2017-06-03 23:33:01 +0000
@@ -45,8 +45,8 @@
 
         :return: None
         """
+        self.setup_application()
         self.build_settings()
-        self.setup_application()
         Registry.create()
         with patch('openlp.core.lib.projector.db.init_url') as mocked_init_url:
             if os.path.exists(TEST_DB):

=== modified file 'tests/interfaces/openlp_plugins/bibles/test_lib_manager.py'
--- tests/interfaces/openlp_plugins/bibles/test_lib_manager.py	2017-04-24 05:17:55 +0000
+++ tests/interfaces/openlp_plugins/bibles/test_lib_manager.py	2017-06-03 23:33:01 +0000
@@ -38,6 +38,7 @@
         """
         Set up the environment for testing bible queries with 1 Timothy 3
         """
+        self.setup_application()
         self.build_settings()
         Registry.create()
         Registry().register('service_list', MagicMock())

=== modified file 'tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py'
--- tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py	2017-05-26 13:30:54 +0000
+++ tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py	2017-06-03 23:33:01 +0000
@@ -38,6 +38,7 @@
         """
         Set up the environment for testing bible parse reference
         """
+        self.setup_application()
         self.build_settings()
         Registry.create()
         Registry().register('service_list', MagicMock())


Follow ups