test fixes

This commit is contained in:
Tim Bentley 2014-04-02 19:51:21 +01:00
parent 3e7370c656
commit c38c576f94
28 changed files with 142 additions and 127 deletions

View File

@ -28,15 +28,15 @@
###############################################################################
"""
The :mod:`http` module contains the API web server. This is a lightweight web
server used by remotes to interact with OpenLP. It uses JSON to communicate with
the remotes.
The :mod:`http` module contains the API web server. This is a lightweight web server used by remotes to interact
with OpenLP. It uses JSON to communicate with the remotes.
"""
import ssl
import socket
import os
import logging
import time
from PyQt4 import QtCore
@ -53,8 +53,8 @@ log = logging.getLogger(__name__)
class CustomHandler(BaseHTTPRequestHandler, HttpRouter):
"""
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
methods within the HttpRouter class.
This class handles just the overrides to the base methods and the logic to invoke the methods within the HttpRouter
class.
DO not try change the structure as this is as per the documentation.
"""
@ -116,9 +116,20 @@ class OpenLPServer():
log.debug('Started ssl httpd...')
else:
port = Settings().value(self.settings_section + '/port')
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...')
if hasattr(self, 'httpd') and self.httpd:
self.httpd.serve_forever()
else:
log.debug('Failed to start server')
def stop_server(self):
"""

View File

@ -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
PLATFORMS!
"""

View File

@ -52,7 +52,9 @@ This is done easily via the ``-d``, ``-p`` and ``-u`` options::
"""
import os
import urllib.request, urllib.error, urllib.parse
import urllib.request
import urllib.error
import urllib.parse
from getpass import getpass
import base64
import json
@ -70,6 +72,7 @@ quiet_mode = False
username = ''
password = ''
class Command(object):
"""
Provide an enumeration of commands.
@ -80,6 +83,7 @@ class Command(object):
Update = 4
Generate = 5
class CommandStack(object):
"""
This class provides an iterable stack.
@ -134,13 +138,13 @@ class CommandStack(object):
results.append(str((item['command'], )))
return '[%s]' % ', '.join(results)
def print_quiet(text, linefeed=True):
"""
This method checks to see if we are in quiet mode, and if not prints
``text`` out.
This method checks to see if we are in quiet mode, and if not prints ``text`` out.
``text``
The text to print.
:param text: The text to print.
:param linefeed: Linefeed required
"""
global quiet_mode
if not quiet_mode:
@ -149,33 +153,33 @@ def print_quiet(text, linefeed=True):
else:
print(text, end=' ')
def print_verbose(text):
"""
This method checks to see if we are in verbose mode, and if so prints
``text`` out.
This method checks to see if we are in verbose mode, and if so prints ``text`` out.
``text``
The text to print.
:param text: The text to print.
"""
global verbose_mode, quiet_mode
if not quiet_mode and verbose_mode:
print(' %s' % text)
def run(command):
"""
This method runs an external application.
``command``
The command to run.
:param command: The command to run.
"""
print_verbose(command)
process = QtCore.QProcess()
process.start(command)
while (process.waitForReadyRead()):
while process.waitForReadyRead():
print_verbose('ReadyRead: %s' % QtCore.QString(process.readAll()))
print_verbose('Error(s):\n%s' % process.readAllStandardError())
print_verbose('Output:\n%s' % process.readAllStandardOutput())
def download_translations():
"""
This method downloads the translation files from the Pootle server.
@ -190,8 +194,7 @@ def download_translations():
password = getpass(' Transifex password: ')
# First get the list of languages
url = SERVER_URL + 'resource/ents/'
base64string = base64.encodestring(
'%s:%s' % (username, password))[:-1]
base64string = base64.encodbytes('%s:%s' % (username, password))[:-1]
auth_header = 'Basic %s' % base64string
request = urllib.request.Request(url + '?details')
request.add_header('Authorization', auth_header)
@ -207,8 +210,7 @@ def download_translations():
lang_url = url + 'translation/%s/?file' % language
request = urllib.request.Request(lang_url)
request.add_header('Authorization', auth_header)
filename = os.path.join(os.path.abspath('..'), 'resources', 'i18n',
language + '.ts')
filename = os.path.join(os.path.abspath('..'), 'resources', 'i18n', language + '.ts')
print_verbose('Get Translation File: %s' % filename)
response = urllib.request.urlopen(request)
fd = open(filename, 'w')
@ -217,10 +219,10 @@ def download_translations():
print_quiet(' Done.')
return True
def prepare_project():
"""
This method creates the project file needed to update the translation files
and compile them into .qm files.
This method creates the project file needed to update the translation files and compile them into .qm files.
"""
print_quiet('Generating the openlp.pro file')
lines = []
@ -229,7 +231,7 @@ def prepare_project():
print_verbose('Starting directory: %s' % start_dir)
for root, dirs, files in os.walk(start_dir):
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_'):
continue
ignore = False
@ -263,6 +265,7 @@ def prepare_project():
file.close()
print_quiet(' Done.')
def update_translations():
print_quiet('Update the translation files')
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
@ -273,6 +276,7 @@ def update_translations():
run('pylupdate4 -verbose -noobsolete openlp.pro')
os.chdir(os.path.abspath('scripts'))
def generate_binaries():
print_quiet('Generate the related *.qm files')
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
@ -290,12 +294,11 @@ def create_translation():
This method opens a browser to the OpenLP project page at Transifex so
that the user can request a new language.
"""
print_quiet('Please request a new language at the OpenLP project on '
'Transifex.')
webbrowser.open('https://www.transifex.net/projects/p/openlp/'
'resource/ents/')
print_quiet('Please request a new language at the OpenLP project on Transifex.')
webbrowser.open('https://www.transifex.net/projects/p/openlp/resource/ents/')
print_quiet('Opening browser to OpenLP project...')
def process_stack(command_stack):
"""
This method looks at the commands in the command stack, and processes them
@ -323,6 +326,7 @@ def process_stack(command_stack):
else:
print_quiet('No commands to process.')
def main():
global verbose_mode, quiet_mode, username, password
# Set up command line options.

