This commit is contained in:
Raoul Snyman 2015-02-28 00:30:47 +02:00
commit f843e5a8a0
43 changed files with 5192 additions and 4728 deletions

View File

@ -1 +1 @@
2.1.2
2.1.3

View File

@ -28,9 +28,9 @@ from PyQt4 import QtCore, QtGui
class HistoryComboBox(QtGui.QComboBox):
"""
The :class:`~openlp.core.common.historycombobox.HistoryComboBox` widget emulates the QLineEdit ``returnPressed`` signal
for when the :kbd:`Enter` or :kbd:`Return` keys are pressed, and saves anything that is typed into the edit box into
its list.
The :class:`~openlp.core.common.historycombobox.HistoryComboBox` widget emulates the QLineEdit ``returnPressed``
signal for when the :kbd:`Enter` or :kbd:`Return` keys are pressed, and saves anything that is typed into the edit
box into its list.
"""
returnPressed = QtCore.pyqtSignal()

View File

@ -25,7 +25,6 @@ This class contains the core default settings.
import datetime
import logging
import os
import sys
from PyQt4 import QtCore, QtGui
@ -45,6 +44,21 @@ if is_linux():
X11_BYPASS_DEFAULT = False
def recent_files_conv(value):
"""
If the value is not a list convert it to a list
:param value: Value to convert
:return: value as a List
"""
if isinstance(value, list):
return value
elif isinstance(value, str):
return [value]
elif isinstance(value, bytes):
return [value.decode()]
return []
class Settings(QtCore.QSettings):
"""
Class to wrap QSettings.
@ -66,10 +80,9 @@ class Settings(QtCore.QSettings):
The first entry is the *old key*; it will be removed.
The second entry is the *new key*; we will add it to the config. If this is just an empty string, we just remove
the old key.
The last entry is a list containing two-pair tuples. If the list is empty, no conversion is made. Otherwise each
pair describes how to convert the old setting's value::
the old key. The last entry is a list containing two-pair tuples. If the list is empty, no conversion is made.
If the first value is callable i.e. a function, the function will be called with the old setting's value.
Otherwise each pair describes how to convert the old setting's value::
(SlideLimits.Wrap, True)
@ -334,7 +347,7 @@ class Settings(QtCore.QSettings):
('general/language', 'core/language', []),
('general/last version test', 'core/last version test', []),
('general/loop delay', 'core/loop delay', []),
('general/recent files', 'core/recent files', []),
('general/recent files', 'core/recent files', [(recent_files_conv, None)]),
('general/save prompt', 'core/save prompt', []),
('general/screen blank', 'core/screen blank', []),
('general/show splash', 'core/show splash', []),
@ -359,7 +372,7 @@ class Settings(QtCore.QSettings):
:param default_values: A dict with setting keys and their default values.
"""
Settings.__default_settings__ = dict(list(default_values.items()) + list(Settings.__default_settings__.items()))
Settings.__default_settings__.update(default_values)
@staticmethod
def set_filename(ini_file):
@ -416,7 +429,9 @@ class Settings(QtCore.QSettings):
for new, old in rules:
# If the value matches with the condition (rule), then use the provided value. This is used to
# convert values. E. g. an old value 1 results in True, and 0 in False.
if old == old_value:
if callable(new):
old_value = new(old_value)
elif old == old_value:
old_value = new
break
self.setValue(new_key, old_value)

View File

@ -145,9 +145,13 @@ def upgrade_db(url, upgrade):
version_meta = session.query(Metadata).get('version')
if version_meta is None:
# Tables have just been created - fill the version field with the most recent version
version = upgrade.__version__
if session.query(Metadata).get('dbversion'):
version = 0
else:
version = upgrade.__version__
version_meta = Metadata.populate(key='version', value=version)
session.add(version_meta)
session.commit()
else:
version = int(version_meta.value)
if version > upgrade.__version__:

View File

