forked from openlp/openlp
test fixes
This commit is contained in:
parent
3e7370c656
commit
c38c576f94
@ -28,15 +28,15 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
"""
|
"""
|
||||||
The :mod:`http` module contains the API web server. This is a lightweight web
|
The :mod:`http` module contains the API web server. This is a lightweight web server used by remotes to interact
|
||||||
server used by remotes to interact with OpenLP. It uses JSON to communicate with
|
with OpenLP. It uses JSON to communicate with the remotes.
|
||||||
the remotes.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import ssl
|
import ssl
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ log = logging.getLogger(__name__)
|
|||||||
class CustomHandler(BaseHTTPRequestHandler, HttpRouter):
|
class CustomHandler(BaseHTTPRequestHandler, HttpRouter):
|
||||||
"""
|
"""
|
||||||
Stateless session handler to handle the HTTP request and process it.
|
Stateless session handler to handle the HTTP request and process it.
|
||||||
This class handles just the overrides to the base methods and the logic to invoke the
|
This class handles just the overrides to the base methods and the logic to invoke the methods within the HttpRouter
|
||||||
methods within the HttpRouter class.
|
class.
|
||||||
DO not try change the structure as this is as per the documentation.
|
DO not try change the structure as this is as per the documentation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -116,9 +116,20 @@ class OpenLPServer():
|
|||||||
log.debug('Started ssl httpd...')
|
log.debug('Started ssl httpd...')
|
||||||
else:
|
else:
|
||||||
port = Settings().value(self.settings_section + '/port')
|
port = Settings().value(self.settings_section + '/port')
|
||||||
self.httpd = ThreadingHTTPServer((address, port), CustomHandler)
|
loop = 1
|
||||||
|
while loop < 3:
|
||||||
|
try:
|
||||||
|
self.httpd = ThreadingHTTPServer((address, port), CustomHandler)
|
||||||
|
except OSError:
|
||||||
|
loop += 1
|
||||||
|
time.sleep(0.1)
|
||||||
|
except:
|
||||||
|
log.error('Failed to start server ')
|
||||||
log.debug('Started non ssl httpd...')
|
log.debug('Started non ssl httpd...')
|
||||||
self.httpd.serve_forever()
|
if hasattr(self, 'httpd') and self.httpd:
|
||||||
|
self.httpd.serve_forever()
|
||||||
|
else:
|
||||||
|
log.debug('Failed to start server')
|
||||||
|
|
||||||
def stop_server(self):
|
def stop_server(self):
|
||||||
"""
|
"""
|
||||||
|
@ -32,4 +32,3 @@ The :mod:`resources` module contains a bunch of resources for OpenLP.
|
|||||||
DO NOT REMOVE THIS FILE, IT IS REQUIRED FOR INCLUDING THE RESOURCES ON SOME
|
DO NOT REMOVE THIS FILE, IT IS REQUIRED FOR INCLUDING THE RESOURCES ON SOME
|
||||||
PLATFORMS!
|
PLATFORMS!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -52,7 +52,9 @@ This is done easily via the ``-d``, ``-p`` and ``-u`` options::
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import urllib.request, urllib.error, urllib.parse
|
import urllib.request
|
||||||
|
import urllib.error
|
||||||
|
import urllib.parse
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
@ -70,6 +72,7 @@ quiet_mode = False
|
|||||||
username = ''
|
username = ''
|
||||||
password = ''
|
password = ''
|
||||||
|
|
||||||
|
|
||||||
class Command(object):
|
class Command(object):
|
||||||
"""
|
"""
|
||||||
Provide an enumeration of commands.
|
Provide an enumeration of commands.
|
||||||
@ -80,6 +83,7 @@ class Command(object):
|
|||||||
Update = 4
|
Update = 4
|
||||||
Generate = 5
|
Generate = 5
|
||||||
|
|
||||||
|
|
||||||
class CommandStack(object):
|
class CommandStack(object):
|
||||||
"""
|
"""
|
||||||
This class provides an iterable stack.
|
This class provides an iterable stack.
|
||||||
@ -134,13 +138,13 @@ class CommandStack(object):
|
|||||||
results.append(str((item['command'], )))
|
results.append(str((item['command'], )))
|
||||||
return '[%s]' % ', '.join(results)
|
return '[%s]' % ', '.join(results)
|
||||||
|
|
||||||
|
|
||||||
def print_quiet(text, linefeed=True):
|
def print_quiet(text, linefeed=True):
|
||||||
"""
|
"""
|
||||||
This method checks to see if we are in quiet mode, and if not prints
|
This method checks to see if we are in quiet mode, and if not prints ``text`` out.
|
||||||
``text`` out.
|
|
||||||
|
|
||||||
``text``
|
:param text: The text to print.
|
||||||
The text to print.
|
:param linefeed: Linefeed required
|
||||||
"""
|
"""
|
||||||
global quiet_mode
|
global quiet_mode
|
||||||
if not quiet_mode:
|
if not quiet_mode:
|
||||||
@ -149,33 +153,33 @@ def print_quiet(text, linefeed=True):
|
|||||||
else:
|
else:
|
||||||
print(text, end=' ')
|
print(text, end=' ')
|
||||||
|
|
||||||
|
|
||||||
def print_verbose(text):
|
def print_verbose(text):
|
||||||
"""
|
"""
|
||||||
This method checks to see if we are in verbose mode, and if so prints
|
This method checks to see if we are in verbose mode, and if so prints ``text`` out.
|
||||||
``text`` out.
|
|
||||||
|
|
||||||
``text``
|
:param text: The text to print.
|
||||||
The text to print.
|
|
||||||
"""
|
"""
|
||||||
global verbose_mode, quiet_mode
|
global verbose_mode, quiet_mode
|
||||||
if not quiet_mode and verbose_mode:
|
if not quiet_mode and verbose_mode:
|
||||||
print(' %s' % text)
|
print(' %s' % text)
|
||||||
|
|
||||||
|
|
||||||
def run(command):
|
def run(command):
|
||||||
"""
|
"""
|
||||||
This method runs an external application.
|
This method runs an external application.
|
||||||
|
|
||||||
``command``
|
:param command: The command to run.
|
||||||
The command to run.
|
|
||||||
"""
|
"""
|
||||||
print_verbose(command)
|
print_verbose(command)
|
||||||
process = QtCore.QProcess()
|
process = QtCore.QProcess()
|
||||||
process.start(command)
|
process.start(command)
|
||||||
while (process.waitForReadyRead()):
|
while process.waitForReadyRead():
|
||||||
print_verbose('ReadyRead: %s' % QtCore.QString(process.readAll()))
|
print_verbose('ReadyRead: %s' % QtCore.QString(process.readAll()))
|
||||||
print_verbose('Error(s):\n%s' % process.readAllStandardError())
|
print_verbose('Error(s):\n%s' % process.readAllStandardError())
|
||||||
print_verbose('Output:\n%s' % process.readAllStandardOutput())
|
print_verbose('Output:\n%s' % process.readAllStandardOutput())
|
||||||
|
|
||||||
|
|
||||||
def download_translations():
|
def download_translations():
|
||||||
"""
|
"""
|
||||||
This method downloads the translation files from the Pootle server.
|
This method downloads the translation files from the Pootle server.
|
||||||
@ -190,9 +194,8 @@ def download_translations():
|
|||||||
password = getpass(' Transifex password: ')
|
password = getpass(' Transifex password: ')
|
||||||
# First get the list of languages
|
# First get the list of languages
|
||||||
url = SERVER_URL + 'resource/ents/'
|
url = SERVER_URL + 'resource/ents/'
|
||||||
base64string = base64.encodestring(
|
base64string = base64.encodbytes('%s:%s' % (username, password))[:-1]
|
||||||
'%s:%s' % (username, password))[:-1]
|
auth_header = 'Basic %s' % base64string
|
||||||
auth_header = 'Basic %s' % base64string
|
|
||||||
request = urllib.request.Request(url + '?details')
|
request = urllib.request.Request(url + '?details')
|
||||||
request.add_header('Authorization', auth_header)
|
request.add_header('Authorization', auth_header)
|
||||||
print_verbose('Downloading list of languages from: %s' % url)
|
print_verbose('Downloading list of languages from: %s' % url)
|
||||||
@ -207,8 +210,7 @@ def download_translations():
|
|||||||
lang_url = url + 'translation/%s/?file' % language
|
lang_url = url + 'translation/%s/?file' % language
|
||||||
request = urllib.request.Request(lang_url)
|
request = urllib.request.Request(lang_url)
|
||||||
request.add_header('Authorization', auth_header)
|
request.add_header('Authorization', auth_header)
|
||||||
filename = os.path.join(os.path.abspath('..'), 'resources', 'i18n',
|
filename = os.path.join(os.path.abspath('..'), 'resources', 'i18n', language + '.ts')
|
||||||
language + '.ts')
|
|
||||||
print_verbose('Get Translation File: %s' % filename)
|
print_verbose('Get Translation File: %s' % filename)
|
||||||
response = urllib.request.urlopen(request)
|
response = urllib.request.urlopen(request)
|
||||||
fd = open(filename, 'w')
|
fd = open(filename, 'w')
|
||||||
@ -217,10 +219,10 @@ def download_translations():
|
|||||||
print_quiet(' Done.')
|
print_quiet(' Done.')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def prepare_project():
|
def prepare_project():
|
||||||
"""
|
"""
|
||||||
This method creates the project file needed to update the translation files
|
This method creates the project file needed to update the translation files and compile them into .qm files.
|
||||||
and compile them into .qm files.
|
|
||||||
"""
|
"""
|
||||||
print_quiet('Generating the openlp.pro file')
|
print_quiet('Generating the openlp.pro file')
|
||||||
lines = []
|
lines = []
|
||||||
@ -229,9 +231,9 @@ def prepare_project():
|
|||||||
print_verbose('Starting directory: %s' % start_dir)
|
print_verbose('Starting directory: %s' % start_dir)
|
||||||
for root, dirs, files in os.walk(start_dir):
|
for root, dirs, files in os.walk(start_dir):
|
||||||
for file in files:
|
for file in files:
|
||||||
path = root.replace(start_dir, '').replace('\\', '/') #.replace(u'..', u'.')
|
path = root.replace(start_dir, '').replace('\\', '/')
|
||||||
if file.startswith('hook-') or file.startswith('test_'):
|
if file.startswith('hook-') or file.startswith('test_'):
|
||||||
continue
|
continue
|
||||||
ignore = False
|
ignore = False
|
||||||
for ignored_path in IGNORED_PATHS:
|
for ignored_path in IGNORED_PATHS:
|
||||||
if path.startswith(ignored_path):
|
if path.startswith(ignored_path):
|
||||||
@ -263,6 +265,7 @@ def prepare_project():
|
|||||||
file.close()
|
file.close()
|
||||||
print_quiet(' Done.')
|
print_quiet(' Done.')
|
||||||
|
|
||||||
|
|
||||||
def update_translations():
|
def update_translations():
|
||||||
print_quiet('Update the translation files')
|
print_quiet('Update the translation files')
|
||||||
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
|
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
|
||||||
@ -273,11 +276,12 @@ def update_translations():
|
|||||||
run('pylupdate4 -verbose -noobsolete openlp.pro')
|
run('pylupdate4 -verbose -noobsolete openlp.pro')
|
||||||
os.chdir(os.path.abspath('scripts'))
|
os.chdir(os.path.abspath('scripts'))
|
||||||
|
|
||||||
|
|
||||||
def generate_binaries():
|
def generate_binaries():
|
||||||
print_quiet('Generate the related *.qm files')
|
print_quiet('Generate the related *.qm files')
|
||||||
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
|
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
|
||||||
print('You have not generated a project file yet, please run this script with the -p option. It is also ' +
|
print('You have not generated a project file yet, please run this script with the -p option. It is also ' +
|
||||||
'recommended that you this script with the -u option to update the translation files as well.')
|
'recommended that you this script with the -u option to update the translation files as well.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
os.chdir(os.path.abspath('..'))
|
os.chdir(os.path.abspath('..'))
|
||||||
@ -290,12 +294,11 @@ def create_translation():
|
|||||||
This method opens a browser to the OpenLP project page at Transifex so
|
This method opens a browser to the OpenLP project page at Transifex so
|
||||||
that the user can request a new language.
|
that the user can request a new language.
|
||||||
"""
|
"""
|
||||||
print_quiet('Please request a new language at the OpenLP project on '
|
print_quiet('Please request a new language at the OpenLP project on Transifex.')
|
||||||
'Transifex.')
|
webbrowser.open('https://www.transifex.net/projects/p/openlp/resource/ents/')
|
||||||
webbrowser.open('https://www.transifex.net/projects/p/openlp/'
|
|
||||||
'resource/ents/')
|
|
||||||
print_quiet('Opening browser to OpenLP project...')
|
print_quiet('Opening browser to OpenLP project...')
|
||||||
|
|
||||||
|
|
||||||
def process_stack(command_stack):
|
def process_stack(command_stack):
|
||||||
"""
|
"""
|
||||||
This method looks at the commands in the command stack, and processes them
|
This method looks at the commands in the command stack, and processes them
|
||||||
@ -323,6 +326,7 @@ def process_stack(command_stack):
|
|||||||
else:
|
else:
|
||||||
print_quiet('No commands to process.')
|
print_quiet('No commands to process.')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global verbose_mode, quiet_mode, username, password
|
global verbose_mode, quiet_mode, username, password
|
||||||
# Set up command line options.
|
# Set up command line options.
|
||||||
@ -331,23 +335,23 @@ def main():
|
|||||||
'This script is used to manage OpenLP\'s translation files.'
|
'This script is used to manage OpenLP\'s translation files.'
|
||||||
parser = OptionParser(usage=usage)
|
parser = OptionParser(usage=usage)
|
||||||
parser.add_option('-U', '--username', dest='username', metavar='USERNAME',
|
parser.add_option('-U', '--username', dest='username', metavar='USERNAME',
|
||||||
help='Transifex username, used for authentication')
|
help='Transifex username, used for authentication')
|
||||||
parser.add_option('-P', '--password', dest='password', metavar='PASSWORD',
|
parser.add_option('-P', '--password', dest='password', metavar='PASSWORD',
|
||||||
help='Transifex password, used for authentication')
|
help='Transifex password, used for authentication')
|
||||||
parser.add_option('-d', '--download-ts', dest='download',
|
parser.add_option('-d', '--download-ts', dest='download',
|
||||||
action='store_true', help='download language files from Transifex')
|
action='store_true', help='download language files from Transifex')
|
||||||
parser.add_option('-c', '--create', dest='create', action='store_true',
|
parser.add_option('-c', '--create', dest='create', action='store_true',
|
||||||
help='go to Transifex to request a new translation file')
|
help='go to Transifex to request a new translation file')
|
||||||
parser.add_option('-p', '--prepare', dest='prepare', action='store_true',
|
parser.add_option('-p', '--prepare', dest='prepare', action='store_true',
|
||||||
help='generate a project file, used to update the translations')
|
help='generate a project file, used to update the translations')
|
||||||
parser.add_option('-u', '--update', action='store_true', dest='update',
|
parser.add_option('-u', '--update', action='store_true', dest='update',
|
||||||
help='update translation files (needs a project file)')
|
help='update translation files (needs a project file)')
|
||||||
parser.add_option('-g', '--generate', dest='generate', action='store_true',
|
parser.add_option('-g', '--generate', dest='generate', action='store_true',
|
||||||
help='compile .ts files into .qm files')
|
help='compile .ts files into .qm files')
|
||||||
parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
|
parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
|
||||||
help='show extra information while processing translations')
|
help='show extra information while processing translations')
|
||||||
parser.add_option('-q', '--quiet', dest='quiet', action='store_true',
|
parser.add_option('-q', '--quiet', dest='quiet', action='store_true',
|
||||||
help='suppress all output other than errors')
|
help='suppress all output other than errors')
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
# Create and populate the command stack
|
# Create and populate the command stack
|
||||||
command_stack = CommandStack()
|
command_stack = CommandStack()
|
||||||
|
10
setup.py
10
setup.py
@ -106,9 +106,9 @@ try:
|
|||||||
# If they are equal, then this tree is tarball with the source for the release. We do not want the revision number
|
# If they are equal, then this tree is tarball with the source for the release. We do not want the revision number
|
||||||
# in the version string.
|
# in the version string.
|
||||||
if tree_revision == tag_revision:
|
if tree_revision == tag_revision:
|
||||||
version_string = tag_version
|
version_string = tag_version
|
||||||
else:
|
else:
|
||||||
version_string = '%s-bzr%s' % (tag_version, tree_revision)
|
version_string = '%s-bzr%s' % (tag_version, tree_revision)
|
||||||
ver_file = open(VERSION_FILE, 'w')
|
ver_file = open(VERSION_FILE, 'w')
|
||||||
ver_file.write(version_string)
|
ver_file.write(version_string)
|
||||||
except:
|
except:
|
||||||
@ -123,7 +123,9 @@ setup(
|
|||||||
version=version_string,
|
version=version_string,
|
||||||
description="Open source Church presentation and lyrics projection application.",
|
description="Open source Church presentation and lyrics projection application.",
|
||||||
long_description="""\
|
long_description="""\
|
||||||
OpenLP (previously openlp.org) is free church presentation software, or lyrics projection software, used to display slides of songs, Bible verses, videos, images, and even presentations (if PowerPoint is installed) for church worship using a computer and a data projector.""",
|
OpenLP (previously openlp.org) is free church presentation software, or lyrics projection software, used to display
|
||||||
|
slides of songs, Bible verses, videos, images, and even presentations (if PowerPoint is installed) for church worship
|
||||||
|
using a computer and a data projector.""",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 4 - Beta',
|
'Development Status :: 4 - Beta',
|
||||||
'Environment :: MacOS X',
|
'Environment :: MacOS X',
|
||||||
@ -158,7 +160,7 @@ OpenLP (previously openlp.org) is free church presentation software, or lyrics p
|
|||||||
'Topic :: Multimedia :: Sound/Audio',
|
'Topic :: Multimedia :: Sound/Audio',
|
||||||
'Topic :: Multimedia :: Video',
|
'Topic :: Multimedia :: Video',
|
||||||
'Topic :: Religion'
|
'Topic :: Religion'
|
||||||
], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
|
], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
|
||||||
keywords='open source church presentation lyrics projection song bible display project',
|
keywords='open source church presentation lyrics projection song bible display project',
|
||||||
author='Raoul Snyman',
|
author='Raoul Snyman',
|
||||||
author_email='raoulsnyman@openlp.org',
|
author_email='raoulsnyman@openlp.org',
|
||||||
|
@ -54,9 +54,9 @@ class TestAppLocation(TestCase):
|
|||||||
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
|
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
|
||||||
mocked_settings = mocked_class.return_value
|
mocked_settings = mocked_class.return_value
|
||||||
mocked_settings.contains.return_value = False
|
mocked_settings.contains.return_value = False
|
||||||
mocked_get_directory.return_value = os.path.join('test','dir')
|
mocked_get_directory.return_value = os.path.join('test', 'dir')
|
||||||
mocked_check_directory_exists.return_value = True
|
mocked_check_directory_exists.return_value = True
|
||||||
mocked_os.path.normpath.return_value = os.path.join('test','dir')
|
mocked_os.path.normpath.return_value = os.path.join('test', 'dir')
|
||||||
|
|
||||||
# WHEN: we call AppLocation.get_data_path()
|
# WHEN: we call AppLocation.get_data_path()
|
||||||
data_path = AppLocation.get_data_path()
|
data_path = AppLocation.get_data_path()
|
||||||
@ -64,8 +64,8 @@ class TestAppLocation(TestCase):
|
|||||||
# THEN: check that all the correct methods were called, and the result is correct
|
# THEN: check that all the correct methods were called, and the result is correct
|
||||||
mocked_settings.contains.assert_called_with('advanced/data path')
|
mocked_settings.contains.assert_called_with('advanced/data path')
|
||||||
mocked_get_directory.assert_called_with(AppLocation.DataDir)
|
mocked_get_directory.assert_called_with(AppLocation.DataDir)
|
||||||
mocked_check_directory_exists.assert_called_with(os.path.join('test','dir'))
|
mocked_check_directory_exists.assert_called_with(os.path.join('test', 'dir'))
|
||||||
self.assertEqual(os.path.join('test','dir'), data_path, 'Result should be "test/dir"')
|
self.assertEqual(os.path.join('test', 'dir'), data_path, 'Result should be "test/dir"')
|
||||||
|
|
||||||
def get_data_path_with_custom_location_test(self):
|
def get_data_path_with_custom_location_test(self):
|
||||||
"""
|
"""
|
||||||
@ -110,14 +110,14 @@ class TestAppLocation(TestCase):
|
|||||||
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
|
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
|
||||||
patch('openlp.core.common.applocation.os.listdir') as mocked_listdir:
|
patch('openlp.core.common.applocation.os.listdir') as mocked_listdir:
|
||||||
# GIVEN: Our mocked modules/methods.
|
# GIVEN: Our mocked modules/methods.
|
||||||
mocked_get_data_path.return_value = os.path.join('test','dir')
|
mocked_get_data_path.return_value = os.path.join('test', 'dir')
|
||||||
mocked_listdir.return_value = copy.deepcopy(FILE_LIST)
|
mocked_listdir.return_value = copy.deepcopy(FILE_LIST)
|
||||||
|
|
||||||
# When: Get the list of files.
|
# When: Get the list of files.
|
||||||
result = AppLocation.get_files('section', '.mp3')
|
result = AppLocation.get_files('section', '.mp3')
|
||||||
|
|
||||||
# Then: Check if the section parameter was used correctly.
|
# Then: Check if the section parameter was used correctly.
|
||||||
mocked_listdir.assert_called_with(os.path.join('test','dir','section'))
|
mocked_listdir.assert_called_with(os.path.join('test', 'dir', 'section'))
|
||||||
|
|
||||||
# Then: check if the file lists are identical.
|
# Then: check if the file lists are identical.
|
||||||
self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.')
|
self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.')
|
||||||
@ -129,15 +129,15 @@ class TestAppLocation(TestCase):
|
|||||||
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
|
with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \
|
||||||
patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists:
|
patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists:
|
||||||
# GIVEN: A mocked out AppLocation.get_data_path()
|
# GIVEN: A mocked out AppLocation.get_data_path()
|
||||||
mocked_get_data_path.return_value = os.path.join('test','dir')
|
mocked_get_data_path.return_value = os.path.join('test', 'dir')
|
||||||
mocked_check_directory_exists.return_value = True
|
mocked_check_directory_exists.return_value = True
|
||||||
|
|
||||||
# WHEN: we call AppLocation.get_data_path()
|
# WHEN: we call AppLocation.get_data_path()
|
||||||
data_path = AppLocation.get_section_data_path('section')
|
data_path = AppLocation.get_section_data_path('section')
|
||||||
|
|
||||||
# THEN: check that all the correct methods were called, and the result is correct
|
# THEN: check that all the correct methods were called, and the result is correct
|
||||||
mocked_check_directory_exists.assert_called_with(os.path.join('test','dir','section'))
|
mocked_check_directory_exists.assert_called_with(os.path.join('test', 'dir', 'section'))
|
||||||
self.assertEqual(os.path.join('test','dir','section'), data_path, 'Result should be "test/dir/section"')
|
self.assertEqual(os.path.join('test', 'dir', 'section'), data_path, 'Result should be "test/dir/section"')
|
||||||
|
|
||||||
def get_directory_for_app_dir_test(self):
|
def get_directory_for_app_dir_test(self):
|
||||||
"""
|
"""
|
||||||
@ -145,13 +145,13 @@ class TestAppLocation(TestCase):
|
|||||||
"""
|
"""
|
||||||
# GIVEN: A mocked out _get_frozen_path function
|
# GIVEN: A mocked out _get_frozen_path function
|
||||||
with patch('openlp.core.common.applocation.get_frozen_path') as mocked_get_frozen_path:
|
with patch('openlp.core.common.applocation.get_frozen_path') as mocked_get_frozen_path:
|
||||||
mocked_get_frozen_path.return_value = os.path.join('app','dir')
|
mocked_get_frozen_path.return_value = os.path.join('app', 'dir')
|
||||||
|
|
||||||
# WHEN: We call AppLocation.get_directory
|
# WHEN: We call AppLocation.get_directory
|
||||||
directory = AppLocation.get_directory(AppLocation.AppDir)
|
directory = AppLocation.get_directory(AppLocation.AppDir)
|
||||||
|
|
||||||
# THEN: check that the correct directory is returned
|
# THEN: check that the correct directory is returned
|
||||||
self.assertEqual(os.path.join('app','dir'), directory, 'Directory should be "app/dir"')
|
self.assertEqual(os.path.join('app', 'dir'), directory, 'Directory should be "app/dir"')
|
||||||
|
|
||||||
def get_directory_for_plugins_dir_test(self):
|
def get_directory_for_plugins_dir_test(self):
|
||||||
"""
|
"""
|
||||||
|
@ -28,4 +28,4 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
"""
|
"""
|
||||||
Package to test the openlp.core.lib package.
|
Package to test the openlp.core.lib package.
|
||||||
"""
|
"""
|
||||||
|
@ -52,7 +52,7 @@ class TestDB(TestCase):
|
|||||||
with patch('openlp.core.lib.db.create_engine') as mocked_create_engine, \
|
with patch('openlp.core.lib.db.create_engine') as mocked_create_engine, \
|
||||||
patch('openlp.core.lib.db.MetaData') as MockedMetaData, \
|
patch('openlp.core.lib.db.MetaData') as MockedMetaData, \
|
||||||
patch('openlp.core.lib.db.sessionmaker') as mocked_sessionmaker, \
|
patch('openlp.core.lib.db.sessionmaker') as mocked_sessionmaker, \
|
||||||
patch('openlp.core.lib.db.scoped_session') as mocked_scoped_session:
|
patch('openlp.core.lib.db.scoped_session') as mocked_scoped_session:
|
||||||
mocked_engine = MagicMock()
|
mocked_engine = MagicMock()
|
||||||
mocked_metadata = MagicMock()
|
mocked_metadata = MagicMock()
|
||||||
mocked_sessionmaker_object = MagicMock()
|
mocked_sessionmaker_object = MagicMock()
|
||||||
|
@ -42,7 +42,8 @@ class TestFileDialog(TestCase):
|
|||||||
# THEN: The returned value should be an empty QStringList and os.path.exists should not have been called
|
# THEN: The returned value should be an empty QStringList and os.path.exists should not have been called
|
||||||
assert not self.mocked_os.path.exists.called
|
assert not self.mocked_os.path.exists.called
|
||||||
self.assertEqual(result, [],
|
self.assertEqual(result, [],
|
||||||
'FileDialog.getOpenFileNames should return and empty list when QFileDialog.getOpenFileNames is canceled')
|
'FileDialog.getOpenFileNames should return and empty list when QFileDialog.getOpenFileNames '
|
||||||
|
'is canceled')
|
||||||
|
|
||||||
def returned_file_list_test(self):
|
def returned_file_list_test(self):
|
||||||
"""
|
"""
|
||||||
@ -70,5 +71,5 @@ class TestFileDialog(TestCase):
|
|||||||
self.mocked_os.path.exists.assert_callde_with('/non-existing')
|
self.mocked_os.path.exists.assert_callde_with('/non-existing')
|
||||||
self.mocked_os.path.exists.assert_callde_with('/non-existing')
|
self.mocked_os.path.exists.assert_callde_with('/non-existing')
|
||||||
self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FileNotFound,
|
self.mocked_qt_gui.QmessageBox.information.called_with(self.mocked_parent, UiStrings().FileNotFound,
|
||||||
UiStrings().FileNotFoundMessage % '/non-existing')
|
UiStrings().FileNotFoundMessage % '/non-existing')
|
||||||
self.assertEqual(result, ['/Valid File', '/url encoded file #1'], 'The returned file list is incorrect')
|
self.assertEqual(result, ['/Valid File', '/url encoded file #1'], 'The returned file list is incorrect')
|
||||||
|
@ -108,4 +108,3 @@ class TestFormattingTags(TestCase):
|
|||||||
|
|
||||||
# THEN: The lists should now be identical.
|
# THEN: The lists should now be identical.
|
||||||
assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'
|
assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'
|
||||||
|
|
||||||
|
@ -321,4 +321,3 @@ class Htmbuilder(TestCase):
|
|||||||
|
|
||||||
# THEN: THE css should be the same.
|
# THEN: THE css should be the same.
|
||||||
assert FOOTER_CSS == css, 'The footer strings should be equal.'
|
assert FOOTER_CSS == css, 'The footer strings should be equal.'
|
||||||
|
|
||||||
|
@ -311,8 +311,8 @@ class TestLib(TestCase):
|
|||||||
mocked_buffer.open.assert_called_with('writeonly')
|
mocked_buffer.open.assert_called_with('writeonly')
|
||||||
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
|
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
|
||||||
mocked_byte_array.toBase64.assert_called_with()
|
mocked_byte_array.toBase64.assert_called_with()
|
||||||
self.assertEqual('base64mock', result,
|
self.assertEqual('base64mock', result, 'The result should be the return value of the mocked out '
|
||||||
'The result should be the return value of the mocked out base64 method')
|
'base64 method')
|
||||||
|
|
||||||
def create_thumb_with_size_test(self):
|
def create_thumb_with_size_test(self):
|
||||||
"""
|
"""
|
||||||
|
@ -86,4 +86,4 @@ class TestRenderer(TestCase):
|
|||||||
self.assertEqual(renderer.width, 1024, 'The base renderer should be a live controller')
|
self.assertEqual(renderer.width, 1024, 'The base renderer should be a live controller')
|
||||||
self.assertEqual(renderer.height, 768, 'The base renderer should be a live controller')
|
self.assertEqual(renderer.height, 768, 'The base renderer should be a live controller')
|
||||||
self.assertEqual(renderer.screen_ratio, 0.75, 'The base renderer should be a live controller')
|
self.assertEqual(renderer.screen_ratio, 0.75, 'The base renderer should be a live controller')
|
||||||
self.assertEqual(renderer.footer_start, 691, 'The base renderer should be a live controller')
|
self.assertEqual(renderer.footer_start, 691, 'The base renderer should be a live controller')
|
||||||
|
@ -69,4 +69,3 @@ class TestTheme(TestCase):
|
|||||||
'The theme should have a font_footer_name of Arial')
|
'The theme should have a font_footer_name of Arial')
|
||||||
self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false')
|
self.assertTrue(default_theme.font_main_bold is False, 'The theme should have a font_main_bold of false')
|
||||||
self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')
|
self.assertTrue(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')
|
||||||
|
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -26,4 +26,3 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -116,7 +116,8 @@ class TestBSExtract(TestCase):
|
|||||||
self.mock_get_soup_for_bible_ref.assert_called_once_with(
|
self.mock_get_soup_for_bible_ref.assert_called_once_with(
|
||||||
'http://m.bibleserver.com/overlay/selectBook?translation=NIV')
|
'http://m.bibleserver.com/overlay/selectBook?translation=NIV')
|
||||||
self.assertIsNone(result,
|
self.assertIsNone(result,
|
||||||
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a false value')
|
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a '
|
||||||
|
'false value')
|
||||||
|
|
||||||
def get_books_from_http_no_content_test(self):
|
def get_books_from_http_no_content_test(self):
|
||||||
"""
|
"""
|
||||||
@ -146,7 +147,8 @@ class TestBSExtract(TestCase):
|
|||||||
self.mock_log.error.assert_called_once_with('No books found in the Bibleserver response.')
|
self.mock_log.error.assert_called_once_with('No books found in the Bibleserver response.')
|
||||||
self.mock_send_error_message.assert_called_once_with('parse')
|
self.mock_send_error_message.assert_called_once_with('parse')
|
||||||
self.assertIsNone(result,
|
self.assertIsNone(result,
|
||||||
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a false value')
|
'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a '
|
||||||
|
'false value')
|
||||||
|
|
||||||
def get_books_from_http_content_test(self):
|
def get_books_from_http_content_test(self):
|
||||||
"""
|
"""
|
||||||
|
@ -85,5 +85,3 @@ class TestLib(TestCase):
|
|||||||
|
|
||||||
# THEN: It should be False
|
# THEN: It should be False
|
||||||
self.assertFalse(has_verse_list, 'The SearchResults object should have a verse list')
|
self.assertFalse(has_verse_list, 'The SearchResults object should have a verse list')
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -108,7 +108,7 @@ class TestImageMediaItem(TestCase):
|
|||||||
Test that the save_new_images_list() saves all images in the list
|
Test that the save_new_images_list() saves all images in the list
|
||||||
"""
|
"""
|
||||||
# GIVEN: A list with 3 images
|
# GIVEN: A list with 3 images
|
||||||
image_list = [ 'test_image_1.jpg', 'test_image_2.jpg', 'test_image_3.jpg' ]
|
image_list = ['test_image_1.jpg', 'test_image_2.jpg', 'test_image_3.jpg']
|
||||||
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
|
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
|
||||||
self.media_item.manager = MagicMock()
|
self.media_item.manager = MagicMock()
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ class TestImageMediaItem(TestCase):
|
|||||||
Test that the save_new_images_list() ignores everything in the provided list except strings
|
Test that the save_new_images_list() ignores everything in the provided list except strings
|
||||||
"""
|
"""
|
||||||
# GIVEN: A list with images and objects
|
# GIVEN: A list with images and objects
|
||||||
image_list = [ 'test_image_1.jpg', None, True, ImageFilenames(), 'test_image_2.jpg' ]
|
image_list = ['test_image_1.jpg', None, True, ImageFilenames(), 'test_image_2.jpg']
|
||||||
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
|
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
|
||||||
self.media_item.manager = MagicMock()
|
self.media_item.manager = MagicMock()
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ class TestImageMediaItem(TestCase):
|
|||||||
assert self.media_item.manager.delete_object.call_count == 7, \
|
assert self.media_item.manager.delete_object.call_count == 7, \
|
||||||
'manager.delete_object() should be called exactly 7 times'
|
'manager.delete_object() should be called exactly 7 times'
|
||||||
|
|
||||||
# CLEANUP: Remove added attribute from ImageFilenames and ImageGroups
|
# CLEANUP: Remove added attribute from Image Filenames and ImageGroups
|
||||||
delattr(ImageFilenames, 'group_id')
|
delattr(ImageFilenames, 'group_id')
|
||||||
delattr(ImageGroups, 'parent_id')
|
delattr(ImageGroups, 'parent_id')
|
||||||
|
|
||||||
|
@ -115,8 +115,8 @@ class TestSongShowPlusImport(TestCase):
|
|||||||
|
|
||||||
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
|
# THEN: do_import should return none and the progress bar setMaximum should be called with the length of
|
||||||
# import_source.
|
# import_source.
|
||||||
self.assertIsNone(importer.do_import(),
|
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is a list '
|
||||||
'do_import should return None when import_source is a list and stop_import_flag is True')
|
'and stop_import_flag is True')
|
||||||
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
|
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
|
||||||
|
|
||||||
def to_openlp_verse_tag_test(self):
|
def to_openlp_verse_tag_test(self):
|
||||||
@ -143,8 +143,8 @@ class TestSongShowPlusImport(TestCase):
|
|||||||
# THEN: The returned value should should correlate with the input arguments
|
# THEN: The returned value should should correlate with the input arguments
|
||||||
for original_tag, openlp_tag in test_values:
|
for original_tag, openlp_tag in test_values:
|
||||||
self.assertEquals(importer.to_openlp_verse_tag(original_tag), openlp_tag,
|
self.assertEquals(importer.to_openlp_verse_tag(original_tag), openlp_tag,
|
||||||
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"'
|
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' %
|
||||||
% (openlp_tag, original_tag))
|
(openlp_tag, original_tag))
|
||||||
|
|
||||||
def to_openlp_verse_tag_verse_order_test(self):
|
def to_openlp_verse_tag_verse_order_test(self):
|
||||||
"""
|
"""
|
||||||
@ -171,5 +171,5 @@ class TestSongShowPlusImport(TestCase):
|
|||||||
# THEN: The returned value should should correlate with the input arguments
|
# THEN: The returned value should should correlate with the input arguments
|
||||||
for original_tag, openlp_tag in test_values:
|
for original_tag, openlp_tag in test_values:
|
||||||
self.assertEquals(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag,
|
self.assertEquals(importer.to_openlp_verse_tag(original_tag, ignore_unique=True), openlp_tag,
|
||||||
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"'
|
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' %
|
||||||
% (openlp_tag, original_tag))
|
(openlp_tag, original_tag))
|
||||||
|
@ -73,35 +73,37 @@ class WorshipCenterProImportLogger(WorshipCenterProImport):
|
|||||||
|
|
||||||
|
|
||||||
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
||||||
TestRecord(1, 'LYRICS',
|
TestRecord(
|
||||||
'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;'
|
1, 'LYRICS',
|
||||||
'I once was lost,&crlf;but now am found;&crlf;Was blind, but now I see.&crlf;&crlf;'
|
'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;'
|
||||||
'\'Twas grace that&crlf;taught my heart to fear,&crlf;And grace my fears relieved;&crlf;'
|
'I once was lost,&crlf;but now am found;&crlf;Was blind, but now I see.&crlf;&crlf;'
|
||||||
'How precious did&crlf;that grace appear&crlf;The hour I first believed.&crlf;&crlf;'
|
'\'Twas grace that&crlf;taught my heart to fear,&crlf;And grace my fears relieved;&crlf;'
|
||||||
'Through many dangers,&crlf;toils and snares,&crlf;I have already come;&crlf;'
|
'How precious did&crlf;that grace appear&crlf;The hour I first believed.&crlf;&crlf;'
|
||||||
'\'Tis grace hath brought&crlf;me safe thus far,&crlf;'
|
'Through many dangers,&crlf;toils and snares,&crlf;I have already come;&crlf;'
|
||||||
'And grace will lead me home.&crlf;&crlf;The Lord has&crlf;promised good to me,&crlf;'
|
'\'Tis grace hath brought&crlf;me safe thus far,&crlf;'
|
||||||
'His Word my hope secures;&crlf;He will my Shield&crlf;and Portion be,&crlf;'
|
'And grace will lead me home.&crlf;&crlf;The Lord has&crlf;promised good to me,&crlf;'
|
||||||
'As long as life endures.&crlf;&crlf;Yea, when this flesh&crlf;and heart shall fail,&crlf;'
|
'His Word my hope secures;&crlf;He will my Shield&crlf;and Portion be,&crlf;'
|
||||||
'And mortal life shall cease,&crlf;I shall possess,&crlf;within the veil,&crlf;'
|
'As long as life endures.&crlf;&crlf;Yea, when this flesh&crlf;and heart shall fail,&crlf;'
|
||||||
'A life of joy and peace.&crlf;&crlf;The earth shall soon&crlf;dissolve like snow,&crlf;'
|
'And mortal life shall cease,&crlf;I shall possess,&crlf;within the veil,&crlf;'
|
||||||
'The sun forbear to shine;&crlf;But God, Who called&crlf;me here below,&crlf;'
|
'A life of joy and peace.&crlf;&crlf;The earth shall soon&crlf;dissolve like snow,&crlf;'
|
||||||
'Shall be forever mine.&crlf;&crlf;When we\'ve been there&crlf;ten thousand years,&crlf;'
|
'The sun forbear to shine;&crlf;But God, Who called&crlf;me here below,&crlf;'
|
||||||
'Bright shining as the sun,&crlf;We\'ve no less days to&crlf;sing God\'s praise&crlf;'
|
'Shall be forever mine.&crlf;&crlf;When we\'ve been there&crlf;ten thousand years,&crlf;'
|
||||||
'Than when we\'d first begun.&crlf;&crlf;'),
|
'Bright shining as the sun,&crlf;We\'ve no less days to&crlf;sing God\'s praise&crlf;'
|
||||||
|
'Than when we\'d first begun.&crlf;&crlf;'),
|
||||||
TestRecord(2, 'TITLE', 'Beautiful Garden Of Prayer, The'),
|
TestRecord(2, 'TITLE', 'Beautiful Garden Of Prayer, The'),
|
||||||
TestRecord(2, 'LYRICS',
|
TestRecord(
|
||||||
'There\'s a garden where&crlf;Jesus is waiting,&crlf;'
|
2, 'LYRICS',
|
||||||
'There\'s a place that&crlf;is wondrously fair,&crlf;For it glows with the&crlf;'
|
'There\'s a garden where&crlf;Jesus is waiting,&crlf;'
|
||||||
'light of His presence.&crlf;\'Tis the beautiful&crlf;garden of prayer.&crlf;&crlf;'
|
'There\'s a place that&crlf;is wondrously fair,&crlf;For it glows with the&crlf;'
|
||||||
'Oh, the beautiful garden,&crlf;the garden of prayer!&crlf;Oh, the beautiful&crlf;'
|
'light of His presence.&crlf;\'Tis the beautiful&crlf;garden of prayer.&crlf;&crlf;'
|
||||||
'garden of prayer!&crlf;There my Savior awaits,&crlf;and He opens the gates&crlf;'
|
'Oh, the beautiful garden,&crlf;the garden of prayer!&crlf;Oh, the beautiful&crlf;'
|
||||||
'To the beautiful&crlf;garden of prayer.&crlf;&crlf;There\'s a garden where&crlf;'
|
'garden of prayer!&crlf;There my Savior awaits,&crlf;and He opens the gates&crlf;'
|
||||||
'Jesus is waiting,&crlf;And I go with my&crlf;burden and care,&crlf;'
|
'To the beautiful&crlf;garden of prayer.&crlf;&crlf;There\'s a garden where&crlf;'
|
||||||
'Just to learn from His&crlf;lips words of comfort&crlf;In the beautiful&crlf;'
|
'Jesus is waiting,&crlf;And I go with my&crlf;burden and care,&crlf;'
|
||||||
'garden of prayer.&crlf;&crlf;There\'s a garden where&crlf;Jesus is waiting,&crlf;'
|
'Just to learn from His&crlf;lips words of comfort&crlf;In the beautiful&crlf;'
|
||||||
'And He bids you to come,&crlf;meet Him there;&crlf;Just to bow and&crlf;'
|
'garden of prayer.&crlf;&crlf;There\'s a garden where&crlf;Jesus is waiting,&crlf;'
|
||||||
'receive a new blessing&crlf;In the beautiful&crlf;garden of prayer.&crlf;&crlf;')]
|
'And He bids you to come,&crlf;meet Him there;&crlf;Just to bow and&crlf;'
|
||||||
|
'receive a new blessing&crlf;In the beautiful&crlf;garden of prayer.&crlf;&crlf;')]
|
||||||
SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
||||||
'verses': [
|
'verses': [
|
||||||
('Amazing grace! How\nsweet the sound\nThat saved a wretch like me!\nI once was lost,\n'
|
('Amazing grace! How\nsweet the sound\nThat saved a wretch like me!\nI once was lost,\n'
|
||||||
@ -118,7 +120,7 @@ SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
|||||||
'me here below,\nShall be forever mine.'),
|
'me here below,\nShall be forever mine.'),
|
||||||
('When we\'ve been there\nten thousand years,\nBright shining as the sun,\n'
|
('When we\'ve been there\nten thousand years,\nBright shining as the sun,\n'
|
||||||
'We\'ve no less days to\nsing God\'s praise\nThan when we\'d first begun.')]},
|
'We\'ve no less days to\nsing God\'s praise\nThan when we\'d first begun.')]},
|
||||||
{'title': 'Beautiful Garden Of Prayer, The',
|
{'title': 'Beautiful Garden Of Prayer, The',
|
||||||
'verses': [
|
'verses': [
|
||||||
('There\'s a garden where\nJesus is waiting,\nThere\'s a place that\nis wondrously fair,\n'
|
('There\'s a garden where\nJesus is waiting,\nThere\'s a place that\nis wondrously fair,\n'
|
||||||
'For it glows with the\nlight of His presence.\n\'Tis the beautiful\ngarden of prayer.'),
|
'For it glows with the\nlight of His presence.\n\'Tis the beautiful\ngarden of prayer.'),
|
||||||
@ -129,6 +131,7 @@ SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
|||||||
('There\'s a garden where\nJesus is waiting,\nAnd He bids you to come,\nmeet Him there;\n'
|
('There\'s a garden where\nJesus is waiting,\nAnd He bids you to come,\nmeet Him there;\n'
|
||||||
'Just to bow and\nreceive a new blessing\nIn the beautiful\ngarden of prayer.')]}]
|
'Just to bow and\nreceive a new blessing\nIn the beautiful\ngarden of prayer.')]}]
|
||||||
|
|
||||||
|
|
||||||
class TestWorshipCenterProSongImport(TestCase):
|
class TestWorshipCenterProSongImport(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the functions in the :mod:`worshipcenterproimport` module.
|
Test the functions in the :mod:`worshipcenterproimport` module.
|
||||||
@ -155,7 +158,7 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
# a mocked "manager" and a mocked out log_error method.
|
# a mocked "manager" and a mocked out log_error method.
|
||||||
with patch('openlp.plugins.songs.lib.worshipcenterproimport.SongImport'), \
|
with patch('openlp.plugins.songs.lib.worshipcenterproimport.SongImport'), \
|
||||||
patch('openlp.plugins.songs.lib.worshipcenterproimport.pyodbc.connect') as mocked_pyodbc_connect, \
|
patch('openlp.plugins.songs.lib.worshipcenterproimport.pyodbc.connect') as mocked_pyodbc_connect, \
|
||||||
patch('openlp.plugins.songs.lib.worshipcenterproimport.translate') as mocked_translate:
|
patch('openlp.plugins.songs.lib.worshipcenterproimport.translate') as mocked_translate:
|
||||||
mocked_manager = MagicMock()
|
mocked_manager = MagicMock()
|
||||||
mocked_log_error = MagicMock()
|
mocked_log_error = MagicMock()
|
||||||
mocked_translate.return_value = 'Translated Text'
|
mocked_translate.return_value = 'Translated Text'
|
||||||
@ -171,9 +174,9 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
|
|
||||||
# THEN: do_import should return None, and pyodbc, translate & log_error are called with known calls
|
# THEN: do_import should return None, and pyodbc, translate & log_error are called with known calls
|
||||||
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
|
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
|
||||||
mocked_pyodbc_connect.assert_called_with( 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
|
mocked_pyodbc_connect.assert_called_with('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=import_source')
|
||||||
mocked_translate.assert_called_with('SongsPlugin.WorshipCenterProImport',
|
mocked_translate.assert_called_with('SongsPlugin.WorshipCenterProImport',
|
||||||
'Unable to connect the WorshipCenter Pro database.')
|
'Unable to connect the WorshipCenter Pro database.')
|
||||||
mocked_log_error.assert_called_with('import_source', 'Translated Text')
|
mocked_log_error.assert_called_with('import_source', 'Translated Text')
|
||||||
|
|
||||||
def song_import_test(self):
|
def song_import_test(self):
|
||||||
@ -184,7 +187,7 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
# translate method, a mocked "manager", add_verse method & mocked_finish method.
|
# translate method, a mocked "manager", add_verse method & mocked_finish method.
|
||||||
with patch('openlp.plugins.songs.lib.worshipcenterproimport.SongImport'), \
|
with patch('openlp.plugins.songs.lib.worshipcenterproimport.SongImport'), \
|
||||||
patch('openlp.plugins.songs.lib.worshipcenterproimport.pyodbc') as mocked_pyodbc, \
|
patch('openlp.plugins.songs.lib.worshipcenterproimport.pyodbc') as mocked_pyodbc, \
|
||||||
patch('openlp.plugins.songs.lib.worshipcenterproimport.translate') as mocked_translate:
|
patch('openlp.plugins.songs.lib.worshipcenterproimport.translate') as mocked_translate:
|
||||||
mocked_manager = MagicMock()
|
mocked_manager = MagicMock()
|
||||||
mocked_import_wizard = MagicMock()
|
mocked_import_wizard = MagicMock()
|
||||||
mocked_add_verse = MagicMock()
|
mocked_add_verse = MagicMock()
|
||||||
@ -201,7 +204,6 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
# WHEN: Calling the do_import method
|
# WHEN: Calling the do_import method
|
||||||
return_value = importer.do_import()
|
return_value = importer.do_import()
|
||||||
|
|
||||||
|
|
||||||
# THEN: do_import should return None, and pyodbc, import_wizard, importer.title and add_verse are called with
|
# THEN: do_import should return None, and pyodbc, import_wizard, importer.title and add_verse are called with
|
||||||
# known calls
|
# known calls
|
||||||
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
|
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')
|
||||||
@ -214,10 +216,10 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
for song_data in SONG_TEST_DATA:
|
for song_data in SONG_TEST_DATA:
|
||||||
title_value = song_data['title']
|
title_value = song_data['title']
|
||||||
self.assertIn(title_value, importer._title_assignment_list,
|
self.assertIn(title_value, importer._title_assignment_list,
|
||||||
'title should have been set to %s' % title_value)
|
'title should have been set to %s' % title_value)
|
||||||
verse_calls = song_data['verses']
|
verse_calls = song_data['verses']
|
||||||
add_verse_call_count += len(verse_calls)
|
add_verse_call_count += len(verse_calls)
|
||||||
for call in verse_calls:
|
for call in verse_calls:
|
||||||
mocked_add_verse.assert_any_call(call)
|
mocked_add_verse.assert_any_call(call)
|
||||||
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
|
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
|
||||||
'Incorrect number of calls made to add_verse')
|
'Incorrect number of calls made to add_verse')
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -26,3 +26,4 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -25,4 +25,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License along #
|
# 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 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -48,4 +48,3 @@ def convert_file_service_item(test_path, name, row=0):
|
|||||||
finally:
|
finally:
|
||||||
open_file.close()
|
open_file.close()
|
||||||
return first_line
|
return first_line
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user