2013-10-04 20:36:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2013-12-24 08:56:50 +00:00
|
|
|
# Copyright (c) 2008-2014 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
2013-10-04 20:36:02 +00:00
|
|
|
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
|
|
|
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
|
|
|
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
|
|
|
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
|
|
|
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
|
|
|
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2013-09-01 06:22:06 +00:00
|
|
|
"""
|
|
|
|
Package to test the openlp.core.ui.formattingtagsform package.
|
|
|
|
"""
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2014-09-07 22:17:20 +00:00
|
|
|
from tests.functional import MagicMock, patch, call
|
2013-09-01 06:22:06 +00:00
|
|
|
|
|
|
|
from openlp.core.ui.formattingtagform import FormattingTagForm
|
|
|
|
|
|
|
|
# TODO: Tests Still TODO
|
|
|
|
# __init__
|
|
|
|
# exec_
|
|
|
|
# on_saved_clicked
|
|
|
|
# _reloadTable
|
|
|
|
|
|
|
|
|
|
|
|
class TestFormattingTagForm(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2014-09-07 22:17:20 +00:00
|
|
|
"""
|
|
|
|
Mock out stuff for all the tests
|
|
|
|
"""
|
|
|
|
self.setup_patcher = patch('openlp.core.ui.formattingtagform.FormattingTagForm._setup')
|
|
|
|
self.setup_patcher.start()
|
2013-09-01 06:22:06 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2014-09-07 22:17:20 +00:00
|
|
|
"""
|
|
|
|
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)
|
2013-09-01 06:22:06 +00:00
|
|
|
|
2014-09-07 22:17:20 +00:00
|
|
|
def on_new_clicked_test(self):
|
2013-09-01 06:22:06 +00:00
|
|
|
"""
|
2014-09-07 22:17:20 +00:00
|
|
|
Test that clicking the Add a new tag button does the right thing
|
2013-09-01 06:22:06 +00:00
|
|
|
"""
|
|
|
|
|
2014-09-07 22:17:20 +00:00
|
|
|
# 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
|
2013-09-01 06:22:06 +00:00
|
|
|
|
2014-09-07 22:17:20 +00:00
|
|
|
# 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()
|
2013-09-01 06:22:06 +00:00
|
|
|
|
2014-09-07 22:17:20 +00:00
|
|
|
# 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)
|