@ -25,6 +25,7 @@ This module contains the first time wizard.
import hashlib
import logging
import os
import socket
import time
import urllib.request
import urllib.parse
@ -61,6 +62,7 @@ class ThemeScreenshotWorker(QtCore.QObject):
self.filename = filename
self.sha256 = sha256
self.screenshot = screenshot
socket.setdefaulttimeout(CONNECTION_TIMEOUT)
super(ThemeScreenshotWorker, self).__init__()
def run(self):
@ -250,7 +252,6 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
# Download the theme screenshots
themes = self.config.get('themes', 'files').split(',')
for theme in themes:
self.application.process_events()
title = self.config.get('theme_%s' % theme, 'title')
filename = self.config.get('theme_%s' % theme, 'filename')
sha256 = self.config.get('theme_%s' % theme, 'sha256', fallback='')
@ -264,6 +265,7 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
worker.finished.connect(thread.quit)
worker.moveToThread(thread)
thread.start()
self.application.process_events()
def set_defaults(self):
"""
@ -403,8 +405,8 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
retries = 0
while True:
try:
url_file = urllib.request.urlopen(url, timeout=CONNECTION_TIMEOUT)
filename = open(f_path, "wb")
url_file = urllib.request.urlopen(url, timeout=CONNECTION_TIMEOUT)
if sha256:
hasher = hashlib.sha256()
# Download until finished or canceled.
@ -422,7 +424,7 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
log.error('sha256 sums did not match for file: {}'.format(f_path))
os.remove(f_path)
return False
except urllib.error.URLError:
except (urllib.error.URLError, socket.timeout) as err:
trace_error_handler(log)
filename.close()
os.remove(f_path)
@ -447,8 +449,8 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
for index, theme in enumerate(themes):
screenshot = self.config.get('theme_%s' % theme, 'screenshot')
item = self.themes_list_widget.item(index)
# if item:
item.setIcon(build_icon(os.path.join(gettempdir(), 'openlp', screenshot)))
if item:
item.setIcon(build_icon(os.path.join(gettempdir(), 'openlp', screenshot)))
def _get_file_size(self, url):
"""
@ -617,6 +619,7 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
songs_destination = os.path.join(gettempdir(), 'openlp')
bibles_destination = AppLocation.get_section_data_path('bibles')
themes_destination = AppLocation.get_section_data_path('themes')
missed_files = []
# Download songs
for i in range(self.songs_list_widget.count()):
item = self.songs_list_widget.item(i)
@ -626,7 +629,7 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
self.previous_size = 0
destination = os.path.join(songs_destination, str(filename))
if not self.url_get_file('%s%s' % (self.songs_url, filename), destination, sha256):
return False
missed_files.append('Song: {}'.format(filename))
# Download Bibles
bibles_iterator = QtGui.QTreeWidgetItemIterator(self.bibles_tree_widget)
while bibles_iterator.value():
@ -637,7 +640,7 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
self.previous_size = 0
if not self.url_get_file('%s%s' % (self.bibles_url, bible), os.path.join(bibles_destination, bible),
sha256):
return False
missed_files.append('Bible: {}'.format(bible))
bibles_iterator += 1
# Download themes
for i in range(self.themes_list_widget.count()):
@ -648,7 +651,20 @@ class FirstTimeForm(QtGui.QWizard, UiFirstTimeWizard, RegistryProperties):
self.previous_size = 0
if not self.url_get_file('%s%s' % (self.themes_url, theme), os.path.join(themes_destination, theme),
sha256):
return False
missed_files.append('Theme: {}'.format(theme))
if missed_files:
file_list = ''
for entry in missed_files:
file_list += '{}<br \>'.format(entry)
msg = QtGui.QMessageBox()
msg.setIcon(QtGui.QMessageBox.Warning)
msg.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'Network Error'))
msg.setText(translate('OpenLP.FirstTimeWizard', 'Unable to download some files'))
msg.setInformativeText(translate('OpenLP.FirstTimeWizard',
'The following files were not able to be '
'downloaded:<br \>{}'.format(file_list)))
msg.setStandardButtons(msg.Ok)
ans = msg.exec_()
return True
def _set_plugin_status(self, field, tag):

View File

@ -1317,6 +1317,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties):
filename = filename[0].upper() + filename[1:]
if filename in self.recent_files:
self.recent_files.remove(filename)
if not isinstance(self.recent_files, list):
self.recent_files = [self.recent_files]
self.recent_files.insert(0, filename)
while len(self.recent_files) > max_recent_files:
self.recent_files.pop()

View File

@ -517,6 +517,9 @@ class MediaController(RegistryMixin, OpenLPMixin, RegistryProperties):
used_players = get_media_players()[0]
if service_item.processor != UiStrings().Automatic:
used_players = [service_item.processor.lower()]
# If no player, we can't play
if not used_players:
return False
if controller.media_info.file_info.isFile():
suffix = '*.%s' % controller.media_info.file_info.suffix().lower()
for title in used_players:

