More Service item tests

This commit is contained in:
Tim Bentley 2013-01-20 10:01:51 +00:00
parent 40ac589470
commit d4db88d2a4
5 changed files with 141 additions and 12 deletions

View File

@ -629,10 +629,10 @@ class ServiceItem(object):
if self.is_image() and not os.path.exists((frame[u'path'])):
self.is_valid = False
elif self.is_command():
file = os.path.join(frame[u'path'],frame[u'title'])
if not os.path.exists(file):
file_name = os.path.join(frame[u'path'], frame[u'title'])
if not os.path.exists(file_name):
self.is_valid = False
if suffix_list and not self.is_text():
type = frame[u'title'].split(u'.')[-1]
if type.lower() not in suffix_list:
file_suffix = frame[u'title'].split(u'.')[-1]
if file_suffix.lower() not in suffix_list:
self.is_valid = False

View File

@ -474,8 +474,7 @@ class ThemeManager(QtGui.QWidget):
Name of the theme to load from file
"""
log.debug(u'getthemedata for theme %s', theme_name)
xml_file = os.path.join(self.path, unicode(theme_name),
unicode(theme_name) + u'.xml')
xml_file = os.path.join(self.path, unicode(theme_name), unicode(theme_name) + u'.xml')
xml = get_text_file_string(xml_file)
if not xml:
log.debug(u'No theme data - using default theme')

View File

@ -465,7 +465,7 @@ def get_uno_instance(resolver):
def format_time(text, local_time):
"""
Workaround for Python built-in time formatting fuction time.strftime().
Workaround for Python built-in time formatting function time.strftime().
time.strftime() accepts only ascii characters. This function accepts
unicode string and passes individual % placeholders to time.strftime().

View File

@ -0,0 +1,96 @@
(lp1
(dp2
Vserviceitem
p3
(dp4
Vheader
p5
(dp6
Vfooter
p7
(lp8
VTest Custom Credits
p9
asVaudit
p10
V
sVsearch
p11
V
sVwill_auto_start
p12
I00
sVname
p13
Vcustom
p14
sVplugin
p15
g14
sVdata
p16
V
sVnotes
p17
V
sVtitle
p18
VTest Custom
p19
sVfrom_plugin
p20
I00
sVcapabilities
p21
(lp22
I2
aI1
aI5
aI13
aI8
asVmedia_length
p23
I0
sVtheme_overwritten
p24
I00
sVtheme
p25
NsVxml_version
p26
NsVend_time
p27
I0
sVbackground_audio
p28
(lp29
sVtype
p30
I1
sVstart_time
p31
I0
sVicon
p32
V:/plugins/plugin_custom.png
p33
ssg16
(lp34
(dp35
VverseTag
p36
NsVraw_slide
p37
VSlide 1
p38
sVtitle
p39
g38
sa(dp40
g36
Nsg37
VSlide 2
p41
sg39
g41
sassa.

View File

@ -2,6 +2,7 @@
Package to test the openlp.core.lib package.
"""
import os
import cPickle
from unittest import TestCase
from mock import MagicMock
@ -18,11 +19,12 @@ FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456']
TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'resources'))
class TestServiceItem(TestCase):
def serviceitem_basic_test(self):
"""
Test the Service Item basic test
Test the Service Item - basic test
"""
# GIVEN: A new service item
@ -35,7 +37,7 @@ class TestServiceItem(TestCase):
def serviceitem_add_text_test(self):
"""
Test the Service Item add text test
Test the Service Item - add text test
"""
# GIVEN: A new service item
service_item = ServiceItem(None)
@ -63,7 +65,7 @@ class TestServiceItem(TestCase):
def serviceitem_add_image_test(self):
"""
Test the Service Item add image test
Test the Service Item - add image test
"""
# GIVEN: A new service item and a mocked renderer
service_item = ServiceItem(None)
@ -120,7 +122,7 @@ class TestServiceItem(TestCase):
def serviceitem_add_command_test(self):
"""
Test the Service Item add command test
Test the Service Item - add command test
"""
# GIVEN: A new service item and a mocked renderer
service_item = ServiceItem(None)
@ -161,3 +163,35 @@ class TestServiceItem(TestCase):
# THEN the service item should not be valid
assert service_item.is_valid is False, u'The service item is not valid'
def serviceitem_load_custom_from_service_test(self):
"""
Test the Service Item - adding from a saved service
"""
# GIVEN: A new service item and a mocked add icon function
service_item = ServiceItem(None)
mocked_add_icon = MagicMock()
service_item.add_icon = mocked_add_icon
mocked_renderer = MagicMock()
service_item.renderer = mocked_renderer
# WHEN: adding a custom from a saved Service
line = self.convert_file_service_item(u'serviceitem_custom1.osd')
service_item.set_from_service(line)
# THEN: We should get back a valid service item
assert service_item.is_valid is True, u'The new service item should be valid'
assert len(service_item._display_frames) == 0, u'The service item has no display frames'
assert len(service_item.capabilities) == 5, u'There are 5 default custom item capabilities'
service_item.render(True)
assert (service_item.get_display_title()) == u'Test Custom', u'The custom title is correct'
def convert_file_service_item(self, name):
service_file = os.path.join(TESTPATH, name)
try:
open_file = open(service_file, u'r')
items = cPickle.load(open_file)
first_line = items[0]
except:
first_line = u''
return first_line