diff --git a/.bzrignore b/.bzrignore index 76a07245d..ab4adde18 100644 --- a/.bzrignore +++ b/.bzrignore @@ -23,3 +23,5 @@ resources/windows/warnOpenLP.txt openlp.cfg .idea openlp.pro +.kdev4 +tests.kdev4 diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index ff4f8234b..ce920d598 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -34,7 +34,6 @@ import logging import os from urllib import quote_plus as urlquote -from PyQt4 import QtCore from sqlalchemy import Table, MetaData, Column, types, create_engine from sqlalchemy.exc import SQLAlchemyError, InvalidRequestError, DBAPIError, OperationalError from sqlalchemy.orm import scoped_session, sessionmaker, mapper diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index 594a4322e..eb52dc26f 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -31,8 +31,6 @@ Provide HTML Tag management and Formatting Tag access class """ import cPickle -from PyQt4 import QtCore - from openlp.core.lib import translate, Settings class FormattingTags(object): diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index dd2c722ad..4c0d638d4 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -183,6 +183,9 @@ class ServiceItem(object): self.background_audio = [] self.theme_overwritten = False self.temporary_edit = False + self.auto_play_slides_once = False + self.auto_play_slides_loop = False + self.timed_slide_interval = 0 self.will_auto_start = False self.has_original_files = True self._new_item() @@ -344,6 +347,9 @@ class ServiceItem(object): u'search': self.search_string, u'data': self.data_string, u'xml_version': self.xml_version, + u'auto_play_slides_once': self.auto_play_slides_once, + u'auto_play_slides_loop': self.auto_play_slides_loop, + u'timed_slide_interval': self.timed_slide_interval, u'start_time': self.start_time, u'end_time': self.end_time, u'media_length': self.media_length, @@ -398,6 +404,9 @@ class ServiceItem(object): self.start_time = header.get(u'start_time', 0) self.end_time = header.get(u'end_time', 0) self.media_length = header.get(u'media_length', 0) + self.auto_play_slides_once = header.get(u'auto_play_slides_once', False) + self.auto_play_slides_loop = header.get(u'auto_play_slides_loop', False) + self.timed_slide_interval = header.get(u'timed_slide_interval', 0) self.will_auto_start = header.get(u'will_auto_start', False) self.has_original_files = True if u'background_audio' in header: @@ -427,7 +436,6 @@ class ServiceItem(object): self.add_from_command(path, text_image[u'title'], text_image[u'image']) else: self.add_from_command(text_image[u'path'], text_image[u'title'], text_image[u'image']) - self._new_item() def get_display_title(self): diff --git a/openlp/core/ui/__init__.py b/openlp/core/ui/__init__.py index e117a0809..132465b2e 100644 --- a/openlp/core/ui/__init__.py +++ b/openlp/core/ui/__init__.py @@ -29,9 +29,7 @@ """ The :mod:`ui` module provides the core user interface for OpenLP """ -from PyQt4 import QtGui -from openlp.core.lib import translate class HideMode(object): """ diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 785cba95a..8a9b01d04 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -257,6 +257,20 @@ class ServiceManager(QtGui.QWidget): text=translate('OpenLP.ServiceManager', 'Create New &Custom Slide'), icon=u':/general/general_edit.png', triggers=self.create_custom) self.menu.addSeparator() + # Add AutoPlay menu actions + self.autoPlaySlidesGroup = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Auto play slides')) + self.menu.addMenu(self.autoPlaySlidesGroup) + self.autoPlaySlidesLoop = create_widget_action(self.autoPlaySlidesGroup, + text=translate('OpenLP.ServiceManager', 'Auto play slides &Loop'), + checked=False, triggers=self.toggleAutoPlaySlidesLoop) + self.autoPlaySlidesOnce = create_widget_action(self.autoPlaySlidesGroup, + text=translate('OpenLP.ServiceManager', 'Auto play slides &Once'), + checked=False, triggers=self.toggleAutoPlaySlidesOnce) + self.autoPlaySlidesGroup.addSeparator() + self.timedSlideInterval = create_widget_action(self.autoPlaySlidesGroup, + text=translate('OpenLP.ServiceManager', '&Delay between slides'), + checked=False, triggers=self.onTimedSlideInterval) + self.menu.addSeparator() self.previewAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', 'Show &Preview'), icon=u':/general/general_preview.png', triggers=self.makePreview) # Add already existing make live action to the menu. @@ -766,6 +780,22 @@ class ServiceManager(QtGui.QWidget): self.maintainAction.setVisible(True) if item.parent() is None: self.notesAction.setVisible(True) + if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanLoop) and \ + len(serviceItem[u'service_item'].get_frames()) > 1: + self.autoPlaySlidesGroup.menuAction().setVisible(True) + self.autoPlaySlidesOnce.setChecked(serviceItem[u'service_item'].auto_play_slides_once) + self.autoPlaySlidesLoop.setChecked(serviceItem[u'service_item'].auto_play_slides_loop) + self.timedSlideInterval.setChecked(serviceItem[u'service_item'].timed_slide_interval > 0) + if serviceItem[u'service_item'].timed_slide_interval > 0: + delay_suffix = u' ' + delay_suffix += unicode(serviceItem[u'service_item'].timed_slide_interval) + delay_suffix += u' s' + else: + delay_suffix = u' ...' + self.timedSlideInterval.setText(translate('OpenLP.ServiceManager', '&Delay between slides') + delay_suffix) + # TODO for future: make group explains itself more visually + else: + self.autoPlaySlidesGroup.menuAction().setVisible(False) if serviceItem[u'service_item'].is_capable(ItemCapabilities.HasVariableStartTime): self.timeAction.setVisible(True) if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): @@ -811,6 +841,59 @@ class ServiceManager(QtGui.QWidget): if self.startTimeForm.exec_(): self.repaintServiceList(item, -1) + def toggleAutoPlaySlidesOnce(self): + """ + Toggle Auto play slide once. + Inverts auto play once option for the item + """ + item = self.findServiceItem()[0] + service_item = self.serviceItems[item][u'service_item'] + service_item.auto_play_slides_once = not service_item.auto_play_slides_once + if service_item.auto_play_slides_once: + service_item.auto_play_slides_loop = False + self.autoPlaySlidesLoop.setChecked(False) + if service_item.auto_play_slides_once and service_item.timed_slide_interval == 0: + service_item.timed_slide_interval = Settings().value(u'loop delay', 5) + self.setModified() + + def toggleAutoPlaySlidesLoop(self): + """ + Toggle Auto play slide loop. + """ + item = self.findServiceItem()[0] + service_item = self.serviceItems[item][u'service_item'] + service_item.auto_play_slides_loop = not service_item.auto_play_slides_loop + if service_item.auto_play_slides_loop: + service_item.auto_play_slides_once = False + self.autoPlaySlidesOnce.setChecked(False) + if service_item.auto_play_slides_loop and service_item.timed_slide_interval == 0: + service_item.timed_slide_interval = Settings().value(u'loop delay', 5) + self.setModified() + + def onTimedSlideInterval(self): + """ + on set times slide interval. + Shows input dialog for enter interval in seconds for delay + """ + item = self.findServiceItem()[0] + service_item = self.serviceItems[item][u'service_item'] + if service_item.timed_slide_interval == 0: + timed_slide_interval = Settings().value(u'loop delay', 5) + else: + timed_slide_interval = service_item.timed_slide_interval + timed_slide_interval, ok = QtGui.QInputDialog.getInteger(self, translate('OpenLP.ServiceManager', + 'Input delay'), translate('OpenLP.ServiceManager', 'Delay between slides in seconds.'), + timed_slide_interval, 0, 180, 1) + if ok: + service_item.timed_slide_interval = timed_slide_interval + if service_item.timed_slide_interval <> 0 and not service_item.auto_play_slides_loop\ + and not service_item.auto_play_slides_once: + service_item.auto_play_slides_loop = True + elif service_item.timed_slide_interval == 0: + service_item.auto_play_slides_loop = False + service_item.auto_play_slides_once = False + self.setModified() + def onAutoStart(self): """ Toggles to Auto Start Setting. @@ -1291,6 +1374,8 @@ class ServiceManager(QtGui.QWidget): if self.serviceItems and item < len(self.serviceItems) and \ self.serviceItems[item][u'service_item'].is_capable(ItemCapabilities.CanPreview): self.mainwindow.previewController.addServiceManagerItem(self.serviceItems[item][u'service_item'], 0) + next_item = self.serviceManagerList.topLevelItem(item) + self.serviceManagerList.setCurrentItem(next_item) self.mainwindow.liveController.previewListWidget.setFocus() else: critical_error_message_box(translate('OpenLP.ServiceManager', 'Missing Display Handler'), diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 55e94e3a6..2807f215a 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -31,7 +31,7 @@ The :mod:`settingsform` provides a user interface for the OpenLP settings """ import logging -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui from openlp.core.lib import Receiver, build_icon, PluginStatus from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab @@ -141,4 +141,4 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ if self.resetSuffixes: self.mainWindow.serviceManagerContents.resetSupportedSuffixes() - self.resetSuffixes = False \ No newline at end of file + self.resetSuffixes = False diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 8a19958d8..7e6879bdf 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -692,6 +692,14 @@ class SlideController(DisplayController): self.slideSelected() else: self._processItem(item, slidenum) + if self.isLive and item.auto_play_slides_loop and item.timed_slide_interval > 0: + self.playSlidesLoop.setChecked(item.auto_play_slides_loop) + self.delaySpinBox.setValue(int(item.timed_slide_interval)) + self.onPlaySlidesLoop() + elif self.isLive and item.auto_play_slides_once and item.timed_slide_interval > 0: + self.playSlidesOnce.setChecked(item.auto_play_slides_once) + self.delaySpinBox.setValue(int(item.timed_slide_interval)) + self.onPlaySlidesOnce() def _processItem(self, serviceItem, slideno): """ @@ -881,6 +889,7 @@ class SlideController(DisplayController): Settings().remove(self.parent().generalSettingsSection + u'/screen blank') self.blankPlugin() self.updatePreview() + self.onToggleLoop() def onThemeDisplay(self, checked=None): """ @@ -899,6 +908,7 @@ class SlideController(DisplayController): Settings().remove(self.parent().generalSettingsSection + u'/screen blank') self.blankPlugin() self.updatePreview() + self.onToggleLoop() def onHideDisplay(self, checked=None): """ @@ -917,6 +927,7 @@ class SlideController(DisplayController): Settings().remove(self.parent().generalSettingsSection + u'/screen blank') self.hidePlugin(checked) self.updatePreview() + self.onToggleLoop() def blankPlugin(self): """ @@ -1092,7 +1103,8 @@ class SlideController(DisplayController): """ Toggles the loop state. """ - if self.playSlidesLoop.isChecked() or self.playSlidesOnce.isChecked(): + hide_mode = self.hideMode() + if hide_mode is None and (self.playSlidesLoop.isChecked() or self.playSlidesOnce.isChecked()): self.onStartLoop() else: self.onStopLoop() @@ -1126,11 +1138,11 @@ class SlideController(DisplayController): self.playSlidesLoop.setText(UiStrings().StopPlaySlidesInLoop) self.playSlidesOnce.setIcon(build_icon(u':/media/media_time.png')) self.playSlidesOnce.setText(UiStrings().PlaySlidesToEnd) + self.playSlidesMenu.setDefaultAction(self.playSlidesLoop) + self.playSlidesOnce.setChecked(False) else: self.playSlidesLoop.setIcon(build_icon(u':/media/media_time.png')) self.playSlidesLoop.setText(UiStrings().PlaySlidesInLoop) - self.playSlidesMenu.setDefaultAction(self.playSlidesLoop) - self.playSlidesOnce.setChecked(False) self.onToggleLoop() def onPlaySlidesOnce(self, checked=None): @@ -1147,11 +1159,11 @@ class SlideController(DisplayController): self.playSlidesOnce.setText(UiStrings().StopPlaySlidesToEnd) self.playSlidesLoop.setIcon(build_icon(u':/media/media_time.png')) self.playSlidesLoop.setText(UiStrings().PlaySlidesInLoop) + self.playSlidesMenu.setDefaultAction(self.playSlidesOnce) + self.playSlidesLoop.setChecked(False) else: self.playSlidesOnce.setIcon(build_icon(u':/media/media_time')) self.playSlidesOnce.setText(UiStrings().PlaySlidesToEnd) - self.playSlidesMenu.setDefaultAction(self.playSlidesOnce) - self.playSlidesLoop.setChecked(False) self.onToggleLoop() def setAudioItemsVisibility(self, visible): diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 8e8f8c458..f22fc8bf8 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -29,7 +29,7 @@ import logging -from PyQt4 import QtCore, QtGui +from PyQt4 import QtGui from openlp.core.lib import Plugin, StringContent, build_icon, translate, Settings from openlp.core.lib.ui import create_action, UiStrings diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index 7346fc697..01314ddc9 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -34,7 +34,7 @@ import logging import re from openlp.core.lib import translate, Settings -from openlp.plugins.bibles.lib.db import BiblesResourcesDB + log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 15250223c..1fa07ba86 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -30,8 +30,6 @@ import logging import os -from PyQt4 import QtCore - from openlp.core.lib import Receiver, SettingsManager, translate, Settings from openlp.core.utils import AppLocation, delete_file from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index fb9a5b9ea..3063bfa7b 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -28,7 +28,6 @@ ############################################################################### import logging -import os from PyQt4 import QtCore diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index c9328b31c..39ecb0ae2 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -28,7 +28,7 @@ ############################################################################### import re -from PyQt4 import QtGui, QtCore +from PyQt4 import QtGui from openlp.core.lib import translate from openlp.core.utils import CONTROL_CHARS, locale_direct_compare diff --git a/openlp/plugins/songs/lib/db.py b/openlp/plugins/songs/lib/db.py index 9c425b9d7..db5f59357 100644 --- a/openlp/plugins/songs/lib/db.py +++ b/openlp/plugins/songs/lib/db.py @@ -36,7 +36,6 @@ import re from sqlalchemy import Column, ForeignKey, Table, types from sqlalchemy.orm import mapper, relation, reconstructor from sqlalchemy.sql.expression import func -from PyQt4 import QtCore from openlp.core.lib.db import BaseModel, init_db diff --git a/openlp/plugins/songs/lib/dreambeamimport.py b/openlp/plugins/songs/lib/dreambeamimport.py index 759f8b055..4f8d343c4 100644 --- a/openlp/plugins/songs/lib/dreambeamimport.py +++ b/openlp/plugins/songs/lib/dreambeamimport.py @@ -30,8 +30,6 @@ The :mod:`dreambeamimport` module provides the functionality for importing DreamBeam songs into the OpenLP database. """ -import os -import sys import logging from lxml import etree, objectify @@ -46,11 +44,11 @@ class DreamBeamImport(SongImport): """ The :class:`DreamBeamImport` class provides the ability to import song files from DreamBeam. - + An example of DreamBeam xml mark-up:: - + - false 0.80 @@ -84,7 +82,7 @@ class DreamBeamImport(SongImport): * \*.xml """ - + def doImport(self): """ Receive a single file or a list of files to import. diff --git a/openlp/plugins/songs/lib/mediashoutimport.py b/openlp/plugins/songs/lib/mediashoutimport.py index 5f6cf6276..e3358c044 100644 --- a/openlp/plugins/songs/lib/mediashoutimport.py +++ b/openlp/plugins/songs/lib/mediashoutimport.py @@ -30,8 +30,6 @@ The :mod:`mediashoutimport` module provides the functionality for importing a MediaShout database into the OpenLP database. """ -import re -import os import pyodbc from openlp.core.lib import translate diff --git a/openlp/plugins/songs/lib/songproimport.py b/openlp/plugins/songs/lib/songproimport.py index 52ac79431..7556454d8 100644 --- a/openlp/plugins/songs/lib/songproimport.py +++ b/openlp/plugins/songs/lib/songproimport.py @@ -31,9 +31,7 @@ The :mod:`songproimport` module provides the functionality for importing SongPro songs into the OpenLP database. """ import re -import os -from openlp.core.lib import translate from openlp.plugins.songs.lib import strip_rtf from openlp.plugins.songs.lib.songimport import SongImport diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 90e429b9a..de2847ac5 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -5,7 +5,8 @@ from unittest import TestCase from mock import MagicMock, patch -from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string +from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string, build_icon, \ + image_to_byte, check_item_selected class TestLib(TestCase): @@ -197,3 +198,104 @@ class TestLib(TestCase): """ assert True, u'Impossible to test due to conflicts when mocking out the "open" function' + def build_icon_with_qicon_test(self): + """ + Test the build_icon() function with a QIcon instance + """ + with patch(u'openlp.core.lib.QtGui') as MockedQtGui: + # GIVEN: A mocked QIcon + MockedQtGui.QIcon = MagicMock + mocked_icon = MockedQtGui.QIcon() + + # WHEN: We pass a QIcon instance in + result = build_icon(mocked_icon) + + # THEN: The result should be our mocked QIcon + assert result is mocked_icon, u'The result should be the mocked QIcon' + + def build_icon_with_resource_test(self): + """ + Test the build_icon() function with a resource URI + """ + with patch(u'openlp.core.lib.QtGui') as MockedQtGui, \ + patch(u'openlp.core.lib.QtGui.QPixmap') as MockedQPixmap: + # GIVEN: A mocked QIcon and a mocked QPixmap + MockedQtGui.QIcon = MagicMock + MockedQtGui.QIcon.Normal = 1 + MockedQtGui.QIcon.Off = 2 + MockedQPixmap.return_value = u'mocked_pixmap' + resource_uri = u':/resource/uri' + + # WHEN: We pass a QIcon instance in + result = build_icon(resource_uri) + + # THEN: The result should be our mocked QIcon + MockedQPixmap.assert_called_with(resource_uri) + # There really should be more assert statements here but due to type checking and things they all break. The + # best we can do is to assert that we get back a MagicMock object. + assert isinstance(result, MagicMock), u'The result should be a MagicMock, because we mocked it out' + + def image_to_byte_test(self): + """ + Test the image_to_byte() function + """ + with patch(u'openlp.core.lib.QtCore') as MockedQtCore: + # GIVEN: A set of mocked-out Qt classes + mocked_byte_array = MagicMock() + MockedQtCore.QByteArray.return_value = mocked_byte_array + mocked_byte_array.toBase64.return_value = u'base64mock' + mocked_buffer = MagicMock() + MockedQtCore.QBuffer.return_value = mocked_buffer + MockedQtCore.QIODevice.WriteOnly = u'writeonly' + mocked_image = MagicMock() + + # WHEN: We convert an image to a byte array + result = image_to_byte(mocked_image) + + # THEN: We should receive a value of u'base64mock' + MockedQtCore.QByteArray.assert_called_with() + MockedQtCore.QBuffer.assert_called_with(mocked_byte_array) + mocked_buffer.open.assert_called_with(u'writeonly') + mocked_image.save.assert_called_with(mocked_buffer, "PNG") + mocked_byte_array.toBase64.assert_called_with() + assert result == u'base64mock', u'The result should be the return value of the mocked out base64 method' + + def check_item_selected_true_test(self): + """ + Test that the check_item_selected() function returns True when there are selected indexes. + """ + # GIVEN: A mocked out QtGui module and a list widget with selected indexes + MockedQtGui = patch(u'openlp.core.lib.QtGui') + mocked_list_widget = MagicMock() + mocked_list_widget.selectedIndexes.return_value = True + message = u'message' + + # WHEN: We check if there are selected items + result = check_item_selected(mocked_list_widget, message) + + # THEN: The selectedIndexes function should have been called and the result should be true + mocked_list_widget.selectedIndexes.assert_called_with() + assert result, u'The result should be True' + + def check_item_selected_false_test(self): + """ + Test that the check_item_selected() function returns False when there are no selected indexes. + """ + # GIVEN: A mocked out QtGui module and a list widget with selected indexes + with patch(u'openlp.core.lib.QtGui') as MockedQtGui, \ + patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_translate.return_value = u'mocked translate' + mocked_list_widget = MagicMock() + mocked_list_widget.selectedIndexes.return_value = False + mocked_list_widget.parent.return_value = u'parent' + message = u'message' + + # WHEN: We check if there are selected items + result = check_item_selected(mocked_list_widget, message) + + # THEN: The selectedIndexes function should have been called and the result should be true + mocked_list_widget.selectedIndexes.assert_called_with() + MockedQtGui.QMessageBox.information.assert_called_with(u'parent', u'mocked translate', 'message') + assert not result, u'The result should be False' + + diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index 677ba5b35..3b288ad4a 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -20,7 +20,7 @@ VERSE = u'The Lord said to {r}Noah{/r}: \n'\ 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456'] -TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'resources')) +TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) class TestServiceItem(TestCase): @@ -167,6 +167,7 @@ class TestServiceItem(TestCase): # THEN the service item should not be valid assert service_item.is_valid is False, u'The service item is not valid' + def serviceitem_load_custom_from_service_test(self): """ Test the Service Item - adding a custom slide from a saved service diff --git a/tests/functional/openlp_core_ui/test_starttimedialog.py b/tests/functional/openlp_core_ui/test_starttimedialog.py new file mode 100644 index 000000000..8a1c42e2d --- /dev/null +++ b/tests/functional/openlp_core_ui/test_starttimedialog.py @@ -0,0 +1,56 @@ +""" + Package to test the openlp.core.ui package. +""" +import sys + +from unittest import TestCase +from mock import MagicMock, patch +from openlp.core.ui import starttimeform +from PyQt4 import QtGui, QtTest + +class TestStartTimeDialog(TestCase): + + def setUp(self): + """ + Create the UI + """ + self.app = QtGui.QApplication(sys.argv) + self.window = QtGui.QMainWindow() + self.form = starttimeform.StartTimeForm(self.window) + + def ui_defaults_test(self): + """ + Test StartTimeDialog defaults + """ + self.assertEqual(self.form.hourSpinBox.minimum(), 0) + self.assertEqual(self.form.hourSpinBox.maximum(), 4) + self.assertEqual(self.form.minuteSpinBox.minimum(), 0) + self.assertEqual(self.form.minuteSpinBox.maximum(), 59) + self.assertEqual(self.form.secondSpinBox.minimum(), 0) + self.assertEqual(self.form.secondSpinBox.maximum(), 59) + self.assertEqual(self.form.hourFinishSpinBox.minimum(), 0) + self.assertEqual(self.form.hourFinishSpinBox.maximum(), 4) + self.assertEqual(self.form.minuteFinishSpinBox.minimum(), 0) + self.assertEqual(self.form.minuteFinishSpinBox.maximum(), 59) + self.assertEqual(self.form.secondFinishSpinBox.minimum(), 0) + self.assertEqual(self.form.secondFinishSpinBox.maximum(), 59) + + def time_display_test(self): + """ + Test StartTimeDialog display initialisation + """ + # GIVEN: A service item with with time + mocked_serviceitem = MagicMock() + mocked_serviceitem.start_time = 61 + mocked_serviceitem.end_time = 3701 + + # WHEN displaying the UI and pressing enter + self.form.item = mocked_serviceitem + with patch(u'openlp.core.lib.QtGui.QDialog') as MockedQtGuiQDialog: + MockedQtGuiQDialog.return_value = True + self.form.exec_() + + # THEN the following values are returned + self.assertEqual(self.form.hourSpinBox.value(), 1) + self.assertEqual(self.form.minuteSpinBox.value(), 1) + self.assertEqual(self.form.secondSpinBox.value(), 1) \ No newline at end of file diff --git a/tests/functional/resources/church.jpg b/tests/functional/resources/church.jpg deleted file mode 100644 index 826180870..000000000 Binary files a/tests/functional/resources/church.jpg and /dev/null differ diff --git a/tests/functional/openlp_core_lib/resources/church.jpg b/tests/resources/church.jpg similarity index 100% rename from tests/functional/openlp_core_lib/resources/church.jpg rename to tests/resources/church.jpg diff --git a/tests/functional/openlp_core_lib/resources/serviceitem_custom1.osd b/tests/resources/serviceitem_custom1.osd similarity index 100% rename from tests/functional/openlp_core_lib/resources/serviceitem_custom1.osd rename to tests/resources/serviceitem_custom1.osd diff --git a/tests/functional/openlp_core_lib/resources/serviceitem_image1.osd b/tests/resources/serviceitem_image1.osd similarity index 100% rename from tests/functional/openlp_core_lib/resources/serviceitem_image1.osd rename to tests/resources/serviceitem_image1.osd