View File

@ -114,15 +114,15 @@ class Ui_ProjectorManager(object):
text=translate('OpenLP.ProjectorManager',
'Connect to selected projector'),
icon=':/projector/projector_connect.png',
tootip=translate('OpenLP.ProjectorManager',
'Connect to selected projector'),
tooltip=translate('OpenLP.ProjectorManager',
'Connect to selected projector'),
triggers=self.on_connect_projector)
self.one_toolbar.add_toolbar_action('connect_projector_multiple',
text=translate('OpenLP.ProjectorManager',
'Connect to selected projectors'),
icon=':/projector/projector_connect_tiled.png',
tootip=translate('OpenLP.ProjectorManager',
'Connect to selected projector'),
tooltip=translate('OpenLP.ProjectorManager',
'Connect to selected projector'),
triggers=self.on_connect_projector)
self.one_toolbar.add_toolbar_action('disconnect_projector',
text=translate('OpenLP.ProjectorManager',
@ -181,15 +181,15 @@ class Ui_ProjectorManager(object):
'Blank selected projector screen'),
triggers=self.on_blank_projector)
self.one_toolbar.add_toolbar_action('show_projector',
ext=translate('OpenLP.ProjectorManager',
'Show selected projector screen'),
text=translate('OpenLP.ProjectorManager',
'Show selected projector screen'),
icon=':/projector/projector_show.png',
tooltip=translate('OpenLP.ProjectorManager',
'Show selected projector screen'),
triggers=self.on_show_projector)
self.one_toolbar.add_toolbar_action('show_projector_multiple',
ext=translate('OpenLP.ProjectorManager',
'Show selected projector screen'),
text=translate('OpenLP.ProjectorManager',
'Show selected projector screen'),
icon=':/projector/projector_show_tiled.png',
tooltip=translate('OpenLP.ProjectorManager',
'Show selected projector screen'),

View File

@ -29,6 +29,7 @@ import locale
import os
import platform
import re
import socket
import time
from shutil import which
from subprocess import Popen, PIPE
@ -394,26 +395,44 @@ def get_web_page(url, header=None, update_openlp=False):
req.add_header('User-Agent', user_agent)
if header:
req.add_header(header[0], header[1])
page = None
log.debug('Downloading URL = %s' % url)
retries = 1
while True:
retries = 0
while retries <= CONNECTION_RETRIES:
retries += 1
time.sleep(0.1)
try:
page = urllib.request.urlopen(req, timeout=CONNECTION_TIMEOUT)
log.debug('Downloaded URL = %s' % page.geturl())
except (urllib.error.URLError, ConnectionError):
log.debug('Downloaded page {}'.format(page.geturl()))
except urllib.error.URLError as err:
log.exception('URLError on {}'.format(url))
log.exception('URLError: {}'.format(err.reason))
page = None
if retries > CONNECTION_RETRIES:
log.exception('The web page could not be downloaded')
raise
else:
retries += 1
time.sleep(0.1)
continue
break
if not page:
return None
except socket.timeout:
log.exception('Socket timeout: {}'.format(url))
page = None
if retries > CONNECTION_RETRIES:
raise
except ConnectionRefusedError:
log.exception('ConnectionRefused: {}'.format(url))
page = None
if retries > CONNECTION_RETRIES:
raise
break
except ConnectionError:
log.exception('Connection error: {}'.format(url))
page = None
if retries > CONNECTION_RETRIES:
raise
except:
# Don't know what's happening, so reraise the original
raise
if update_openlp:
Registry().get('application').process_events()
if not page:
log.exception('{} could not be downloaded'.format(url))
return None
log.debug(page)
return page

View File

@ -26,7 +26,7 @@ displaying of alerts.
from PyQt4 import QtCore
from openlp.core.common import OpenLPMixin, RegistryMixin, Registry, RegistryProperties, translate
from openlp.core.common import OpenLPMixin, RegistryMixin, Registry, RegistryProperties, Settings, translate
class AlertsManager(OpenLPMixin, RegistryMixin, QtCore.QObject, RegistryProperties):
@ -70,7 +70,8 @@ class AlertsManager(OpenLPMixin, RegistryMixin, QtCore.QObject, RegistryProperti
"""
Format and request the Alert and start the timer.
"""
if not self.alert_list:
if not self.alert_list or (self.live_controller.display.screens.display_count == 1
and not Settings().value('core/display on monitor')):
return
text = self.alert_list.pop(0)
alert_tab = self.parent().settings_tab

View File

@ -164,9 +164,6 @@ class BibleDB(QtCore.QObject, Manager, RegistryProperties):
Returns the version name of the Bible.
"""
version_name = self.get_object(BibleMeta, 'name')
# Fallback to old way of naming
if not version_name:
version_name = self.get_object(BibleMeta, 'Version')
self.name = version_name.value if version_name else None
return self.name

View File

@ -24,14 +24,177 @@ The :mod:`upgrade` module provides a way for the database and schema that is the
"""
import logging
from sqlalchemy import delete, func, insert, select
log = logging.getLogger(__name__)
__version__ = 1
# TODO: When removing an upgrade path the ftw-data needs updating to the minimum supported version
def upgrade_1(session, metadata):
"""
Version 1 upgrade.
This upgrade renames a number of keys to a single naming convention.
"""
log.info('No upgrades to perform')
metadata_table = metadata.tables['metadata']
# Copy "Version" to "name" ("version" used by upgrade system)
try:
session.execute(insert(metadata_table).values(
key='name',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Version'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Version'))
except:
log.exception('Exception when upgrading Version')
# Copy "Copyright" to "copyright"
try:
session.execute(insert(metadata_table).values(
key='copyright',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Copyright'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Copyright'))
except:
log.exception('Exception when upgrading Copyright')
# Copy "Permissions" to "permissions"
try:
session.execute(insert(metadata_table).values(
key='permissions',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Permissions'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Permissions'))
except:
log.exception('Exception when upgrading Permissions')
# Copy "Bookname language" to "book_name_language"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'Bookname language'
)
).scalar()
if value_count > 0:
session.execute(insert(metadata_table).values(
key='book_name_language',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'Bookname language'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'Bookname language'))
except:
log.exception('Exception when upgrading Bookname language')
# Copy "download source" to "download_source"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'download source'
)
).scalar()
log.debug('download source: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key='download_source',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'download source'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'download source'))
except:
log.exception('Exception when upgrading download source')
# Copy "download name" to "download_name"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'download name'
)
).scalar()
log.debug('download name: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key='download_name',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'download name'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'download name'))
except:
log.exception('Exception when upgrading download name')
# Copy "proxy server" to "proxy_server"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'proxy server'
)
).scalar()
log.debug('proxy server: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key='proxy_server',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'proxy server'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'proxy server'))
except:
log.exception('Exception when upgrading proxy server')
# Copy "proxy username" to "proxy_username"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'proxy username'
)
).scalar()
log.debug('proxy username: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key='proxy_username',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'proxy username'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'proxy username'))
except:
log.exception('Exception when upgrading proxy username')
# Copy "proxy password" to "proxy_password"
try:
value_count = session.execute(
select(
[func.count(metadata_table.c.value)],
metadata_table.c.key == 'proxy password'
)
).scalar()
log.debug('proxy password: %s', value_count)
if value_count > 0:
session.execute(insert(metadata_table).values(
key='proxy_password',
value=select(
[metadata_table.c.value],
metadata_table.c.key == 'proxy password'
).as_scalar()
))
session.execute(delete(metadata_table).where(metadata_table.c.key == 'proxy password'))
except:
log.exception('Exception when upgrading proxy password')
try:
session.execute(delete(metadata_table).where(metadata_table.c.key == 'dbversion'))
except:
log.exception('Exception when deleting dbversion')
session.commit()

View File

@ -35,6 +35,7 @@ log = logging.getLogger(__name__)
__version__ = 4
# TODO: When removing an upgrade path the ftw-data needs updating to the minimum supported version
def upgrade_1(session, metadata):
"""
Version 1 upgrade.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,8 @@ Package to test the openlp.core.lib.settings package.
from unittest import TestCase
from openlp.core.common import Settings
from openlp.core.common.settings import recent_files_conv
from tests.functional import patch
from tests.helpers.testmixin import TestMixin
@ -45,6 +47,25 @@ class TestSettings(TestCase, TestMixin):
"""
self.destroy_settings()
def recent_files_conv_test(self):
"""
Test that recent_files_conv, converts various possible types of values correctly.
"""
# GIVEN: A list of possible value types and the expected results
possible_values = [(['multiple', 'values'], ['multiple', 'values']),
(['single value'], ['single value']),
('string value', ['string value']),
(b'bytes value', ['bytes value']),
([], []),
(None, [])]
# WHEN: Calling recent_files_conv with the possible values
for value, expected_result in possible_values:
actual_result = recent_files_conv(value)
# THEN: The actual result should be the same as the expected result
self.assertEqual(actual_result, expected_result)
def settings_basic_test(self):
"""
Test the Settings creation and its default usage
@ -120,3 +141,19 @@ class TestSettings(TestCase, TestMixin):
# THEN: An exception with the non-existing key should be thrown
self.assertEqual(str(cm.exception), "'core/does not exists'", 'We should get an exception')
def extend_default_settings_test(self):
"""
Test that the extend_default_settings method extends the default settings
"""
# GIVEN: A patched __default_settings__ dictionary
with patch.dict(Settings.__default_settings__,
{'test/setting 1': 1, 'test/setting 2': 2, 'test/setting 3': 3}, True):
# WHEN: Calling extend_default_settings
Settings.extend_default_settings({'test/setting 3': 4, 'test/extended 1': 1, 'test/extended 2': 2})
# THEN: The _default_settings__ dictionary_ should have the new keys
self.assertEqual(
Settings.__default_settings__, {'test/setting 1': 1, 'test/setting 2': 2, 'test/setting 3': 4,
'test/extended 1': 1, 'test/extended 2': 2})

View File

@ -23,6 +23,8 @@
Package to test the openlp.core.ui.firsttimeform package.
"""
import os
import socket
import tempfile
import urllib
from unittest import TestCase
@ -70,6 +72,11 @@ class TestFirstTimeForm(TestCase, TestMixin):
self.app.process_events = lambda: None
Registry.create()
Registry().register('application', self.app)
self.tempfile = os.path.join(tempfile.gettempdir(), 'testfile')
def tearDown(self):
if os.path.isfile(self.tempfile):
os.remove(self.tempfile)
def initialise_test(self):
"""
@ -229,3 +236,20 @@ class TestFirstTimeForm(TestCase, TestMixin):
# THEN: the critical_error_message_box should have been called
self.assertEquals(mocked_message_box.mock_calls[1][1][0], 'Network Error 407',
'first_time_form should have caught Network Error')
@patch('openlp.core.ui.firsttimeform.urllib.request.urlopen')
def socket_timeout_test(self, mocked_urlopen):
"""
Test socket timeout gets caught
"""
# GIVEN: Mocked urlopen to fake a network disconnect in the middle of a download
first_time_form = FirstTimeForm(None)
first_time_form.initialize(MagicMock())
mocked_urlopen.side_effect = socket.timeout()
# WHEN: Attempt to retrieve a file
first_time_form.url_get_file(url='http://localhost/test', f_path=self.tempfile)
# THEN: socket.timeout should have been caught
# NOTE: Test is if $tmpdir/tempfile is still there, then test fails since ftw deletes bad downloaded files
self.assertFalse(os.path.exists(self.tempfile), 'FTW url_get_file should have caught socket.timeout')

View File

@ -22,13 +22,14 @@
"""
Package to test the openlp.core.ui.thememanager package.
"""
import zipfile
import os
import shutil
from unittest import TestCase
from tempfile import mkdtemp
from PyQt4 import QtGui
from openlp.core.ui import ThemeManager
from openlp.core.common import Registry
@ -130,6 +131,46 @@ class TestThemeManager(TestCase):
# THEN: The mocked_copyfile should not have been called
self.assertTrue(mocked_copyfile.called, 'shutil.copyfile should be called')
def over_write_message_box_yes_test(self):
"""
Test that theme_manager.over_write_message_box returns True when the user clicks yes.
"""
# GIVEN: A patched QMessageBox.question and an instance of ThemeManager
with patch('openlp.core.ui.thememanager.QtGui.QMessageBox.question', return_value=QtGui.QMessageBox.Yes)\
as mocked_qmessagebox_question,\
patch('openlp.core.ui.thememanager.translate') as mocked_translate:
mocked_translate.side_effect = lambda context, text: text
theme_manager = ThemeManager(None)
# WHEN: Calling over_write_message_box with 'Theme Name'
result = theme_manager.over_write_message_box('Theme Name')
# THEN: over_write_message_box should return True and the message box should contain the theme name
self.assertTrue(result)
mocked_qmessagebox_question.assert_called_once_with(
theme_manager, 'Theme Already Exists', 'Theme Theme Name already exists. Do you want to replace it?',
ANY, ANY)
def over_write_message_box_no_test(self):
"""
Test that theme_manager.over_write_message_box returns False when the user clicks no.
"""
# GIVEN: A patched QMessageBox.question and an instance of ThemeManager
with patch('openlp.core.ui.thememanager.QtGui.QMessageBox.question', return_value=QtGui.QMessageBox.No)\
as mocked_qmessagebox_question,\
patch('openlp.core.ui.thememanager.translate') as mocked_translate:
mocked_translate.side_effect = lambda context, text: text
theme_manager = ThemeManager(None)
# WHEN: Calling over_write_message_box with 'Theme Name'
result = theme_manager.over_write_message_box('Theme Name')
# THEN: over_write_message_box should return False and the message box should contain the theme name
self.assertFalse(result)
mocked_qmessagebox_question.assert_called_once_with(
theme_manager, 'Theme Already Exists', 'Theme Theme Name already exists. Do you want to replace it?',
ANY, ANY)
def unzip_theme_test(self):
"""
Test that unzipping of themes works

View File

@ -28,7 +28,7 @@ from openlp.core.ui.media.mediacontroller import MediaController
from openlp.core.ui.media.mediaplayer import MediaPlayer
from openlp.core.common import Registry
from tests.functional import MagicMock
from tests.functional import MagicMock, patch
from tests.helpers.testmixin import TestMixin
@ -58,3 +58,26 @@ class TestMediaController(TestCase, TestMixin):
'Video extensions should be the same')
self.assertListEqual(media_player.audio_extensions_list, media_controller.audio_extensions_list,
'Audio extensions should be the same')
def check_file_type_no_players_test(self):
"""
Test that we don't try to play media when no players available
"""
# GIVEN: A mocked UiStrings, get_media_players, controller, display and service_item
with patch('openlp.core.ui.media.mediacontroller.get_media_players') as mocked_get_media_players,\
patch('openlp.core.ui.media.mediacontroller.UiStrings') as mocked_uistrings:
mocked_get_media_players.return_value = ([], '')
mocked_ret_uistrings = MagicMock()
mocked_ret_uistrings.Automatic = 1
mocked_uistrings.return_value = mocked_ret_uistrings
media_controller = MediaController()
mocked_controller = MagicMock()
mocked_display = MagicMock()
mocked_service_item = MagicMock()
mocked_service_item.processor = 1
# WHEN: calling _check_file_type when no players exists
ret = media_controller._check_file_type(mocked_controller, mocked_display, mocked_service_item)
# THEN: it should return False
self.assertFalse(ret, '_check_file_type should return False when no mediaplayers are available.')

