forked from openlp/openlp
Added tests for with and without os x menu icon, renamed some tests to use our test name convention, fixed up and added more tests for the FormattingTagsForm.
This commit is contained in:
parent
09be73cc26
commit
bf488da516
@ -60,6 +60,12 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog, FormattingTagCont
|
||||
"""
|
||||
super(FormattingTagForm, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self._setup()
|
||||
|
||||
def _setup(self):
|
||||
"""
|
||||
Set up the class. This method is mocked out by the tests.
|
||||
"""
|
||||
self.services = FormattingTagController()
|
||||
self.tag_table_widget.itemSelectionChanged.connect(self.on_row_selected)
|
||||
self.new_button.clicked.connect(self.on_new_clicked)
|
||||
|
@ -51,7 +51,7 @@ class TestTheme(TestCase):
|
||||
"""
|
||||
pass
|
||||
|
||||
def test_new_theme(self):
|
||||
def new_theme_test(self):
|
||||
"""
|
||||
Test the theme creation - basic test
|
||||
"""
|
||||
|
@ -29,10 +29,14 @@
|
||||
"""
|
||||
Package to test the openlp.core.lib.ui package.
|
||||
"""
|
||||
from PyQt4 import QtGui
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from unittest import TestCase
|
||||
|
||||
from openlp.core.lib.ui import *
|
||||
from openlp.core.common import UiStrings, translate
|
||||
from openlp.core.lib.ui import add_welcome_page, create_button_box, create_horizontal_adjusting_combo_box, \
|
||||
create_button, create_action, create_valign_selection_widgets, find_and_set_in_combo_box, create_widget_action, \
|
||||
set_case_insensitive_completer
|
||||
from tests.functional import MagicMock, patch
|
||||
|
||||
|
||||
class TestUi(TestCase):
|
||||
@ -40,7 +44,7 @@ class TestUi(TestCase):
|
||||
Test the functions in the ui module
|
||||
"""
|
||||
|
||||
def test_add_welcome_page(self):
|
||||
def add_welcome_page_test(self):
|
||||
"""
|
||||
Test appending a welcome page to a wizard
|
||||
"""
|
||||
@ -54,7 +58,7 @@ class TestUi(TestCase):
|
||||
self.assertEqual(1, len(wizard.pageIds()), 'The wizard should have one page.')
|
||||
self.assertIsInstance(wizard.page(0).pixmap(QtGui.QWizard.WatermarkPixmap), QtGui.QPixmap)
|
||||
|
||||
def test_create_button_box(self):
|
||||
def create_button_box_test(self):
|
||||
"""
|
||||
Test creating a button box for a dialog
|
||||
"""
|
||||
@ -82,7 +86,7 @@ class TestUi(TestCase):
|
||||
self.assertEqual(1, len(btnbox.buttons()))
|
||||
self.assertEqual(QtGui.QDialogButtonBox.HelpRole, btnbox.buttonRole(btnbox.buttons()[0]))
|
||||
|
||||
def test_create_horizontal_adjusting_combo_box(self):
|
||||
def create_horizontal_adjusting_combo_box_test(self):
|
||||
"""
|
||||
Test creating a horizontal adjusting combo box
|
||||
"""
|
||||
@ -97,7 +101,7 @@ class TestUi(TestCase):
|
||||
self.assertEqual('combo1', combo.objectName())
|
||||
self.assertEqual(QtGui.QComboBox.AdjustToMinimumContentsLength, combo.sizeAdjustPolicy())
|
||||
|
||||
def test_create_button(self):
|
||||
def create_button_test(self):
|
||||
"""
|
||||
Test creating a button
|
||||
"""
|
||||
@ -129,7 +133,7 @@ class TestUi(TestCase):
|
||||
self.assertEqual('my_btn', btn.objectName())
|
||||
self.assertTrue(btn.isEnabled())
|
||||
|
||||
def test_create_action(self):
|
||||
def create_action_test(self):
|
||||
"""
|
||||
Test creating an action
|
||||
"""
|
||||
@ -154,7 +158,44 @@ class TestUi(TestCase):
|
||||
self.assertEqual('my tooltip', action.toolTip())
|
||||
self.assertEqual('my statustip', action.statusTip())
|
||||
|
||||
def test_create_checked_enabled_visible_action(self):
|
||||
def create_action_on_mac_osx_test(self):
|
||||
"""
|
||||
Test creating an action on OS X calls the correct method
|
||||
"""
|
||||
# GIVEN: A dialog and a mocked out is_macosx() method to always return True
|
||||
with patch('openlp.core.lib.ui.is_macosx') as mocked_is_macosx, \
|
||||
patch('openlp.core.lib.ui.QtGui.QAction') as MockedQAction:
|
||||
mocked_is_macosx.return_value = True
|
||||
mocked_action = MagicMock()
|
||||
MockedQAction.return_value = mocked_action
|
||||
dialog = QtGui.QDialog()
|
||||
|
||||
# WHEN: An action is created
|
||||
create_action(dialog, 'my_action')
|
||||
|
||||
# THEN: setIconVisibleInMenu should be called
|
||||
mocked_action.setIconVisibleInMenu.assert_called_with(False)
|
||||
|
||||
def create_action_not_on_mac_osx_test(self):
|
||||
"""
|
||||
Test creating an action on something other than OS X doesn't call the method
|
||||
"""
|
||||
# GIVEN: A dialog and a mocked out is_macosx() method to always return True
|
||||
with patch('openlp.core.lib.ui.is_macosx') as mocked_is_macosx, \
|
||||
patch('openlp.core.lib.ui.QtGui.QAction') as MockedQAction:
|
||||
mocked_is_macosx.return_value = False
|
||||
mocked_action = MagicMock()
|
||||
MockedQAction.return_value = mocked_action
|
||||
dialog = QtGui.QDialog()
|
||||
|
||||
# WHEN: An action is created
|
||||
create_action(dialog, 'my_action')
|
||||
|
||||
# THEN: setIconVisibleInMenu should not be called
|
||||
self.assertEqual(0, mocked_action.setIconVisibleInMenu.call_count,
|
||||
'setIconVisibleInMenu should not have been called')
|
||||
|
||||
def create_checked_enabled_visible_action_test(self):
|
||||
"""
|
||||
Test creating an action with the 'checked', 'enabled' and 'visible' properties.
|
||||
"""
|
||||
@ -169,7 +210,7 @@ class TestUi(TestCase):
|
||||
self.assertEqual(False, action.isEnabled())
|
||||
self.assertEqual(False, action.isVisible())
|
||||
|
||||
def test_create_valign_selection_widgets(self):
|
||||
def create_valign_selection_widgets_test(self):
|
||||
"""
|
||||
Test creating a combo box for valign selection
|
||||
"""
|
||||
@ -186,7 +227,7 @@ class TestUi(TestCase):
|
||||
for text in [UiStrings().Top, UiStrings().Middle, UiStrings().Bottom]:
|
||||
self.assertTrue(combo.findText(text) >= 0)
|
||||
|
||||
def test_find_and_set_in_combo_box(self):
|
||||
def find_and_set_in_combo_box_test(self):
|
||||
"""
|
||||
Test finding a string in a combo box and setting it as the selected item if present
|
||||
"""
|
||||
@ -213,7 +254,7 @@ class TestUi(TestCase):
|
||||
# THEN: The index should have changed
|
||||
self.assertEqual(2, combo.currentIndex())
|
||||
|
||||
def test_create_widget_action(self):
|
||||
def create_widget_action_test(self):
|
||||
"""
|
||||
Test creating an action for a widget
|
||||
"""
|
||||
@ -227,7 +268,7 @@ class TestUi(TestCase):
|
||||
self.assertIsInstance(action, QtGui.QAction)
|
||||
self.assertEqual(action.objectName(), 'some action')
|
||||
|
||||
def test_set_case_insensitive_completer(self):
|
||||
def set_case_insensitive_completer_test(self):
|
||||
"""
|
||||
Test setting a case insensitive completer on a widget
|
||||
"""
|
||||
|
@ -47,7 +47,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
|
||||
Registry().register('application', self.app)
|
||||
self.first_time_form = FirstTimeForm(screens)
|
||||
|
||||
def test_access_to_config(self):
|
||||
def access_to_config_test(self):
|
||||
"""
|
||||
Test if we can access the First Time Form's config file
|
||||
"""
|
||||
@ -59,7 +59,7 @@ class TestFirstTimeForm(TestCase, TestMixin):
|
||||
self.assertTrue(self.first_time_form.web_access,
|
||||
'First Time Wizard\'s web configuration file should be available')
|
||||
|
||||
def test_parsable_config(self):
|
||||
def parsable_config_test(self):
|
||||
"""
|
||||
Test if the First Time Form's config file is parsable
|
||||
"""
|
||||
|
@ -39,7 +39,7 @@ class TestFormattingTagController(TestCase):
|
||||
def setUp(self):
|
||||
self.services = FormattingTagController()
|
||||
|
||||
def test_strip(self):
|
||||
def strip_test(self):
|
||||
"""
|
||||
Test that the _strip strips the correct chars
|
||||
"""
|
||||
@ -52,7 +52,7 @@ class TestFormattingTagController(TestCase):
|
||||
# THEN: The tag should be returned with the wrappers removed.
|
||||
self.assertEqual(result, 'tag', 'FormattingTagForm._strip should return u\'tag\' when called with u\'{tag}\'')
|
||||
|
||||
def test_end_tag_changed_processes_correctly(self):
|
||||
def end_tag_changed_processes_correctly_test(self):
|
||||
"""
|
||||
Test that the end html tags are generated correctly
|
||||
"""
|
||||
@ -77,7 +77,7 @@ class TestFormattingTagController(TestCase):
|
||||
self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' %
|
||||
error)
|
||||
|
||||
def test_start_tag_changed_processes_correctly(self):
|
||||
def start_tag_changed_processes_correctly_test(self):
|
||||
"""
|
||||
Test that the end html tags are generated correctly
|
||||
"""
|
||||
@ -100,7 +100,7 @@ class TestFormattingTagController(TestCase):
|
||||
self.assertTrue(error == test['valid'], 'Function should not generate unexpected error messages : %s ' %
|
||||
error)
|
||||
|
||||
def test_start_html_to_end_html(self):
|
||||
def start_html_to_end_html_test(self):
|
||||
"""
|
||||
Test that the end html tags are generated correctly
|
||||
"""
|
||||
|
@ -29,17 +29,17 @@
|
||||
"""
|
||||
Package to test the openlp.core.ui.formattingtagsform package.
|
||||
"""
|
||||
from PyQt4 import QtGui
|
||||
from unittest import TestCase
|
||||
from openlp.core.common import translate
|
||||
|
||||
from tests.functional import MagicMock, patch
|
||||
from tests.functional import MagicMock, patch, call
|
||||
|
||||
from openlp.core.ui.formattingtagform import FormattingTagForm
|
||||
|
||||
# TODO: Tests Still TODO
|
||||
# __init__
|
||||
# exec_
|
||||
# on_new_clicked
|
||||
# on_delete_clicked
|
||||
# on_saved_clicked
|
||||
# _reloadTable
|
||||
|
||||
@ -47,30 +47,60 @@ from openlp.core.ui.formattingtagform import FormattingTagForm
|
||||
class TestFormattingTagForm(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.init_patcher = patch('openlp.core.ui.formattingtagform.FormattingTagForm.__init__')
|
||||
self.qdialog_patcher = patch('openlp.core.ui.formattingtagform.QtGui.QDialog')
|
||||
self.ui_formatting_tag_dialog_patcher = patch('openlp.core.ui.formattingtagform.Ui_FormattingTagDialog')
|
||||
self.mocked_init = self.init_patcher.start()
|
||||
self.mocked_qdialog = self.qdialog_patcher.start()
|
||||
self.mocked_ui_formatting_tag_dialog = self.ui_formatting_tag_dialog_patcher.start()
|
||||
self.mocked_init.return_value = None
|
||||
"""
|
||||
Mock out stuff for all the tests
|
||||
"""
|
||||
self.setup_patcher = patch('openlp.core.ui.formattingtagform.FormattingTagForm._setup')
|
||||
self.setup_patcher.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.init_patcher.stop()
|
||||
self.qdialog_patcher.stop()
|
||||
self.ui_formatting_tag_dialog_patcher.stop()
|
||||
|
||||
def test_on_text_edited(self):
|
||||
"""
|
||||
Test that the appropriate actions are preformed when on_text_edited is called
|
||||
Remove the mocks
|
||||
"""
|
||||
self.setup_patcher.stop()
|
||||
|
||||
def on_row_selected_test(self):
|
||||
"""
|
||||
Test that the appropriate actions are preformed when on_row_selected is called
|
||||
"""
|
||||
# GIVEN: An instance of the Formatting Tag Form and a mocked delete_button
|
||||
form = FormattingTagForm(None)
|
||||
form.delete_button = MagicMock()
|
||||
|
||||
# WHEN: on_row_selected is called
|
||||
form.on_row_selected()
|
||||
|
||||
# THEN: setEnabled and should have been called on delete_button
|
||||
form.delete_button.setEnabled.assert_called_with(True)
|
||||
|
||||
def on_new_clicked_test(self):
|
||||
"""
|
||||
Test that clicking the Add a new tag button does the right thing
|
||||
"""
|
||||
|
||||
# GIVEN: An instance of the Formatting Tag Form and a mocked save_push_button
|
||||
form = FormattingTagForm()
|
||||
form.save_button = MagicMock()
|
||||
# GIVEN: A formatting tag form and a mocked out tag table widget
|
||||
form = FormattingTagForm(None)
|
||||
form.tag_table_widget = MagicMock()
|
||||
row_count = 5
|
||||
form.tag_table_widget.rowCount.return_value = row_count
|
||||
|
||||
# WHEN: on_text_edited is called with an arbitrary value
|
||||
# form.on_text_edited('text')
|
||||
# WHEN: on_new_clicked is run (i.e. the Add new button was clicked)
|
||||
with patch('openlp.core.ui.formattingtagform.QtGui.QTableWidgetItem') as MockedQTableWidgetItem:
|
||||
mocked_table_widget = MagicMock()
|
||||
MockedQTableWidgetItem.return_value = mocked_table_widget
|
||||
form.on_new_clicked()
|
||||
|
||||
# THEN: setEnabled and setDefault should have been called on save_push_button
|
||||
# form.save_button.setEnabled.assert_called_with(True)
|
||||
# THEN: A new row should be added to the table
|
||||
form.tag_table_widget.rowCount.assert_called_with()
|
||||
form.tag_table_widget.insertRow.assert_called_with(row_count)
|
||||
expected_set_item_calls = [
|
||||
call(row_count, 0, mocked_table_widget),
|
||||
call(row_count, 1, mocked_table_widget),
|
||||
call(row_count, 2, mocked_table_widget),
|
||||
call(row_count, 3, mocked_table_widget)
|
||||
]
|
||||
self.assertEqual(expected_set_item_calls, form.tag_table_widget.setItem.call_args_list,
|
||||
'setItem should have been called correctly')
|
||||
form.tag_table_widget.resizeRowsToContents.assert_called_with()
|
||||
form.tag_table_widget.scrollToBottom.assert_called_with()
|
||||
form.tag_table_widget.selectRow.assert_called_with(row_count)
|
||||
|
Loading…
Reference in New Issue
Block a user