View File

@ -123,7 +123,9 @@ setup(
version=version_string,
description="Open source Church presentation and lyrics projection application.",
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=[
'Development Status :: 4 - Beta',
'Environment :: MacOS X',

View File

@ -54,9 +54,9 @@ class TestAppLocation(TestCase):
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value
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_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()
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
mocked_settings.contains.assert_called_with('advanced/data path')
mocked_get_directory.assert_called_with(AppLocation.DataDir)
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"')
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"')
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, \
patch('openlp.core.common.applocation.os.listdir') as mocked_listdir:
# 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)
# When: Get the list of files.
result = AppLocation.get_files('section', '.mp3')
# 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.
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, \
patch('openlp.core.common.applocation.check_directory_exists') as mocked_check_directory_exists:
# 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
# WHEN: we call AppLocation.get_data_path()
data_path = AppLocation.get_section_data_path('section')
# 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'))
self.assertEqual(os.path.join('test','dir','section'), data_path, 'Result should be "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"')
def get_directory_for_app_dir_test(self):
"""
@ -145,13 +145,13 @@ class TestAppLocation(TestCase):
"""
# GIVEN: A mocked out _get_frozen_path function
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
directory = AppLocation.get_directory(AppLocation.AppDir)
# 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):
"""

View File

@ -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
assert not self.mocked_os.path.exists.called
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):
"""

View File

@ -108,4 +108,3 @@ class TestFormattingTags(TestCase):
# THEN: The lists should now be identical.
assert old_tags_list == FormattingTags.get_html_tags(), 'The lists should be identical.'

View File

@ -321,4 +321,3 @@ class Htmbuilder(TestCase):
# THEN: THE css should be the same.
assert FOOTER_CSS == css, 'The footer strings should be equal.'

View File

@ -311,8 +311,8 @@ class TestLib(TestCase):
mocked_buffer.open.assert_called_with('writeonly')
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
mocked_byte_array.toBase64.assert_called_with()
self.assertEqual('base64mock', result,
'The result should be the return value of the mocked out base64 method')
self.assertEqual('base64mock', result, 'The result should be the return value of the mocked out '
'base64 method')
def create_thumb_with_size_test(self):
"""

View File

@ -69,4 +69,3 @@ class TestTheme(TestCase):
'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(len(default_theme.__dict__) == 47, 'The theme should have 47 variables')

View File

@ -26,4 +26,3 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################

View File

@ -116,7 +116,8 @@ class TestBSExtract(TestCase):
self.mock_get_soup_for_bible_ref.assert_called_once_with(
'http://m.bibleserver.com/overlay/selectBook?translation=NIV')
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):
"""
@ -146,7 +147,8 @@ class TestBSExtract(TestCase):
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.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):
"""

View File

@ -85,5 +85,3 @@ class TestLib(TestCase):
# THEN: It should be False
self.assertFalse(has_verse_list, 'The SearchResults object should have a verse list')

View File

@ -108,7 +108,7 @@ class TestImageMediaItem(TestCase):
Test that the save_new_images_list() saves all images in the list
"""
# 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:
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
"""
# 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:
self.media_item.manager = MagicMock()
@ -171,7 +171,7 @@ class TestImageMediaItem(TestCase):
assert self.media_item.manager.delete_object.call_count == 7, \
'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(ImageGroups, 'parent_id')

View File

@ -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
# import_source.
self.assertIsNone(importer.do_import(),
'do_import should return None when import_source is a list and stop_import_flag is True')
self.assertIsNone(importer.do_import(), 'do_import should return None when import_source is a list '
'and stop_import_flag is True')
mocked_import_wizard.progress_bar.setMaximum.assert_called_with(len(importer.import_source))
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
for original_tag, openlp_tag in test_values:
self.assertEquals(importer.to_openlp_verse_tag(original_tag), openlp_tag,
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"'
% (openlp_tag, original_tag))
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' %
(openlp_tag, original_tag))
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
for original_tag, openlp_tag in test_values:
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"'
% (openlp_tag, original_tag))
'SongShowPlusImport.to_openlp_verse_tag should return "%s" when called with "%s"' %
(openlp_tag, original_tag))

View File

@ -73,7 +73,8 @@ class WorshipCenterProImportLogger(WorshipCenterProImport):
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
TestRecord(1, 'LYRICS',
TestRecord(
1, 'LYRICS',
'Amazing grace! How&crlf;sweet the sound&crlf;That saved a wretch like me!&crlf;'
'I once was lost,&crlf;but now am found;&crlf;Was blind, but now I see.&crlf;&crlf;'
'\'Twas grace that&crlf;taught my heart to fear,&crlf;And grace my fears relieved;&crlf;'
@ -90,7 +91,8 @@ RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
'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, 'LYRICS',
TestRecord(
2, 'LYRICS',
'There\'s a garden where&crlf;Jesus is waiting,&crlf;'
'There\'s a place that&crlf;is wondrously fair,&crlf;For it glows with the&crlf;'
'light of His presence.&crlf;\'Tis the beautiful&crlf;garden of prayer.&crlf;&crlf;'
@ -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'
'Just to bow and\nreceive a new blessing\nIn the beautiful\ngarden of prayer.')]}]
class TestWorshipCenterProSongImport(TestCase):
"""
Test the functions in the :mod:`worshipcenterproimport` module.
@ -171,7 +174,7 @@ class TestWorshipCenterProSongImport(TestCase):
# 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.')
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',
'Unable to connect the WorshipCenter Pro database.')
mocked_log_error.assert_called_with('import_source', 'Translated Text')
@ -201,7 +204,6 @@ class TestWorshipCenterProSongImport(TestCase):
# WHEN: Calling the do_import method
return_value = importer.do_import()
# THEN: do_import should return None, and pyodbc, import_wizard, importer.title and add_verse are called with
# known calls
self.assertIsNone(return_value, 'do_import should return None when pyodbc raises an exception.')

View File

@ -26,3 +26,4 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################

View File

@ -48,4 +48,3 @@ def convert_file_service_item(test_path, name, row=0):
finally:
open_file.close()
return first_line