forked from openlp/openlp
Updated more tests
This commit is contained in:
parent
188f312669
commit
1215494303
@ -69,8 +69,8 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_media_manager()
|
||||
|
||||
# THEN: The create_media_manager_item() method should have been called
|
||||
assert mocked_plugin.create_media_manager_item.call_count == 0, \
|
||||
'The create_media_manager_item() method should not have been called.'
|
||||
self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count,
|
||||
'The create_media_manager_item() method should not have been called.')
|
||||
|
||||
def hook_media_manager_with_active_plugin_test(self):
|
||||
"""
|
||||
@ -102,8 +102,8 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_settings_tabs()
|
||||
|
||||
# THEN: The hook_settings_tabs() method should have been called
|
||||
assert mocked_plugin.create_media_manager_item.call_count == 0, \
|
||||
'The create_media_manager_item() method should not have been called.'
|
||||
self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count,
|
||||
'The create_media_manager_item() method should not have been called.')
|
||||
|
||||
def hook_settings_tabs_with_disabled_plugin_and_mocked_form_test(self):
|
||||
"""
|
||||
@ -122,8 +122,8 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_settings_tabs()
|
||||
|
||||
# THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same
|
||||
assert mocked_plugin.create_settings_tab.call_count == 0, \
|
||||
'The create_media_manager_item() method should not have been called.'
|
||||
self.assertEqual(0, mocked_plugin.create_settings_tab.call_count,
|
||||
'The create_media_manager_item() method should not have been called.')
|
||||
self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
|
||||
'The plugins on the settings form should be the same as the plugins in the plugin manager')
|
||||
|
||||
@ -144,9 +144,9 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_settings_tabs()
|
||||
|
||||
# THEN: The create_media_manager_item() method should have been called with the mocked settings form
|
||||
assert mocked_plugin.create_settings_tab.call_count == 1, \
|
||||
'The create_media_manager_item() method should have been called once.'
|
||||
self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
|
||||
self.assertEqual(1, mocked_plugin.create_settings_tab.call_count,
|
||||
'The create_media_manager_item() method should have been called once.')
|
||||
self.assertEqual(plugin_manager.plugins, mocked_settings_form.plugin_manager.plugins,
|
||||
'The plugins on the settings form should be the same as the plugins in the plugin manager')
|
||||
|
||||
def hook_settings_tabs_with_active_plugin_and_no_form_test(self):
|
||||
@ -179,8 +179,8 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_import_menu()
|
||||
|
||||
# THEN: The create_media_manager_item() method should have been called
|
||||
assert mocked_plugin.add_import_menu_item.call_count == 0, \
|
||||
'The add_import_menu_item() method should not have been called.'
|
||||
self.assertEqual(0, mocked_plugin.add_import_menu_item.call_count,
|
||||
'The add_import_menu_item() method should not have been called.')
|
||||
|
||||
def hook_import_menu_with_active_plugin_test(self):
|
||||
"""
|
||||
@ -212,8 +212,8 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_export_menu()
|
||||
|
||||
# THEN: The add_export_menu_Item() method should not have been called
|
||||
assert mocked_plugin.add_export_menu_Item.call_count == 0, \
|
||||
'The add_export_menu_Item() method should not have been called.'
|
||||
self.assertEqual(0, mocked_plugin.add_export_menu_Item.call_count,
|
||||
'The add_export_menu_Item() method should not have been called.')
|
||||
|
||||
def hook_export_menu_with_active_plugin_test(self):
|
||||
"""
|
||||
@ -246,8 +246,8 @@ class TestPluginManager(TestCase):
|
||||
plugin_manager.hook_upgrade_plugin_settings(settings)
|
||||
|
||||
# THEN: The upgrade_settings() method should not have been called
|
||||
assert mocked_plugin.upgrade_settings.call_count == 0, \
|
||||
'The upgrade_settings() method should not have been called.'
|
||||
self.assertEqual(0, mocked_plugin.upgrade_settings.call_count,
|
||||
'The upgrade_settings() method should not have been called.')
|
||||
|
||||
def hook_upgrade_plugin_settings_with_active_plugin_test(self):
|
||||
"""
|
||||
|
@ -81,5 +81,6 @@ class TestScreenList(TestCase):
|
||||
|
||||
# THEN: The screen should have been added and the screens should be identical
|
||||
new_screen_count = len(self.screens.screen_list)
|
||||
assert old_screen_count + 1 == new_screen_count, 'The new_screens list should be bigger'
|
||||
assert SCREEN == self.screens.screen_list.pop(), 'The 2nd screen should be identical to the first screen'
|
||||
self.assertEqual(old_screen_count + 1, new_screen_count, 'The new_screens list should be bigger')
|
||||
self.assertEqual(SCREEN, self.screens.screen_list.pop(),
|
||||
'The 2nd screen should be identical to the first screen')
|
||||
|
@ -30,11 +30,11 @@
|
||||
Package to test the openlp.core.lib package.
|
||||
"""
|
||||
import os
|
||||
import json
|
||||
from unittest import TestCase
|
||||
|
||||
from openlp.core.lib import ItemCapabilities, ServiceItem, Registry
|
||||
from tests.functional import MagicMock, patch
|
||||
from tests.utils import assert_length, convert_file_service_item
|
||||
|
||||
VERSE = 'The Lord said to {r}Noah{/r}: \n'\
|
||||
'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\
|
||||
@ -59,7 +59,7 @@ class TestServiceItem(TestCase):
|
||||
Registry().register('renderer', mocked_renderer)
|
||||
Registry().register('image_manager', MagicMock())
|
||||
|
||||
def serviceitem_basic_test(self):
|
||||
def service_item_basic_test(self):
|
||||
"""
|
||||
Test the Service Item - basic test
|
||||
"""
|
||||
@ -69,10 +69,10 @@ class TestServiceItem(TestCase):
|
||||
service_item = ServiceItem(None)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert service_item.missing_frames() is True, 'There should not be any frames in the service item'
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
self.assertTrue(service_item.missing_frames(), 'There should not be any frames in the service item')
|
||||
|
||||
def serviceitem_load_custom_from_service_test(self):
|
||||
def service_item_load_custom_from_service_test(self):
|
||||
"""
|
||||
Test the Service Item - adding a custom slide from a saved service
|
||||
"""
|
||||
@ -80,24 +80,29 @@ class TestServiceItem(TestCase):
|
||||
service_item = ServiceItem(None)
|
||||
service_item.add_icon = MagicMock()
|
||||
|
||||
# WHEN: adding a custom from a saved Service
|
||||
line = self.convert_file_service_item('serviceitem_custom_1.osj')
|
||||
# WHEN: We add a custom from a saved service
|
||||
line = convert_file_service_item('serviceitem_custom_1.osj')
|
||||
service_item.set_from_service(line)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert len(service_item._display_frames) == 0, 'The service item should have no display frames'
|
||||
assert len(service_item.capabilities) == 5, 'There should be 5 default custom item capabilities'
|
||||
service_item.render(True)
|
||||
assert service_item.get_display_title() == 'Test Custom', 'The title should be "Test Custom"'
|
||||
assert service_item.get_frames()[0]['text'] == VERSE[:-1], \
|
||||
'The returned text matches the input, except the last line feed'
|
||||
assert service_item.get_rendered_frame(1) == VERSE.split('\n', 1)[0], 'The first line has been returned'
|
||||
assert service_item.get_frame_title(0) == 'Slide 1', '"Slide 1" has been returned as the title'
|
||||
assert service_item.get_frame_title(1) == 'Slide 2', '"Slide 2" has been returned as the title'
|
||||
assert service_item.get_frame_title(2) == '', 'Blank has been returned as the title of slide 3'
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
assert_length(0, service_item._display_frames, 'The service item should have no display frames')
|
||||
assert_length(5, service_item.capabilities, 'There should be 5 default custom item capabilities')
|
||||
|
||||
def serviceitem_load_image_from_service_test(self):
|
||||
# WHEN: We render the frames of the service item
|
||||
service_item.render(True)
|
||||
|
||||
# THEN: The frames should also be valid
|
||||
self.assertEqual('Test Custom', service_item.get_display_title(), 'The title should be "Test Custom"')
|
||||
self.assertEqual(VERSE[:-1], service_item.get_frames()[0]['text'],
|
||||
'The returned text matches the input, except the last line feed')
|
||||
self.assertEqual(VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
|
||||
'The first line has been returned')
|
||||
self.assertEqual('Slide 1', service_item.get_frame_title(0), '"Slide 1" has been returned as the title')
|
||||
self.assertEqual('Slide 2', service_item.get_frame_title(1), '"Slide 2" has been returned as the title')
|
||||
self.assertEqual('', service_item.get_frame_title(2), 'Blank has been returned as the title of slide 3')
|
||||
|
||||
def service_item_load_image_from_service_test(self):
|
||||
"""
|
||||
Test the Service Item - adding an image from a saved service
|
||||
"""
|
||||
@ -110,29 +115,34 @@ class TestServiceItem(TestCase):
|
||||
service_item.add_icon = MagicMock()
|
||||
|
||||
# WHEN: adding an image from a saved Service and mocked exists
|
||||
line = self.convert_file_service_item('serviceitem_image_1.osj')
|
||||
line = convert_file_service_item(TEST_PATH, 'serviceitem_image_1.osj')
|
||||
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists:
|
||||
mocked_exists.return_value = True
|
||||
service_item.set_from_service(line, TEST_PATH)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert service_item.get_rendered_frame(0) == test_file, 'The first frame should match the path to the image'
|
||||
assert service_item.get_frames()[0] == frame_array, 'The return should match frame array1'
|
||||
assert service_item.get_frame_path(0) == test_file, 'The frame path should match the full path to the image'
|
||||
assert service_item.get_frame_title(0) == image_name, 'The frame title should match the image name'
|
||||
assert service_item.get_display_title() == image_name, 'The display title should match the first image name'
|
||||
assert service_item.is_image() is True, 'This service item should be of an "image" type'
|
||||
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
|
||||
'This service item should be able to be Maintained'
|
||||
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
|
||||
'This service item should be able to be be Previewed'
|
||||
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
|
||||
'This service item should be able to be run in a can be made to Loop'
|
||||
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
|
||||
'This service item should be able to have new items added to it'
|
||||
self.assertTrue(service_item.is_valid, 'The new service item should be valid')
|
||||
self.assertEqual(test_file, service_item.get_rendered_frame(0),
|
||||
'The first frame should match the path to the image')
|
||||
self.assertEqual(frame_array, service_item.get_frames()[0],
|
||||
'The return should match frame array1')
|
||||
self.assertEqual(test_file, service_item.get_frame_path(0),
|
||||
'The frame path should match the full path to the image')
|
||||
self.assertEqual(image_name, service_item.get_frame_title(0),
|
||||
'The frame title should match the image name')
|
||||
self.assertEqual(image_name, service_item.get_display_title(),
|
||||
'The display title should match the first image name')
|
||||
self.assertTrue(service_item.is_image(), 'This service item should be of an "image" type')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanMaintain),
|
||||
'This service item should be able to be Maintained')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanPreview),
|
||||
'This service item should be able to be be Previewed')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanLoop),
|
||||
'This service item should be able to be run in a can be made to Loop')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanAppend),
|
||||
'This service item should be able to have new items added to it')
|
||||
|
||||
def serviceitem_load_image_from_local_service_test(self):
|
||||
def service_item_load_image_from_local_service_test(self):
|
||||
"""
|
||||
Test the Service Item - adding an image from a saved local service
|
||||
"""
|
||||
@ -151,50 +161,42 @@ class TestServiceItem(TestCase):
|
||||
service_item2.add_icon = MagicMock()
|
||||
|
||||
# WHEN: adding an image from a saved Service and mocked exists
|
||||
line = self.convert_file_service_item('serviceitem_image_2.osj')
|
||||
line2 = self.convert_file_service_item('serviceitem_image_2.osj', 1)
|
||||
line = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj')
|
||||
line2 = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj', 1)
|
||||
|
||||
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists:
|
||||
mocked_exists.return_value = True
|
||||
service_item2.set_from_service(line2)
|
||||
service_item.set_from_service(line)
|
||||
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
|
||||
# This test is copied from service_item.py, but is changed since to conform to
|
||||
# new layout of service item. The layout use in serviceitem_image_2.osd is actually invalid now.
|
||||
assert service_item.is_valid is True, 'The first service item should be valid'
|
||||
assert service_item2.is_valid is True, 'The second service item should be valid'
|
||||
assert service_item.get_rendered_frame(0) == test_file1, 'The first frame should match the path to the image'
|
||||
assert service_item2.get_rendered_frame(0) == test_file2, 'The Second frame should match the path to the image'
|
||||
assert service_item.get_frames()[0] == frame_array1, 'The return should match the frame array1'
|
||||
assert service_item2.get_frames()[0] == frame_array2, 'The return should match the frame array2'
|
||||
assert service_item.get_frame_path(0) == test_file1, 'The frame path should match the full path to the image'
|
||||
assert service_item2.get_frame_path(0) == test_file2, 'The frame path should match the full path to the image'
|
||||
assert service_item.get_frame_title(0) == image_name1, 'The 1st frame title should match the image name'
|
||||
assert service_item2.get_frame_title(0) == image_name2, 'The 2nd frame title should match the image name'
|
||||
assert service_item.title.lower() == service_item.name, \
|
||||
'The plugin name should match the display title, as there are > 1 Images'
|
||||
assert service_item.is_image() is True, 'This service item should be of an "image" type'
|
||||
assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
|
||||
'This service item should be able to be Maintained'
|
||||
assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
|
||||
'This service item should be able to be be Previewed'
|
||||
assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
|
||||
'This service item should be able to be run in a can be made to Loop'
|
||||
assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
|
||||
'This service item should be able to have new items added to it'
|
||||
|
||||
def convert_file_service_item(self, name, row=0):
|
||||
service_file = os.path.join(TEST_PATH, name)
|
||||
try:
|
||||
open_file = open(service_file, 'r')
|
||||
items = json.load(open_file)
|
||||
first_line = items[row]
|
||||
except IOError:
|
||||
first_line = ''
|
||||
finally:
|
||||
open_file.close()
|
||||
return first_line
|
||||
|
||||
self.assertTrue(service_item.is_valid, 'The first service item should be valid')
|
||||
self.assertTrue(service_item2.is_valid, 'The second service item should be valid')
|
||||
self.assertEqual(test_file1, service_item.get_rendered_frame(0),
|
||||
'The first frame should match the path to the image')
|
||||
self.assertEqual(test_file2, service_item2.get_rendered_frame(0),
|
||||
'The Second frame should match the path to the image')
|
||||
self.assertEqual(frame_array1, service_item.get_frames()[0], 'The return should match the frame array1')
|
||||
self.assertEqual(frame_array2, service_item2.get_frames()[0], 'The return should match the frame array2')
|
||||
self.assertEqual(test_file1, service_item.get_frame_path(0),
|
||||
'The frame path should match the full path to the image')
|
||||
self.assertEqual(test_file2, service_item2.get_frame_path(0),
|
||||
'The frame path should match the full path to the image')
|
||||
self.assertEqual(image_name1, service_item.get_frame_title(0),
|
||||
'The 1st frame title should match the image name')
|
||||
self.assertEqual(image_name2, service_item2.get_frame_title(0),
|
||||
'The 2nd frame title should match the image name')
|
||||
self.assertEqual(service_item.name, service_item.title.lower(),
|
||||
'The plugin name should match the display title, as there are > 1 Images')
|
||||
self.assertTrue(service_item.is_image(), 'This service item should be of an "image" type')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanMaintain),
|
||||
'This service item should be able to be Maintained')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanPreview),
|
||||
'This service item should be able to be be Previewed')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanLoop),
|
||||
'This service item should be able to be run in a can be made to Loop')
|
||||
self.assertTrue(service_item.is_capable(ItemCapabilities.CanAppend),
|
||||
'This service item should be able to have new items added to it')
|
||||
|
@ -68,13 +68,13 @@ class TestSettings(TestCase):
|
||||
default_value = Settings().value('core/has run wizard')
|
||||
|
||||
# THEN the default value is returned
|
||||
assert default_value is False, 'The default value should be False'
|
||||
self.assertFalse(default_value, 'The default value should be False')
|
||||
|
||||
# WHEN a new value is saved into config
|
||||
Settings().setValue('core/has run wizard', True)
|
||||
|
||||
# THEN the new value is returned when re-read
|
||||
assert Settings().value('core/has run wizard') is True, 'The saved value should have been returned'
|
||||
self.assertTrue(Settings().value('core/has run wizard'), 'The saved value should have been returned')
|
||||
|
||||
def settings_override_test(self):
|
||||
"""
|
||||
@ -90,13 +90,13 @@ class TestSettings(TestCase):
|
||||
extend = Settings().value('test/extend')
|
||||
|
||||
# THEN the default value is returned
|
||||
assert extend == 'very wide', 'The default value of "very wide" should be returned'
|
||||
self.assertEqual('very wide', extend, 'The default value of "very wide" should be returned')
|
||||
|
||||
# WHEN a new value is saved into config
|
||||
Settings().setValue('test/extend', 'very short')
|
||||
|
||||
# THEN the new value is returned when re-read
|
||||
assert Settings().value('test/extend') == 'very short', 'The saved value should be returned'
|
||||
self.assertEqual('very short', Settings().value('test/extend'), 'The saved value should be returned')
|
||||
|
||||
def settings_override_with_group_test(self):
|
||||
"""
|
||||
@ -114,10 +114,10 @@ class TestSettings(TestCase):
|
||||
extend = settings.value('extend')
|
||||
|
||||
# THEN the default value is returned
|
||||
assert extend == 'very wide', 'The default value defined should be returned'
|
||||
self.assertEqual('very wide', extend, 'The default value defined should be returned')
|
||||
|
||||
# WHEN a new value is saved into config
|
||||
Settings().setValue('test/extend', 'very short')
|
||||
|
||||
# THEN the new value is returned when re-read
|
||||
assert Settings().value('test/extend') == 'very short', 'The saved value should be returned'
|
||||
self.assertEqual('very short', Settings().value('test/extend'), 'The saved value should be returned')
|
||||
|
@ -45,6 +45,6 @@ class TestUiStrings(TestCase):
|
||||
second_instance = UiStrings()
|
||||
|
||||
# THEN: Check if the instances are the same.
|
||||
assert first_instance is second_instance, "They should be the same instance!"
|
||||
self.assertIs(first_instance, second_instance, 'Two UiStrings objects should be the same instance')
|
||||
|
||||
|
||||
|
@ -0,0 +1,51 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
|
||||
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
|
||||
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# This program is free software; you can redistribute it and/or modify it #
|
||||
# under the terms of the GNU General Public License as published by the Free #
|
||||
# Software Foundation; version 2 of the License. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||
# more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License along #
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
def assert_length(expected, iterable, msg=None):
|
||||
if len(iterable) != expected:
|
||||
if not msg:
|
||||
msg = 'Expected length %s, got %s' % (expected, len(iterable))
|
||||
raise AssertionError(msg)
|
||||
|
||||
|
||||
def convert_file_service_item(test_path, name, row=0):
|
||||
service_file = os.path.join(test_path, name)
|
||||
open_file = open(service_file, 'r')
|
||||
try:
|
||||
items = json.load(open_file)
|
||||
first_line = items[row]
|
||||
except IOError:
|
||||
first_line = ''
|
||||
finally:
|
||||
open_file.close()
|
||||
return first_line
|
||||
|
Loading…
Reference in New Issue
Block a user