View File

@ -633,7 +633,6 @@ class TestSongSelectFileImport(TestCase, TestMixin):
def setUp(self):
"""
Initial setups
:return:
"""
Registry.create()
test_song_name = 'TestSong'
@ -646,7 +645,6 @@ class TestSongSelectFileImport(TestCase, TestMixin):
def songselect_import_bin_file_test(self):
"""
Verify import SongSelect BIN file parses file properly
:return:
"""
# GIVEN: Text file to import and mocks
copyright_bin = '2011 OpenLP Programmer One (Admin. by OpenLP One) | ' \
@ -668,10 +666,9 @@ class TestSongSelectFileImport(TestCase, TestMixin):
self.assertEquals(song_import.topics, self.topics, 'Theme(s) should match')
self.assertEquals(song_import.verses, verses_bin, 'Verses should match with test verses')
def songselect_import_txt_file_test(self):
def songselect_import_text_file_test(self):
"""
Verify import SongSelect TXT file parses file properly
:return:
Verify import SongSelect TEXT file parses file properly
"""
# GIVEN: Text file to import and mocks
copyright_txt = '© 2011 OpenLP Programmer One (Admin. by OpenLP One)'

View File

@ -45,7 +45,8 @@ TAGS = [
['2.0', '2118'],
['2.1.0', '2119'],
['2.1.1', '2438'],
['2.1.2', '2488']
['2.1.2', '2488'],
['2.1.3', '2513']
]
# Depending on the repository, we sometimes have the 2.0.x tags in the repo too. They come up with a revision number of
# "?", which I suspect is due to the fact that we're using shared repositories. This regular expression matches all