Cleanup Service Item Validation and start tests

This commit is contained in:
Tim Bentley 2012-12-08 08:40:41 +00:00
parent d2d48da480
commit 5be9ba5b2c
5 changed files with 23 additions and 17 deletions

View File

@ -192,6 +192,7 @@ class ServiceItem(object):
service items to see if they are the same.
"""
self._uuid = unicode(uuid.uuid1())
self.validate_item()
def add_capability(self, capability):
"""
@ -614,8 +615,25 @@ class ServiceItem(object):
if self.get_frame_path(frame=frame) in invalid_paths:
self.remove_frame(frame)
def validate(self):
def missing_frames(self):
"""
Validates this service item
Returns if there are any frames in the service item
"""
return bool(self._raw_frames)
def validate_item(self, suffix_list=None):
"""
Validates a service item to make sure it is valid
"""
self.is_valid = True
for frame in self._raw_frames:
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):
self.is_valid = False
if suffix_list:
type = frame[u'title'].split(u'.')[-1]
if type.lower() not in suffix_list:
self.is_valid = False

View File

@ -536,7 +536,7 @@ class ServiceManager(QtGui.QWidget):
for item in list(self.serviceItems):
self.mainwindow.incrementProgressBar()
item[u'service_item'].remove_invalid_frames(missing_list)
if not item[u'service_item'].validate():
if item[u'service_item'].missing_frames():
self.serviceItems.remove(item)
else:
service_item = item[u'service_item'].get_service_repr(self._saveLite)
@ -795,7 +795,7 @@ class ServiceManager(QtGui.QWidget):
serviceItem.set_from_service(item)
else:
serviceItem.set_from_service(item, self.servicePath)
self.validateItem(serviceItem)
serviceItem.validate_item(self.suffixes)
self.load_item_uuid = 0
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
Receiver.send_message(u'%s_service_load' %
@ -1215,18 +1215,6 @@ class ServiceManager(QtGui.QWidget):
self.serviceManagerList.setCurrentItem(treewidgetitem)
treewidgetitem.setExpanded(item[u'expanded'])
def validateItem(self, serviceItem):
"""
Validates the service item and if the suffix matches an accepted
one it allows the item to be displayed.
"""
#@todo check file items exist
if serviceItem.is_command():
type = serviceItem._raw_frames[0][u'title'].split(u'.')[-1]
if type.lower() not in self.suffixes:
serviceItem.is_valid = False
#@todo check file items exist
def cleanUp(self):
"""
Empties the servicePath of temporary files on system exit.

View File

@ -34,4 +34,4 @@ from openlp.core.ui.mainwindow import MainWindow
def test_start_app(openlpapp):
assert type(openlpapp) == OpenLP
assert type(openlpapp.mainWindow) == MainWindow
assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.0'
assert unicode(openlpapp.mainWindow.windowTitle()) == u'OpenLP 2.1'